Skip to content

Commit 603bb98

Browse files
committed
Fix previous detection of empty arrays
1 parent 2304d99 commit 603bb98

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

setuptools/config/_apply_pyprojecttoml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def _some_attrgetter(*items):
303303
"""
304304
def _acessor(obj):
305305
values = (_attrgetter(i)(obj) for i in items)
306-
return next((i for i in values if i), None)
306+
return next((i for i in values if i is not None), None)
307307
return _acessor
308308

309309

setuptools/config/pyprojecttoml.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,12 @@ def _expand_all_dynamic(self, dist: "Distribution", package_dir: Mapping[str, st
282282
)
283283
# `None` indicates there is nothing in `tool.setuptools.dynamic` but the value
284284
# might have already been set by setup.py/extensions, so avoid overwriting.
285-
self.project_cfg.update({k: v for k, v in obtained_dynamic.items() if v})
285+
updates = {k: v for k, v in obtained_dynamic.items() if v is not None}
286+
self.project_cfg.update(updates)
286287

287288
def _ensure_previously_set(self, dist: "Distribution", field: str):
288289
previous = _PREVIOUSLY_DEFINED[field](dist)
289-
if not previous and not self.ignore_option_errors:
290+
if previous is None and not self.ignore_option_errors:
290291
msg = (
291292
f"No configuration found for dynamic {field!r}.\n"
292293
"Some dynamic fields need to be specified via `tool.setuptools.dynamic`"

setuptools/tests/config/test_apply_pyprojecttoml.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from setuptools.dist import Distribution
1515
from setuptools.config import setupcfg, pyprojecttoml
1616
from setuptools.config import expand
17-
from setuptools.config._apply_pyprojecttoml import _WouldIgnoreField
17+
from setuptools.config._apply_pyprojecttoml import _WouldIgnoreField, _some_attrgetter
1818
from setuptools.command.egg_info import write_requirements
1919

2020

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

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

240240
@pytest.mark.parametrize(
241241
"attr, field, value",
242242
[
243+
("install_requires", "dependencies", []),
244+
("extras_require", "optional-dependencies", {}),
243245
("install_requires", "dependencies", ["six"]),
244246
("classifiers", "classifiers", ["Private :: Classifier"]),
245247
]
@@ -248,7 +250,7 @@ def test_listed_in_dynamic(self, tmp_path, attr, field, value):
248250
pyproject = self.pyproject(tmp_path, [field])
249251
dist = makedist(tmp_path, **{attr: value})
250252
dist = pyprojecttoml.apply_configuration(dist, pyproject)
251-
dist_value = getattr(dist, attr, None) or getattr(dist.metadata, attr, object())
253+
dist_value = _some_attrgetter(f"metadata.{attr}", attr)(dist)
252254
assert dist_value == value
253255

254256
def test_optional_dependencies_dont_remove_env_markers(self, tmp_path):

0 commit comments

Comments
 (0)