diff --git a/grayskull/strategy/py_base.py b/grayskull/strategy/py_base.py index 76a185535..224578965 100644 --- a/grayskull/strategy/py_base.py +++ b/grayskull/strategy/py_base.py @@ -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"([>", "<", "=", "!", "~", "^"} & 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 @@ -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: diff --git a/tests/test_py_base.py b/tests/test_py_base.py index 8e711162e..3774220f1 100644 --- a/tests/test_py_base.py +++ b/tests/test_py_base.py @@ -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 @@ -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"]