summaryrefslogtreecommitdiff
path: root/setuptools/tests
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2022-08-19 17:36:38 +0100
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2022-08-19 18:22:05 +0100
commitce572dfe4aa5cad3c6889863a46dbac6e015b397 (patch)
treeb161341b0449714bbf782d51900b1ef9e83f27f6 /setuptools/tests
parente1fd1b447895dc8e8d4183d23e492d862608d258 (diff)
downloadpython-setuptools-git-ce572dfe4aa5cad3c6889863a46dbac6e015b397.tar.gz
Replicate problems with name discovery and dynamic versions
According to issue 3545 it seems that "name-discovery" happens, even when the project already explicitly sets it. This is related to parsing of dynamic versions (via `attr` directive), which triggers the auto-discovery to obtain the value of `package_dir`. The value of `package_dir` is used to find the path to the module in `version = {"attr" = "module_name.attr_name"}`.
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/test_config_discovery.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/setuptools/tests/test_config_discovery.py b/setuptools/tests/test_config_discovery.py
index f6c114af..85b64b31 100644
--- a/setuptools/tests/test_config_discovery.py
+++ b/setuptools/tests/test_config_discovery.py
@@ -517,6 +517,40 @@ def test_name_discovery_doesnt_break_cli(tmpdir_cwd):
assert dist.get_name() == "pkg"
+def test_preserve_explicit_name_with_dynamic_version(tmpdir_cwd, monkeypatch):
+ """According to #3545 it seems that ``name`` discovery is running,
+ even when the project already explicitly sets it.
+ This seems to be related to parsing of dynamic versions (via ``attr`` directive),
+ which requires the auto-discovery of ``package_dir``.
+ """
+ files = {
+ "src": {
+ "pkg": {"__init__.py": "__version__ = 42\n"},
+ },
+ "pyproject.toml": DALS("""
+ [project]
+ name = "myproj" # purposefully different from package name
+ dynamic = ["version"]
+ [tool.setuptools.dynamic]
+ version = {"attr" = "pkg.__version__"}
+ """)
+ }
+ jaraco.path.build(files)
+ dist = Distribution({})
+ orig_analyse_name = dist.set_defaults.analyse_name
+
+ def spy_analyse_name():
+ # We can check if name discovery was triggered by ensuring the original
+ # name remains instead of the package name.
+ orig_analyse_name()
+ assert dist.get_name() == "myproj"
+
+ monkeypatch.setattr(dist.set_defaults, "analyse_name", spy_analyse_name)
+ dist.parse_config_files()
+ assert dist.get_version() == "42"
+ assert set(dist.packages) == {"pkg"}
+
+
def _populate_project_dir(root, files, options):
# NOTE: Currently pypa/build will refuse to build the project if no
# `pyproject.toml` or `setup.py` is found. So it is impossible to do