Skip to content

Commit 74cc26c

Browse files
committed
Improve backwards compatibility with deprecated CLI practices (#4048)
2 parents e3d5edd + facbb75 commit 74cc26c

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

newsfragments/4048.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve backwards compatibility with deprecated CLI practices.

setuptools/config/_apply_pyprojecttoml.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _set_config(dist: "Distribution", field: str, value: Any):
125125
setter(value)
126126
elif hasattr(dist.metadata, field) or field in SETUPTOOLS_PATCHES:
127127
setattr(dist.metadata, field, value)
128-
if hasattr(dist, field):
128+
else:
129129
setattr(dist, field, value)
130130

131131

@@ -212,12 +212,12 @@ def _dependencies(dist: "Distribution", val: list, _root_dir):
212212
if getattr(dist, "install_requires", []):
213213
msg = "`install_requires` overwritten in `pyproject.toml` (dependencies)"
214214
SetuptoolsWarning.emit(msg)
215-
_set_config(dist, "install_requires", val)
215+
dist.install_requires = val
216216

217217

218218
def _optional_dependencies(dist: "Distribution", val: dict, _root_dir):
219219
existing = getattr(dist, "extras_require", None) or {}
220-
_set_config(dist, "extras_require", {**existing, **val})
220+
dist.extras_require = {**existing, **val}
221221

222222

223223
def _unify_entry_points(project_table: dict):

setuptools/tests/config/test_apply_pyprojecttoml.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,25 @@ def test_example_file_not_in_wheel(self, setuptools_wheel):
423423
assert not any(name.endswith(EXAMPLES_FILE) for name in zipfile.namelist())
424424

425425

426+
class TestInteropCommandLineParsing:
427+
def test_version(self, tmp_path, monkeypatch, capsys):
428+
# See pypa/setuptools#4047
429+
# This test can be removed once the CLI interface of setup.py is removed
430+
monkeypatch.chdir(tmp_path)
431+
toml_config = """
432+
[project]
433+
name = "test"
434+
version = "42.0"
435+
"""
436+
pyproject = Path(tmp_path, "pyproject.toml")
437+
pyproject.write_text(cleandoc(toml_config), encoding="utf-8")
438+
opts = {"script_args": ["--version"]}
439+
dist = pyprojecttoml.apply_configuration(Distribution(opts), pyproject)
440+
dist.parse_command_line() # <-- there should be no exception here.
441+
captured = capsys.readouterr()
442+
assert "42.0" in captured.out
443+
444+
426445
# --- Auxiliary Functions ---
427446

428447

0 commit comments

Comments
 (0)