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

Modify walk(), is_file(), and is_dir() to have the option to follow symlinks #2

Merged
merged 5 commits into from
Oct 20, 2020

Conversation

JonoYang
Copy link
Member

This PR modifies walk(), is_file(), and is_dir() to have the option to follow symlinks. This is needed for the situations where we are forced to deal with symlinked files.

    * Add missing dep `typing`

Signed-off-by: Jono Yang <jyang@nexb.com>
Signed-off-by: Jono Yang <jyang@nexb.com>
    * Install the toml extra_requires for setuptools_scm in setup_requires

Signed-off-by: Jono Yang <jyang@nexb.com>
Signed-off-by: Jono Yang <jyang@nexb.com>
@@ -45,20 +45,24 @@ def is_link(location):
return location and os.path.islink(location)


def is_file(location):
def is_file(location, allow_symlinks=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the same name as in the standard lib?
https://docs.python.org/3/library/os.html?highlight=link#os.link
https://docs.python.org/3/library/os.html?highlight=link#follow-symlinks

If follow_symlinks is False, and the last element of the path to operate on is a symbolic link, the function will operate on the symbolic link itself rather than the file pointed to by the link. (For POSIX systems, Python will call the l... variant of the function.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, I'll change it.

    * Test that resource_iter can follow symlinks

Signed-off-by: Jono Yang <jyang@nexb.com>
Copy link
Member

@pombredanne pombredanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JonoYang JonoYang merged commit d89c6b6 into main Oct 20, 2020
@JonoYang JonoYang deleted the visit-symlinks branch October 20, 2020 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants