Skip to content

Commit 0a15141

Browse files
committed
Handle strings in pyprject.toml's tool.setuptools.dynamic.*.file (#3782)
2 parents f23c915 + e99c7e0 commit 0a15141

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

changelog.d/3782.misc.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed problem with ``file`` directive in ``tool.setuptools.dynamic``
2+
(``pyproject.toml``) when value is a simple string instead of list.

setuptools/config/pyprojecttoml.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,12 @@ def _ensure_previously_set(self, dist: "Distribution", field: str):
309309
def _expand_directive(
310310
self, specifier: str, directive, package_dir: Mapping[str, str]
311311
):
312+
from setuptools.extern.more_itertools import always_iterable # type: ignore
313+
312314
with _ignore_errors(self.ignore_option_errors):
313315
root_dir = self.root_dir
314316
if "file" in directive:
315-
self._referenced_files.update(directive["file"])
317+
self._referenced_files.update(always_iterable(directive["file"]))
316318
return _expand.read_files(directive["file"], root_dir)
317319
if "attr" in directive:
318320
return _expand.read_attr(directive["attr"], package_dir, root_dir)

setuptools/tests/test_sdist.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def test_sdist_with_latin1_encoded_filename(self):
502502
"setup.cfg - long_description and version": """
503503
[metadata]
504504
name = testing
505-
version = file: VERSION.txt
505+
version = file: src/VERSION.txt
506506
license_files = DOWHATYOUWANT
507507
long_description = file: README.rst, USAGE.rst
508508
""",
@@ -513,15 +513,25 @@ def test_sdist_with_latin1_encoded_filename(self):
513513
license = {file = "DOWHATYOUWANT"}
514514
dynamic = ["version"]
515515
[tool.setuptools.dynamic]
516-
version = {file = ["VERSION.txt"]}
516+
version = {file = ["src/VERSION.txt"]}
517+
""",
518+
"pyproject.toml - directive with str instead of list": """
519+
[project]
520+
name = "testing"
521+
readme = "USAGE.rst"
522+
license = {file = "DOWHATYOUWANT"}
523+
dynamic = ["version"]
524+
[tool.setuptools.dynamic]
525+
version = {file = "src/VERSION.txt"}
517526
"""
518527
}
519528

520529
@pytest.mark.parametrize("config", _EXAMPLE_DIRECTIVES.keys())
521530
def test_add_files_referenced_by_config_directives(self, tmp_path, config):
522531
config_file, _, _ = config.partition(" - ")
523532
config_text = self._EXAMPLE_DIRECTIVES[config]
524-
(tmp_path / 'VERSION.txt').write_text("0.42", encoding="utf-8")
533+
(tmp_path / 'src').mkdir()
534+
(tmp_path / 'src/VERSION.txt').write_text("0.42", encoding="utf-8")
525535
(tmp_path / 'README.rst').write_text("hello world!", encoding="utf-8")
526536
(tmp_path / 'USAGE.rst').write_text("hello world!", encoding="utf-8")
527537
(tmp_path / 'DOWHATYOUWANT').write_text("hello world!", encoding="utf-8")
@@ -536,9 +546,14 @@ def test_add_files_referenced_by_config_directives(self, tmp_path, config):
536546
with quiet():
537547
cmd.run()
538548

539-
assert 'VERSION.txt' in cmd.filelist.files
549+
assert (
550+
'src/VERSION.txt' in cmd.filelist.files
551+
or 'src\\VERSION.txt' in cmd.filelist.files
552+
)
540553
assert 'USAGE.rst' in cmd.filelist.files
541554
assert 'DOWHATYOUWANT' in cmd.filelist.files
555+
assert '/' not in cmd.filelist.files
556+
assert '\\' not in cmd.filelist.files
542557

543558
def test_pyproject_toml_in_sdist(self, tmpdir):
544559
"""

0 commit comments

Comments
 (0)