Skip to content

Commit

Permalink
Workaround when the deps are missing comma or has an empty space (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotrevisani authored Sep 19, 2023
1 parent f3e1a4c commit 30f052d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
17 changes: 16 additions & 1 deletion grayskull/strategy/py_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,21 @@ def ensure_pep440_in_req_list(list_req: List[str]) -> List[str]:
return [ensure_pep440(pkg) for pkg in list_req]


def split_deps(deps: str) -> List[str]:
deps = deps.split(",")
result = []
for d in deps:
constrain = ""
for val in re.split(r"([><!=~^]+)", d):
if not val:
continue
if {">", "<", "=", "!", "~", "^"} & set(val):
constrain = val.strip()
else:
result.append(f"{constrain}{val.strip()}")
return result


def ensure_pep440(pkg: str) -> str:
if not pkg:
return pkg
Expand All @@ -813,7 +828,7 @@ def ensure_pep440(pkg: str) -> str:
selector = f" {' '.join(split_pkg[hash_index:])}"
split_pkg = split_pkg[:hash_index]
constrain_pkg = "".join(split_pkg[1:])
list_constrains = constrain_pkg.split(",")
list_constrains = split_deps(constrain_pkg)
full_constrain = []
for constrain in list_constrains:
if "~=" in constrain:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_py_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
generic_py_ver_to,
get_sdist_metadata,
merge_deps_toml_setup,
split_deps,
update_requirements_with_pin,
)
from grayskull.utils import PyVer
Expand Down Expand Up @@ -117,3 +118,15 @@ def test_get_sdist_metadata_toml_files_BLACK():
"typing_extensions>=3.10.0.0; python_version < '3.10'",
"python >=3.7",
]


def test_split_deps_without_comma():
assert split_deps(">=1.8.0<3.0.0,!=2.0.1") == [">=1.8.0", "<3.0.0", "!=2.0.1"]


def test_split_deps():
assert split_deps(">=1.8.0,<3.0.0,!=2.0.1") == [">=1.8.0", "<3.0.0", "!=2.0.1"]


def test_split_deps_space():
assert split_deps(">=1.8.0 <3.0.0 !=2.0.1") == [">=1.8.0", "<3.0.0", "!=2.0.1"]

0 comments on commit 30f052d

Please sign in to comment.