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

Fix star operator #503

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions grayskull/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,20 @@ def rm_duplicated_deps(all_requirements: Union[list, set, None]) -> Optional[lis
# as it should be added.
# (This is order-preserving since dicts are ordered by first insertion.)
new_reqs: dict[str, str] = {}
re_split = re.compile(r"\s+|>|=|<|~|!|#")
re_split = re.compile(r"\s+(|>|=|<|~|!|#)+")
for dep in all_requirements:
if dep.strip().startswith(("{{", "<{")):
new_reqs[dep] = dep
continue
dep_name = re_split.split(dep.strip())[0].strip()
dep_name, *constrains = re_split.split(dep.strip())
dep_name = dep_name.strip()
constrains = [
c.strip()
for c in constrains
if c.strip() not in {"=*", "==*", "*", "*.*", "*.*.*", ""}
]
canonicalized = dep_name.replace("_", "-").lower()
constrains.insert(0, dep_name)
if canonicalized in new_reqs:
# In order to break ties deterministically, we prioritize the requirement
# which is alphanumerically lowest. This happens to prioritize the "-"
Expand All @@ -140,10 +147,10 @@ def rm_duplicated_deps(all_requirements: Union[list, set, None]) -> Optional[lis
# keep "importlib-metadata" because it is alphabetically lower.
previous_req = new_reqs[canonicalized]
if len(dep) > len(previous_req) or "-" in dep_name:
new_reqs[canonicalized] = dep
new_reqs[canonicalized] = " ".join(constrains)
else:
new_reqs[canonicalized] = dep
return list(new_reqs.values())
new_reqs[canonicalized] = " ".join(constrains)
return [re.sub(r"\s+(#)", " \\1", v.strip()) for v in new_reqs.values()]


def format_dependencies(all_dependencies: List, name: str) -> List:
Expand All @@ -162,7 +169,7 @@ def format_dependencies(all_dependencies: List, name: str) -> List:
for req in all_dependencies:
match_req = re_deps.match(req)
deps_name = req
if deps_name.replace("-", "_") == name.replace("-", "_"):
if name is not None and deps_name.replace("-", "_") == name.replace("-", "_"):
continue
if match_req:
match_req = match_req.groups()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_extract_pypi_requirements(pypi_metadata, recipe_config):
"pathlib2 >=2.2.0 # [py<36]",
"importlib-metadata >=0.12 # [py<38]",
"atomicwrites >=1.0 # [win]",
"colorama # [win]",
"colorama # [win]",
]
)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,9 @@ def test_rm_duplicated_deps():
assert rm_duplicated_deps([]) is None
# my-crazy-pkg is preferred because "my-crazy-pkg" < "my_craZy-pkg":
assert rm_duplicated_deps(["my_craZy-pkg", "my-crazy-pkg"]) == ["my-crazy-pkg"]


def test_rm_dupliate_deps_with_star():
assert rm_duplicated_deps(["typing-extensions", "typing_extensions *"]) == [
"typing_extensions"
]
Loading