Skip to content

Commit

Permalink
fix extras_require issue
Browse files Browse the repository at this point in the history
  • Loading branch information
woutdenolf committed May 12, 2022
1 parent 4844d8d commit 49d7884
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 17 deletions.
27 changes: 10 additions & 17 deletions grayskull/strategy/py_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from grayskull.utils import (
PyVer,
get_vendored_dependencies,
merge_dict_of_lists_item,
merge_list_item,
origin_is_github,
sha256_checksum,
)
Expand Down Expand Up @@ -256,23 +258,14 @@ def merge_sdist_metadata(setup_py: dict, setup_cfg: dict) -> dict:
if key not in result:
result[key] = value

def get_full_list(sec_key: str) -> List:
if sec_key not in setup_py:
return setup_cfg.get(sec_key, [])
cfg_val = set(setup_cfg.get(sec_key, []))
result_val = set(result.get(sec_key, []))
return list(cfg_val.union(result_val))

if "install_requires" in result:
result["install_requires"] = get_full_list("install_requires")
if "extras_require" in result:
result["extras_require"] = get_full_list("extras_require")
if "setup_requires" in result:
result["setup_requires"] = get_full_list("setup_requires")
if "setuptools-scm" in result["setup_requires"]:
result["setup_requires"].remove("setuptools-scm")
if "compilers" in result:
result["compilers"] = get_full_list("compilers")
merge_list_item(result, setup_cfg, "install_requires")
merge_list_item(result, setup_cfg, "setup_requires")
merge_list_item(result, setup_cfg, "compilers")
merge_dict_of_lists_item(result, setup_cfg, "extras_require")

if "setuptools-scm" in result.get("setup_requires", []):
result["setup_requires"].remove("setuptools-scm")

return result


Expand Down
16 changes: 16 additions & 0 deletions grayskull/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,19 @@ def _clean_yaml(recipe, all_obj_to_delete=None):
value_to_delete = _clean_yaml(value)
all_obj_to_delete.extend(value_to_delete)
return all_obj_to_delete


def merge_list_item(destination: dict, add: dict, key: str) -> None:
lst = set(destination.get(key, []))
lst |= set(add.get(key, []))
if lst:
destination[key] = list(lst)


def merge_dict_of_lists_item(destination: dict, add: dict, key: str) -> None:
sub_destination = destination.get(key, {})
sub_add = add.get(key, {})
for sub_key in set(sub_destination) | set(sub_add):
merge_list_item(sub_destination, sub_add, sub_key)
if sub_destination:
destination[key] = sub_destination
61 changes: 61 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
get_all_modules_imported_script,
get_std_modules,
get_vendored_dependencies,
merge_dict_of_lists_item,
merge_list_item,
origin_is_local_sdist,
)

Expand Down Expand Up @@ -57,3 +59,62 @@ def test_origin_is_not_local_sdist_file(tmp_path):
)
def test_origin_is_not_local_sdist_filename(filename):
assert not origin_is_local_sdist(filename)


def test_merge_lists_item():
destination = {}
add = {}
merge_list_item(destination, add, "name")
assert destination == {}

destination = {"name": [1]}
add = {}
merge_list_item(destination, add, "name")
destination = {key: set(lst) for key, lst in destination.items()}
assert destination == {"name": {1}}

destination = {}
add = {"name": [2]}
merge_list_item(destination, add, "name")
destination = {key: set(lst) for key, lst in destination.items()}
assert destination == {"name": {2}}

destination = {"name": [1]}
add = {"name": [2]}
merge_list_item(destination, add, "name")
destination = {key: set(lst) for key, lst in destination.items()}
assert destination == {"name": {1, 2}}


def test_merge_dict_of_lists_item():
destination = {}
add = {}
merge_dict_of_lists_item(destination, add, "name")
assert destination == {}

destination = {"name": {"sub_name": [1]}}
add = {}
merge_dict_of_lists_item(destination, add, "name")
for key in destination:
destination[key] = {
sub_key: set(lst) for sub_key, lst in destination[key].items()
}
assert destination == {"name": {"sub_name": {1}}}

destination = {}
add = {"name": {"sub_name": [2]}}
merge_dict_of_lists_item(destination, add, "name")
for key in destination:
destination[key] = {
sub_key: set(lst) for sub_key, lst in destination[key].items()
}
assert destination == {"name": {"sub_name": {2}}}

destination = {"name": {"sub_name": [1]}}
add = {"name": {"sub_name": [2]}}
merge_dict_of_lists_item(destination, add, "name")
for key in destination:
destination[key] = {
sub_key: set(lst) for sub_key, lst in destination[key].items()
}
assert destination == {"name": {"sub_name": {1, 2}}}

0 comments on commit 49d7884

Please sign in to comment.