Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the "python_file_names" function to use pathlib globing #28

Open
fhightower opened this issue May 26, 2021 · 4 comments
Open

Update the "python_file_names" function to use pathlib globing #28

fhightower opened this issue May 26, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed time est: 0.1 hour We estimate this issue will take 0.1 hour (6 minutes) to complete

Comments

@fhightower
Copy link
Contributor

fhightower commented May 26, 2021

HELP WANTED 👋 : If you'd like to take this challenge on, please let me know! Even if you're new to Python and/or Github, this is a great place to start and I'd be happy to help walk you through this challenge as much as you need - don't hesitate to ask.

This particular issue will give you some exposure to update a function to use the Pathlib library.


We should update the python_data.python_file_names function to use the Path.glob function.

@fhightower fhightower added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed time est: 0.1 hour We estimate this issue will take 0.1 hour (6 minutes) to complete labels May 26, 2021
@sachindavra
Copy link

Hi @fhightower, I am new to opensource contribution and want to contribute to this.
I know python basics.
Please let me know details of the issue.

@fhightower
Copy link
Contributor Author

fhightower commented Jun 4, 2021

Wonderful, thanks for reaching out @sachindavra 👋 and sorry it has taken me so long to get back to you. I've assigned this issue to you.

In this library, there is a python_file_names function. Currently, this function calls a directory_file_names_matching function. We would like to replace the directory_file_names_matching function with the Pathlib.Path.glob function instead. The goal is to find Python files (any files ending with .py in the given directory (not recursively)).

Thanks again for reaching out and let me know if you have any other questions!

@sachindavra
Copy link

Thank you for your reply.

def python_file_names(path: str, *, exclude_tests: bool = False) -> List[str]:  # noqa: CCR001
    """Find all python files in the given directory."""
    # from d8s_file_system import directory_file_names_matching
    from pathlib import Path
    # files = directory_file_names_matching(path, '*.py')
    files = Path(path).glob('*.py')
    
    if not exclude_tests:
        return files
    else:
        non_test_files = []

        for file in files:
            if '_test' not in file and 'test_' not in file:
                non_test_files.append(file)

        return non_test_files

I don't know the meaning of exclude_tests here but with files = Path(path).glob('*.py'), It will find all the py files in the current path (which is there in the argument).

May i know what other changes should i make please.

@fhightower
Copy link
Contributor Author

Looks reasonable. You can follow the steps here to create a PR implementing this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed time est: 0.1 hour We estimate this issue will take 0.1 hour (6 minutes) to complete
Projects
None yet
Development

No branches or pull requests

2 participants