From c22fd02b835c9301a5b05b25af38766f1c616d3c Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 24 May 2024 13:25:37 +0100 Subject: [PATCH 01/10] Simplify tool.setuptools.packages.find by using include rule --- pyproject.toml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7e9e66df9f..dd2140473a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -158,15 +158,14 @@ PKG-INFO = "setuptools.command.egg_info:write_pkg_info" include-package-data = false [tool.setuptools.packages.find] +include = [ + "setuptools*", + "pkg_resources*", + "_distutils_hack*", +] exclude = [ "*.tests", "*.tests.*", - "tools*", - "debian*", - "launcher*", - "newsfragments*", - "docs", - "docs.*", ] namespaces = true From 63a2eb3b8246be5a6b50a837b26175e0c8cb6cf8 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 19 Jun 2024 10:12:59 +0100 Subject: [PATCH 02/10] Fix undefined log function in bdist_wheel --- setuptools/command/bdist_wheel.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setuptools/command/bdist_wheel.py b/setuptools/command/bdist_wheel.py index ad34539eb8..a81187598a 100644 --- a/setuptools/command/bdist_wheel.py +++ b/setuptools/command/bdist_wheel.py @@ -284,9 +284,7 @@ def finalize_options(self): wheel = self.distribution.get_option_dict("wheel") if "universal" in wheel: # please don't define this in your global configs - log.warning( - "The [wheel] section is deprecated. Use [bdist_wheel] instead.", - ) + log.warn("The [wheel] section is deprecated. Use [bdist_wheel] instead.") val = wheel["universal"][1].strip() if val.lower() in ("1", "true", "yes"): self.universal = True From be847e002eacf1431470f5d6592de5caddb521e5 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 19 Jun 2024 12:59:30 +0100 Subject: [PATCH 03/10] Add interop tests for pkg_resources and zope-interface --- .../tests/integration/test_zope_interface.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 setuptools/tests/integration/test_zope_interface.py diff --git a/setuptools/tests/integration/test_zope_interface.py b/setuptools/tests/integration/test_zope_interface.py new file mode 100644 index 0000000000..c340c4137d --- /dev/null +++ b/setuptools/tests/integration/test_zope_interface.py @@ -0,0 +1,61 @@ +import platform +import subprocess +import sys +from inspect import cleandoc + +import jaraco.path +import pytest + +pytestmark = pytest.mark.integration + +VIRTUALENV = (sys.executable, "-m", "virtualenv") + + +def run(cmd, **kwargs): + proc = subprocess.run(cmd, encoding="utf-8", capture_output=True, **kwargs) + if proc.returncode != 0: + pytest.fail(f"Command {cmd} failed with:\n{proc.stdout=!s}\n{proc.stderr=!s}") + return proc.stdout + + +@pytest.mark.skipif( + platform.system() != "Linux", + reason="only demonstrated to fail on Linux in #4399", +) +def test_interop_pkg_resources_iter_entry_points(tmp_path, venv): + """ + Importing pkg_resources.iter_entry_points on console_scripts + seems to cause trouble with zope-interface, when deprecates installation method + is used. See #4399. + """ + project = { + "pkg": { + "foo.py": cleandoc( + """ + from pkg_resources import iter_entry_points + + def bar(): + print("Print me if you can") + """ + ), + "setup.py": cleandoc( + """ + from setuptools import setup, find_packages + + setup( + install_requires=["zope-interface==6.4.post2"], + entry_points={ + "console_scripts": [ + "foo=foo:bar", + ], + }, + ) + """ + ), + } + } + jaraco.path.build(project, prefix=tmp_path) + cmd = [venv.exe("pip"), "install", "-e", ".", "--no-use-pep517"] + run(cmd, cwd=tmp_path / "pkg") + out = run([venv.exe("foo")]) + assert "Print me if you can" in out From b95d168faa3fe25d7e9e947472094d23124428cf Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 17 Jun 2024 15:12:06 +0100 Subject: [PATCH 04/10] Move piece of code inside pkg_resources/__init__.py --- pkg_resources/__init__.py | 64 +++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 894b45ac25..15f96693e7 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -3426,6 +3426,38 @@ class PkgResourcesDeprecationWarning(Warning): """ +# Ported from ``setuptools`` to avoid introducing an import inter-dependency: +_LOCALE_ENCODING = "locale" if sys.version_info >= (3, 10) else None + + +def _read_utf8_with_fallback(file: str, fallback_encoding=_LOCALE_ENCODING) -> str: + """See setuptools.unicode_utils._read_utf8_with_fallback""" + try: + with open(file, "r", encoding="utf-8") as f: + return f.read() + except UnicodeDecodeError: # pragma: no cover + msg = f"""\ + ******************************************************************************** + `encoding="utf-8"` fails with {file!r}, trying `encoding={fallback_encoding!r}`. + + This fallback behaviour is considered **deprecated** and future versions of + `setuptools/pkg_resources` may not implement it. + + Please encode {file!r} with "utf-8" to ensure future builds will succeed. + + If this file was produced by `setuptools` itself, cleaning up the cached files + and re-building/re-installing the package with a newer version of `setuptools` + (e.g. by updating `build-system.requires` in its `pyproject.toml`) + might solve the problem. + ******************************************************************************** + """ + # TODO: Add a deadline? + # See comment in setuptools.unicode_utils._Utf8EncodingNeeded + warnings.warn(msg, PkgResourcesDeprecationWarning, stacklevel=2) + with open(file, "r", encoding=fallback_encoding) as f: + return f.read() + + # from jaraco.functools 1.3 def _call_aside(f, *args, **kwargs): f(*args, **kwargs) @@ -3498,35 +3530,3 @@ def _initialize_master_working_set(): add_activation_listener = working_set.subscribe run_script = working_set.run_script run_main = run_script - - -# ---- Ported from ``setuptools`` to avoid introducing an import inter-dependency ---- -LOCALE_ENCODING = "locale" if sys.version_info >= (3, 10) else None - - -def _read_utf8_with_fallback(file: str, fallback_encoding=LOCALE_ENCODING) -> str: - """See setuptools.unicode_utils._read_utf8_with_fallback""" - try: - with open(file, "r", encoding="utf-8") as f: - return f.read() - except UnicodeDecodeError: # pragma: no cover - msg = f"""\ - ******************************************************************************** - `encoding="utf-8"` fails with {file!r}, trying `encoding={fallback_encoding!r}`. - - This fallback behaviour is considered **deprecated** and future versions of - `setuptools/pkg_resources` may not implement it. - - Please encode {file!r} with "utf-8" to ensure future builds will succeed. - - If this file was produced by `setuptools` itself, cleaning up the cached files - and re-building/re-installing the package with a newer version of `setuptools` - (e.g. by updating `build-system.requires` in its `pyproject.toml`) - might solve the problem. - ******************************************************************************** - """ - # TODO: Add a deadline? - # See comment in setuptools.unicode_utils._Utf8EncodingNeeded - warnings.warn(msg, PkgResourcesDeprecationWarning, stacklevel=2) - with open(file, "r", encoding=fallback_encoding) as f: - return f.read() From 03edaaa41059cf580709ec714586a6f7762cd99d Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 17 Jun 2024 17:14:59 +0100 Subject: [PATCH 05/10] Add newsfragment --- newsfragments/4422.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/4422.misc.rst diff --git a/newsfragments/4422.misc.rst b/newsfragments/4422.misc.rst new file mode 100644 index 0000000000..e45b6d44b2 --- /dev/null +++ b/newsfragments/4422.misc.rst @@ -0,0 +1 @@ +Reorder code in ``pkg_resources/__init__.py`` to avoid definitions after ``@_call_aside``. From 06fd687e048224fc2293be50ed30d7f1a04378f4 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 19 Jun 2024 13:04:11 +0100 Subject: [PATCH 06/10] Move integration test to pkg_resources --- .../tests/test_integration_zope_interface.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename setuptools/tests/integration/test_zope_interface.py => pkg_resources/tests/test_integration_zope_interface.py (100%) diff --git a/setuptools/tests/integration/test_zope_interface.py b/pkg_resources/tests/test_integration_zope_interface.py similarity index 100% rename from setuptools/tests/integration/test_zope_interface.py rename to pkg_resources/tests/test_integration_zope_interface.py From 051e70d9b232c5c24b3a64a4fdac07e9a347c4fb Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 19 Jun 2024 13:06:28 +0100 Subject: [PATCH 07/10] Simplify integration test for zop interface --- .../tests/test_integration_zope_interface.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/pkg_resources/tests/test_integration_zope_interface.py b/pkg_resources/tests/test_integration_zope_interface.py index c340c4137d..634025c238 100644 --- a/pkg_resources/tests/test_integration_zope_interface.py +++ b/pkg_resources/tests/test_integration_zope_interface.py @@ -1,6 +1,4 @@ import platform -import subprocess -import sys from inspect import cleandoc import jaraco.path @@ -8,15 +6,6 @@ pytestmark = pytest.mark.integration -VIRTUALENV = (sys.executable, "-m", "virtualenv") - - -def run(cmd, **kwargs): - proc = subprocess.run(cmd, encoding="utf-8", capture_output=True, **kwargs) - if proc.returncode != 0: - pytest.fail(f"Command {cmd} failed with:\n{proc.stdout=!s}\n{proc.stderr=!s}") - return proc.stdout - @pytest.mark.skipif( platform.system() != "Linux", @@ -55,7 +44,7 @@ def bar(): } } jaraco.path.build(project, prefix=tmp_path) - cmd = [venv.exe("pip"), "install", "-e", ".", "--no-use-pep517"] - run(cmd, cwd=tmp_path / "pkg") - out = run([venv.exe("foo")]) + cmd = ["pip", "install", "-e", ".", "--no-use-pep517"] + venv.run(cmd, cwd=tmp_path / "pkg") # Needs this version of pkg_resources installed + out = venv.run(["foo"]) assert "Print me if you can" in out From a4b15f3a07c914c1da9bda2cf458237c97d0e042 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 19 Jun 2024 13:09:32 +0100 Subject: [PATCH 08/10] Add comments on test --- pkg_resources/tests/test_integration_zope_interface.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg_resources/tests/test_integration_zope_interface.py b/pkg_resources/tests/test_integration_zope_interface.py index 634025c238..4e37c3401b 100644 --- a/pkg_resources/tests/test_integration_zope_interface.py +++ b/pkg_resources/tests/test_integration_zope_interface.py @@ -7,6 +7,10 @@ pytestmark = pytest.mark.integration +# For the sake of simplicity this test uses fixtures defined in +# `setuptools.test.fixtures`, +# and it also exercise conditions considered deprecated... +# So if needed this test can be deleted. @pytest.mark.skipif( platform.system() != "Linux", reason="only demonstrated to fail on Linux in #4399", From 3466f9f1e14c4b0ef87299fef414f73600d4a46f Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Wed, 19 Jun 2024 13:29:12 +0100 Subject: [PATCH 09/10] =?UTF-8?q?Bump=20version:=2070.0.0=20=E2=86=92=2070?= =?UTF-8?q?.1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- NEWS.rst | 30 ++++++++++++++++++++++++++++++ newsfragments/1386.feature.rst | 1 - newsfragments/4246.feature.rst | 4 ---- newsfragments/4310.feature.rst | 1 - newsfragments/4365.misc.rst | 1 - newsfragments/4382.bugfix.rst | 1 - newsfragments/4403.bugfix.rst | 1 - newsfragments/4405.bugfix.rst | 2 -- newsfragments/4411.bugfix.rst | 1 - newsfragments/4422.misc.rst | 1 - pyproject.toml | 2 +- 12 files changed, 32 insertions(+), 15 deletions(-) delete mode 100644 newsfragments/1386.feature.rst delete mode 100644 newsfragments/4246.feature.rst delete mode 100644 newsfragments/4310.feature.rst delete mode 100644 newsfragments/4365.misc.rst delete mode 100644 newsfragments/4382.bugfix.rst delete mode 100644 newsfragments/4403.bugfix.rst delete mode 100644 newsfragments/4405.bugfix.rst delete mode 100644 newsfragments/4411.bugfix.rst delete mode 100644 newsfragments/4422.misc.rst diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 25968653ac..4856098dff 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 70.0.0 +current_version = 70.1.0 commit = True tag = True diff --git a/NEWS.rst b/NEWS.rst index 06da16714b..265e545d54 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,3 +1,33 @@ +v70.1.0 +======= + +Features +-------- + +- Adopted the ``bdist_wheel`` command from the ``wheel`` project -- by :user:`agronholm` (#1386) +- Improve error message when ``pkg_resources.ZipProvider`` tries to extract resources with a missing Egg -- by :user:`Avasam` + + Added variables and parameter type annotations to ``pkg_resources`` to be nearly on par with typeshed.\* -- by :user:`Avasam` + \* Excluding ``TypeVar`` and ``overload``. Return types are currently inferred. (#4246) +- Migrated Setuptools' own config to pyproject.toml (#4310) + + +Bugfixes +-------- + +- Prevent a ``TypeError: 'NoneType' object is not callable`` when ``shutil_rmtree`` is called without an ``onexc`` parameter on Python<=3.11 -- by :user:`Avasam` (#4382) +- Replace use of mktemp with can_symlink from the stdlib test suite. (#4403) +- Improvement for ``attr:`` directives in configuration to handle + more edge cases related to complex ``package_dir``. (#4405) +- Fix accidental implicit string concatenation. (#4411) + + +Misc +---- + +- #4365, #4422 + + v70.0.0 ======= diff --git a/newsfragments/1386.feature.rst b/newsfragments/1386.feature.rst deleted file mode 100644 index c8d50bc22e..0000000000 --- a/newsfragments/1386.feature.rst +++ /dev/null @@ -1 +0,0 @@ -Adopted the ``bdist_wheel`` command from the ``wheel`` project -- by :user:`agronholm` diff --git a/newsfragments/4246.feature.rst b/newsfragments/4246.feature.rst deleted file mode 100644 index d5dd2ead98..0000000000 --- a/newsfragments/4246.feature.rst +++ /dev/null @@ -1,4 +0,0 @@ -Improve error message when ``pkg_resources.ZipProvider`` tries to extract resources with a missing Egg -- by :user:`Avasam` - -Added variables and parameter type annotations to ``pkg_resources`` to be nearly on par with typeshed.\* -- by :user:`Avasam` -\* Excluding ``TypeVar`` and ``overload``. Return types are currently inferred. diff --git a/newsfragments/4310.feature.rst b/newsfragments/4310.feature.rst deleted file mode 100644 index 2379f3f342..0000000000 --- a/newsfragments/4310.feature.rst +++ /dev/null @@ -1 +0,0 @@ -Migrated Setuptools' own config to pyproject.toml \ No newline at end of file diff --git a/newsfragments/4365.misc.rst b/newsfragments/4365.misc.rst deleted file mode 100644 index 7badfff8f0..0000000000 --- a/newsfragments/4365.misc.rst +++ /dev/null @@ -1 +0,0 @@ -Use actual boolean parameters and variables instead of 0-1 literals. -- by :user:`Avasam` diff --git a/newsfragments/4382.bugfix.rst b/newsfragments/4382.bugfix.rst deleted file mode 100644 index 3aa9e18573..0000000000 --- a/newsfragments/4382.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Prevent a ``TypeError: 'NoneType' object is not callable`` when ``shutil_rmtree`` is called without an ``onexc`` parameter on Python<=3.11 -- by :user:`Avasam` diff --git a/newsfragments/4403.bugfix.rst b/newsfragments/4403.bugfix.rst deleted file mode 100644 index c07cd48c7e..0000000000 --- a/newsfragments/4403.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Replace use of mktemp with can_symlink from the stdlib test suite. \ No newline at end of file diff --git a/newsfragments/4405.bugfix.rst b/newsfragments/4405.bugfix.rst deleted file mode 100644 index 164ace4934..0000000000 --- a/newsfragments/4405.bugfix.rst +++ /dev/null @@ -1,2 +0,0 @@ -Improvement for ``attr:`` directives in configuration to handle -more edge cases related to complex ``package_dir``. diff --git a/newsfragments/4411.bugfix.rst b/newsfragments/4411.bugfix.rst deleted file mode 100644 index e306f3ef0a..0000000000 --- a/newsfragments/4411.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fix accidental implicit string concatenation. diff --git a/newsfragments/4422.misc.rst b/newsfragments/4422.misc.rst deleted file mode 100644 index e45b6d44b2..0000000000 --- a/newsfragments/4422.misc.rst +++ /dev/null @@ -1 +0,0 @@ -Reorder code in ``pkg_resources/__init__.py`` to avoid definitions after ``@_call_aside``. diff --git a/pyproject.toml b/pyproject.toml index a7d1f3e99c..7c490f7ce9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ backend-path = ["."] [project] name = "setuptools" -version = "70.0.0" +version = "70.1.0" authors = [ { name = "Python Packaging Authority", email = "distutils-sig@python.org" }, ] From dc527c152bd74a9e6680db619933316f3c4b73d8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 19 Jun 2024 12:12:36 -0400 Subject: [PATCH 10/10] Expand changelog to provide more context. Ref #3593 --- NEWS.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/NEWS.rst b/NEWS.rst index 265e545d54..5c3f5b4319 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -139,7 +139,19 @@ v69.3.0 Features -------- -- Support PEP 625 by canonicalizing package name and version in filenames. (#3593) +- Support PEP 625 by canonicalizing package name and version in filenames + per + `the spec `_. + Projects whose names contain uppercase characters, dashes, or periods will + now see their sdist names normalized to match the standard and the format + previously seen in wheels. For example: + + - ``zope.interface`` -> ``zope_interface`` + - ``CherryPy`` -> ``cherrypy`` + - ``foo-bar_baz`` -> ``foo_bar_baz`` + + Projects are encouraged to adopt this change to align with standards and + other backend build systems. (#3593) v69.2.0