Skip to content

Commit

Permalink
Fix problem with dynamic readme (#3247)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Apr 4, 2022
2 parents 3465cac + 760255d commit 58f0fb2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog.d/3247.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

0 comments on commit 58f0fb2

Please sign in to comment.