From 971fa459dda6f9f80557d0e5c741807288938143 Mon Sep 17 00:00:00 2001 From: Marcelo Trevisani Date: Thu, 12 Oct 2023 06:47:59 +0100 Subject: [PATCH 1/3] Fix when a start operator is inplace that can lead to wrong name clashing with the same package name without a star --- grayskull/utils.py | 11 ++++++++--- tests/test_utils.py | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/grayskull/utils.py b/grayskull/utils.py index 44dff95c0..365ce13b5 100644 --- a/grayskull/utils.py +++ b/grayskull/utils.py @@ -130,8 +130,13 @@ def rm_duplicated_deps(all_requirements: Union[list, set, None]) -> Optional[lis 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 "-" @@ -140,9 +145,9 @@ 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 + new_reqs[canonicalized] = " ".join(constrains) return list(new_reqs.values()) diff --git a/tests/test_utils.py b/tests/test_utils.py index a08757915..575f101b8 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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" + ] From 9c7284ad82bbc4077372e04024c7e5c4cbb2a525 Mon Sep 17 00:00:00 2001 From: Marcelo Trevisani Date: Thu, 19 Oct 2023 06:00:37 +0100 Subject: [PATCH 2/3] Match constrains and readded them after processing --- grayskull/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/grayskull/utils.py b/grayskull/utils.py index 365ce13b5..d15e8bca9 100644 --- a/grayskull/utils.py +++ b/grayskull/utils.py @@ -125,7 +125,7 @@ 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 @@ -133,7 +133,9 @@ def rm_duplicated_deps(all_requirements: Union[list, set, None]) -> Optional[lis 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 {"*", "*.*", "*.*.*"} + c.strip() + for c in constrains + if c.strip() not in {"=*", "==*", "*", "*.*", "*.*.*"} ] canonicalized = dep_name.replace("_", "-").lower() constrains.insert(0, dep_name) @@ -167,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() From 5b7a00f2b2c011ea774e9353a36182ce7e7f8a0f Mon Sep 17 00:00:00 2001 From: Marcelo Trevisani Date: Thu, 19 Oct 2023 06:33:28 +0100 Subject: [PATCH 3/3] Fix empty space before comment --- grayskull/utils.py | 4 ++-- tests/test_pypi.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/grayskull/utils.py b/grayskull/utils.py index d15e8bca9..7100f98d3 100644 --- a/grayskull/utils.py +++ b/grayskull/utils.py @@ -135,7 +135,7 @@ def rm_duplicated_deps(all_requirements: Union[list, set, None]) -> Optional[lis constrains = [ c.strip() for c in constrains - if c.strip() not in {"=*", "==*", "*", "*.*", "*.*.*"} + if c.strip() not in {"=*", "==*", "*", "*.*", "*.*.*", ""} ] canonicalized = dep_name.replace("_", "-").lower() constrains.insert(0, dep_name) @@ -150,7 +150,7 @@ def rm_duplicated_deps(all_requirements: Union[list, set, None]) -> Optional[lis new_reqs[canonicalized] = " ".join(constrains) else: new_reqs[canonicalized] = " ".join(constrains) - return list(new_reqs.values()) + return [re.sub(r"\s+(#)", " \\1", v.strip()) for v in new_reqs.values()] def format_dependencies(all_dependencies: List, name: str) -> List: diff --git a/tests/test_pypi.py b/tests/test_pypi.py index e537f4947..aed04c8e7 100644 --- a/tests/test_pypi.py +++ b/tests/test_pypi.py @@ -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]", ] )