Skip to content

Commit

Permalink
Improve backwards compatibility with deprecated CLI practices (#4048)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Sep 12, 2023
2 parents e3d5edd + facbb75 commit 74cc26c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions newsfragments/4048.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve backwards compatibility with deprecated CLI practices.
6 changes: 3 additions & 3 deletions setuptools/config/_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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):
Expand Down
19 changes: 19 additions & 0 deletions setuptools/tests/config/test_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---


Expand Down

0 comments on commit 74cc26c

Please sign in to comment.