Skip to content

Commit 58f0fb2

Browse files
committed
Fix problem with dynamic readme (#3247)
2 parents 3465cac + 760255d commit 58f0fb2

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

changelog.d/3247.misc.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed problem preventing ``readme`` specified as dynamic in ``pyproject.toml``
2+
from being dynamically specified in ``setup.py``.

setuptools/config/pyprojecttoml.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,17 @@ def _obtain_version(self, dist: "Distribution", package_dir: Mapping[str, str]):
316316
return None
317317

318318
def _obtain_readme(self, dist: "Distribution") -> Optional[Dict[str, str]]:
319-
if "readme" in self.dynamic:
320-
dynamic_cfg = self.dynamic_cfg
319+
if "readme" not in self.dynamic:
320+
return None
321+
322+
dynamic_cfg = self.dynamic_cfg
323+
if "readme" in dynamic_cfg:
321324
return {
322325
"text": self._obtain(dist, "readme", {}),
323326
"content-type": dynamic_cfg["readme"].get("content-type", "text/x-rst"),
324327
}
328+
329+
self._ensure_previously_set(dist, "readme")
325330
return None
326331

327332
def _obtain_entry_points(

setuptools/tests/config/test_pyprojecttoml.py

+14
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,20 @@ def test_dynamic_without_config(self, tmp_path):
253253
with pytest.raises(OptionError, match="No configuration .* .classifiers."):
254254
read_configuration(pyproject)
255255

256+
def test_dynamic_readme_from_setup_script_args(self, tmp_path):
257+
config = """
258+
[project]
259+
name = "myproj"
260+
version = '42'
261+
dynamic = ["readme"]
262+
"""
263+
pyproject = tmp_path / "pyproject.toml"
264+
pyproject.write_text(cleandoc(config))
265+
dist = Distribution(attrs={"long_description": "42"})
266+
# No error should occur because of missing `readme`
267+
dist = apply_configuration(dist, pyproject)
268+
assert dist.metadata.long_description == "42"
269+
256270
def test_dynamic_without_file(self, tmp_path):
257271
config = """
258272
[project]

0 commit comments

Comments
 (0)