Imported Upstream version 65.3.0 upstream/65.3.0
authorJinWang An <jinwang.an@samsung.com>
Mon, 27 Mar 2023 08:02:56 +0000 (17:02 +0900)
committerJinWang An <jinwang.an@samsung.com>
Mon, 27 Mar 2023 08:02:56 +0000 (17:02 +0900)
.bumpversion.cfg
CHANGES.rst
docs/userguide/quickstart.rst
setup.cfg
setuptools/command/editable_wheel.py
setuptools/config/pyprojecttoml.py
setuptools/discovery.py
setuptools/tests/test_config_discovery.py
setuptools/tests/test_editable_install.py

index cf3c02a9ac4d3e43f8887ea531afc2fb221bdf75..f90d1027f206cbb4ad6b291f83685fe102895399 100644 (file)
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 65.2.0
+current_version = 65.3.0
 commit = True
 tag = True
 
index 09a7c1bcbdc73dd656a3859c6f3218fe79c2836a..8e35e3f696f274bd5484b44f21fbd096bc2f04da 100644 (file)
@@ -1,3 +1,20 @@
+v65.3.0
+-------
+
+
+Changes
+^^^^^^^
+* #3547: Stop ``ConfigDiscovery.analyse_name`` from splatting the ``Distribution.name`` attribute -- by :user:`jeamland`
+
+Documentation changes
+^^^^^^^^^^^^^^^^^^^^^
+* #3554: Changed requires to requests in the pyproject.toml example in the :ref:`Dependency management section of the Quickstart guide <userguide/quickstart:dependency-management>` -- by :user:`mfbutner`
+
+Misc
+^^^^
+* #3561: Fixed accidental name matching in editable hooks.
+
+
 v65.2.0
 -------
 
@@ -50,7 +67,7 @@ Documentation changes
 
 Misc
 ^^^^
-* #3526: Fix backward compatibility of editable installs and custom ``build_ext``
+* #3526: Fixed backward compatibility of editable installs and custom ``build_ext``
   commands inheriting directly from ``distutils``.
 * #3528: Fixed ``buid_meta.prepare_metadata_for_build_wheel`` when
   given ``metadata_directory`` is ``"."``.
index e2afdb8b5dd84cdbf6a3bddba32eb9018543aef2..13846e205102b7b9347cd6382ad486f89ff00528 100644 (file)
@@ -309,7 +309,7 @@ The example below show how to configure this kind of dependencies:
         # ...
         dependencies = [
             "docutils",
-            "requires <= 0.4",
+            "requests <= 0.4",
         ]
         # ...
 
index 16fe9510b9ddc304244285c9c80954abbff948c6..3d260d5216fba52960c7d82d4505da191d264918 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
 [metadata]
 name = setuptools
-version = 65.2.0
+version = 65.3.0
 author = Python Packaging Authority
 author_email = distutils-sig@python.org
 description = Easily download, build, install, upgrade, and uninstall Python packages
@@ -19,6 +19,7 @@ classifiers =
 keywords = CPAN PyPI distutils eggs package management
 project_urls =
        Documentation = https://setuptools.pypa.io/
+       Changelog = https://setuptools.pypa.io/en/stable/history.html
 
 [options]
 packages = find_namespace:
index b908298f4a3baf791108ef8b5b6f9b5fa9f5b479..d05c3a75e9fb904a6ea4a9f408cc96a2ce854490 100644 (file)
@@ -758,7 +758,7 @@ class _EditableFinder:  # MetaPathFinder
     @classmethod
     def find_spec(cls, fullname, path=None, target=None):
         for pkg, pkg_path in reversed(list(MAPPING.items())):
-            if fullname.startswith(pkg):
+            if fullname == pkg or fullname.startswith(f"{{pkg}}."):
                 rest = fullname.replace(pkg, "", 1).strip(".").split(".")
                 return cls._find_spec(fullname, Path(pkg_path, *rest))
 
index 9ff0c87fa82c8876577f4a2f0cf0ba93fcf3d71b..d995f0bcc7e322d50af91ee23f3241d8cf46e637 100644 (file)
@@ -234,8 +234,8 @@ class _ConfigExpander:
 
         # A distribution object is required for discovering the correct package_dir
         dist = self._ensure_dist()
-
-        with _EnsurePackagesDiscovered(dist, self.setuptools_cfg) as ensure_discovered:
+        ctx = _EnsurePackagesDiscovered(dist, self.project_cfg, self.setuptools_cfg)
+        with ctx as ensure_discovered:
             package_dir = ensure_discovered.package_dir
             self._expand_data_files()
             self._expand_cmdclass(package_dir)
@@ -428,8 +428,11 @@ def _ignore_errors(ignore_option_errors: bool):
 
 
 class _EnsurePackagesDiscovered(_expand.EnsurePackagesDiscovered):
-    def __init__(self, distribution: "Distribution", setuptools_cfg: dict):
+    def __init__(
+        self, distribution: "Distribution", project_cfg: dict, setuptools_cfg: dict
+    ):
         super().__init__(distribution)
+        self._project_cfg = project_cfg
         self._setuptools_cfg = setuptools_cfg
 
     def __enter__(self):
@@ -443,8 +446,10 @@ class _EnsurePackagesDiscovered(_expand.EnsurePackagesDiscovered):
 
         dist.set_defaults._ignore_ext_modules()  # pyproject.toml-specific behaviour
 
-        # Set `py_modules` and `packages` in dist to short-circuit auto-discovery,
-        # but avoid overwriting empty lists purposefully set by users.
+        # Set `name`, `py_modules` and `packages` in dist to short-circuit
+        # auto-discovery, but avoid overwriting empty lists purposefully set by users.
+        if dist.metadata.name is None:
+            dist.metadata.name = self._project_cfg.get("name")
         if dist.py_modules is None:
             dist.py_modules = cfg.get("py-modules")
         if dist.packages is None:
index 6a3d2c9d2e610e0dd769fc05a00b25f677bc3d42..98fc2a7f487da55a23b962793158911848800211 100644 (file)
@@ -481,7 +481,6 @@ class ConfigDiscovery:
         )
         if name:
             self.dist.metadata.name = name
-            self.dist.name = name
 
     def _find_name_single_package_or_module(self) -> Optional[str]:
         """Exactly one module or package"""
index fac365f4107b12b86e7123d8f54af1f09f3b5344..85b64b31dde987034f5a4308cc7c14d87bf3a019 100644 (file)
@@ -508,6 +508,49 @@ def test_compatible_with_numpy_configuration(tmp_path):
     assert dist.packages is None
 
 
+def test_name_discovery_doesnt_break_cli(tmpdir_cwd):
+    jaraco.path.build({"pkg.py": ""})
+    dist = Distribution({})
+    dist.script_args = ["--name"]
+    dist.set_defaults()
+    dist.parse_command_line()  # <-- no exception should be raised here.
+    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
index 4a2ceb12f997970036497d1fdb5c738fc3a7b516..c8ee74778bc1ffa41c0e3be31e8d45a3695c0bc4 100644 (file)
@@ -515,6 +515,30 @@ class TestFinderTemplate:
             with pytest.raises(ImportError, match="pkg"):
                 import_module("pkg")
 
+    def test_similar_name(self, tmp_path):
+        files = {
+            "foo": {
+                "__init__.py": "",
+                "bar": {
+                    "__init__.py": "",
+                }
+            },
+        }
+        jaraco.path.build(files, prefix=tmp_path)
+
+        mapping = {
+            "foo": str(tmp_path / "foo"),
+        }
+        template = _finder_template(str(uuid4()), mapping, {})
+
+        with contexts.save_paths(), contexts.save_sys_modules():
+            sys.modules.pop("foo", None)
+            sys.modules.pop("foo.bar", None)
+
+            self.install_finder(template)
+            with pytest.raises(ImportError, match="foobar"):
+                import_module("foobar")
+
 
 def test_pkg_roots(tmp_path):
     """This test focus in getting a particular implementation detail right.