Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/3244.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed problem preventing ``readme`` specified as dynamic in ``pyproject.toml``
from being dynamically specified in ``setup.py``.
9 changes: 7 additions & 2 deletions setuptools/config/pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,17 @@ def _obtain_version(self, dist: "Distribution", package_dir: Mapping[str, str]):
return None

def _obtain_readme(self, dist: "Distribution") -> Optional[Dict[str, str]]:
if "readme" in self.dynamic:
dynamic_cfg = self.dynamic_cfg
if "readme" not in self.dynamic:
return None

dynamic_cfg = self.dynamic_cfg
if "readme" in dynamic_cfg:
return {
"text": self._obtain(dist, "readme", {}),
"content-type": dynamic_cfg["readme"].get("content-type", "text/x-rst"),
}

self._ensure_previously_set(dist, "readme")
return None

def _obtain_entry_points(
Expand Down
14 changes: 14 additions & 0 deletions setuptools/tests/config/test_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ def test_dynamic_without_config(self, tmp_path):
with pytest.raises(OptionError, match="No configuration .* .classifiers."):
read_configuration(pyproject)

def test_dynamic_readme_from_setup_script_args(self, tmp_path):
config = """
[project]
name = "myproj"
version = '42'
dynamic = ["readme"]
"""
pyproject = tmp_path / "pyproject.toml"
pyproject.write_text(cleandoc(config))
dist = Distribution(attrs={"long_description": "42"})
# No error should occur because of missing `readme`
dist = apply_configuration(dist, pyproject)
assert dist.metadata.long_description == "42"

def test_dynamic_without_file(self, tmp_path):
config = """
[project]
Expand Down