From 566f2948d2fc452109da4e0cf20ac4e113e07809 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 12 Sep 2023 13:31:55 +0100 Subject: [PATCH 1/3] Test command line parsing of '--version' interoperates with pyproject.toml --- .../tests/config/test_apply_pyprojecttoml.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/setuptools/tests/config/test_apply_pyprojecttoml.py b/setuptools/tests/config/test_apply_pyprojecttoml.py index c0c6b13392..294947a00a 100644 --- a/setuptools/tests/config/test_apply_pyprojecttoml.py +++ b/setuptools/tests/config/test_apply_pyprojecttoml.py @@ -423,6 +423,25 @@ def test_example_file_not_in_wheel(self, setuptools_wheel): assert not any(name.endswith(EXAMPLES_FILE) for name in zipfile.namelist()) +class TestInteropCommandLineParsing: + def test_version(self, tmp_path, monkeypatch, capsys): + # See pypa/setuptools#4047 + # This test can be removed once the CLI interface of setup.py is removed + monkeypatch.chdir(tmp_path) + toml_config = """ + [project] + name = "test" + version = "42.0" + """ + pyproject = Path(tmp_path, "pyproject.toml") + pyproject.write_text(cleandoc(toml_config), encoding="utf-8") + opts = {"script_args": ["--version"]} + dist = pyprojecttoml.apply_configuration(Distribution(opts), pyproject) + dist.parse_command_line() # <-- there should be no exception here. + captured = capsys.readouterr() + assert "42.0" in captured.out + + # --- Auxiliary Functions --- From 7b7971e6b08c2a9586e4699312371bb5ae19df9b Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 12 Sep 2023 13:41:29 +0100 Subject: [PATCH 2/3] Set requirements attributes directly into dist when parsing pyproject.toml --- setuptools/config/_apply_pyprojecttoml.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setuptools/config/_apply_pyprojecttoml.py b/setuptools/config/_apply_pyprojecttoml.py index b6443308bf..4489d22437 100644 --- a/setuptools/config/_apply_pyprojecttoml.py +++ b/setuptools/config/_apply_pyprojecttoml.py @@ -125,7 +125,7 @@ def _set_config(dist: "Distribution", field: str, value: Any): setter(value) elif hasattr(dist.metadata, field) or field in SETUPTOOLS_PATCHES: setattr(dist.metadata, field, value) - if hasattr(dist, field): + else: setattr(dist, field, value) @@ -212,12 +212,12 @@ def _dependencies(dist: "Distribution", val: list, _root_dir): if getattr(dist, "install_requires", []): msg = "`install_requires` overwritten in `pyproject.toml` (dependencies)" SetuptoolsWarning.emit(msg) - _set_config(dist, "install_requires", val) + dist.install_requires = val def _optional_dependencies(dist: "Distribution", val: dict, _root_dir): existing = getattr(dist, "extras_require", None) or {} - _set_config(dist, "extras_require", {**existing, **val}) + dist.extras_require = {**existing, **val} def _unify_entry_points(project_table: dict): From facbb757dbef0641fb12b550f07d1da2edd6ed6a Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 12 Sep 2023 13:51:53 +0100 Subject: [PATCH 3/3] Add news fragment --- newsfragments/4048.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/4048.bugfix.rst diff --git a/newsfragments/4048.bugfix.rst b/newsfragments/4048.bugfix.rst new file mode 100644 index 0000000000..cb8407ed5d --- /dev/null +++ b/newsfragments/4048.bugfix.rst @@ -0,0 +1 @@ +Improve backwards compatibility with deprecated CLI practices.