Skip to content

Commit

Permalink
Fix previous detection of empty arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Mar 27, 2022
1 parent 2304d99 commit 603bb98
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setuptools/config/_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def _some_attrgetter(*items):
"""
def _acessor(obj):
values = (_attrgetter(i)(obj) for i in items)
return next((i for i in values if i), None)
return next((i for i in values if i is not None), None)
return _acessor


Expand Down
5 changes: 3 additions & 2 deletions setuptools/config/pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,12 @@ def _expand_all_dynamic(self, dist: "Distribution", package_dir: Mapping[str, st
)
# `None` indicates there is nothing in `tool.setuptools.dynamic` but the value
# might have already been set by setup.py/extensions, so avoid overwriting.
self.project_cfg.update({k: v for k, v in obtained_dynamic.items() if v})
updates = {k: v for k, v in obtained_dynamic.items() if v is not None}
self.project_cfg.update(updates)

def _ensure_previously_set(self, dist: "Distribution", field: str):
previous = _PREVIOUSLY_DEFINED[field](dist)
if not previous and not self.ignore_option_errors:
if previous is None and not self.ignore_option_errors:
msg = (
f"No configuration found for dynamic {field!r}.\n"
"Some dynamic fields need to be specified via `tool.setuptools.dynamic`"
Expand Down
8 changes: 5 additions & 3 deletions setuptools/tests/config/test_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from setuptools.dist import Distribution
from setuptools.config import setupcfg, pyprojecttoml
from setuptools.config import expand
from setuptools.config._apply_pyprojecttoml import _WouldIgnoreField
from setuptools.config._apply_pyprojecttoml import _WouldIgnoreField, _some_attrgetter
from setuptools.command.egg_info import write_requirements


Expand Down Expand Up @@ -234,12 +234,14 @@ def test_not_listed_in_dynamic(self, tmp_path, attr, field, value):
dist = pyprojecttoml.apply_configuration(dist, pyproject)

# TODO: Once support for pyproject.toml config stabilizes attr should be None
dist_value = getattr(dist, attr, None) or getattr(dist.metadata, attr, object())
dist_value = _some_attrgetter(f"metadata.{attr}", attr)(dist)
assert dist_value == value

@pytest.mark.parametrize(
"attr, field, value",
[
("install_requires", "dependencies", []),
("extras_require", "optional-dependencies", {}),
("install_requires", "dependencies", ["six"]),
("classifiers", "classifiers", ["Private :: Classifier"]),
]
Expand All @@ -248,7 +250,7 @@ def test_listed_in_dynamic(self, tmp_path, attr, field, value):
pyproject = self.pyproject(tmp_path, [field])
dist = makedist(tmp_path, **{attr: value})
dist = pyprojecttoml.apply_configuration(dist, pyproject)
dist_value = getattr(dist, attr, None) or getattr(dist.metadata, attr, object())
dist_value = _some_attrgetter(f"metadata.{attr}", attr)(dist)
assert dist_value == value

def test_optional_dependencies_dont_remove_env_markers(self, tmp_path):
Expand Down

0 comments on commit 603bb98

Please sign in to comment.