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

iter_metadata would unexpectly find another package's metadata #186

Closed
frostming opened this issue Sep 30, 2019 · 2 comments · Fixed by #187
Closed

iter_metadata would unexpectly find another package's metadata #186

frostming opened this issue Sep 30, 2019 · 2 comments · Fixed by #187

Comments

@frostming
Copy link
Member

frostming commented Sep 30, 2019

def iter_metadata(path, pkg_name=None, metadata_type="egg-info"):
# type: (AnyStr, Optional[AnyStr], AnyStr) -> Generator
if pkg_name is not None:
pkg_variants = get_name_variants(pkg_name)
non_matching_dirs = []
with contextlib.closing(ScandirCloser(path)) as path_iterator:
for entry in path_iterator:
if entry.is_dir():
entry_name, ext = os.path.splitext(entry.name)
if ext.endswith(metadata_type):
if pkg_name is None or entry_name.lower() in pkg_variants:
yield entry
elif not entry.name.endswith(metadata_type):
non_matching_dirs.append(entry)
for entry in non_matching_dirs:
for dir_entry in iter_metadata(
entry.path, pkg_name=pkg_name, metadata_type=metadata_type
):
yield dir_entry

iter_metadata() scans metadata that ends with given pattern inside a path recursively, which would return unexpected results in some cases, here is the directory tree of one:

├───.venv    # We have a .venv folder here
│   ├───Include
│   ├───Lib
│   │   └───site-packages
│   │       ├───pip
│   │       ├───pip-19.0.3.dist-info   # pip metadata will be returned
├───src
│   ├───requirementslib
...

Testing:

r = requirements.Requirement.from_line('-e .')
print(r.ireq)

The possible solution is to change the DFS method to BFS.

@uranusjr
Copy link
Member

uranusjr commented Oct 2, 2019

I don’t have time to read the actual PR implementation, but using BFS sounds like the correct idea.

@techalchemy
Copy link
Member

I believe I had this implemented at one time and it was terribly broken, but I could be mistaken. at a glance it seems right

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 a pull request may close this issue.

3 participants