Skip to content

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

Merged
JonoYang merged 5 commits into
mainfrom
visit-symlinks
Oct 20, 2020
Merged

Modify walk(), is_file(), and is_dir() to have the option to follow symlinks#2
JonoYang merged 5 commits into
mainfrom
visit-symlinks

Conversation

@JonoYang

Copy link
Copy Markdown
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>
Comment thread src/commoncode/filetype.py Outdated


def is_file(location):
def is_file(location, allow_symlinks=False):

Copy link
Copy Markdown
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
Copy Markdown
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>

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

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