Skip to content

Commit

Permalink
Merge branch 'main' into feature/importlib-metadata-6.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 18, 2023
2 parents d9eafb7 + 4e04393 commit 5a30cc3
Show file tree
Hide file tree
Showing 41 changed files with 579 additions and 316 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -34,6 +34,7 @@ Lib/test/xmltestdata/* noeol

# Shell scripts should have LF even on Windows because of Cygwin
Lib/venv/scripts/common/activate text eol=lf
Lib/venv/scripts/posix/* text eol=lf

# CRLF files
[attr]dos text eol=crlf
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/project-updater.yml
Expand Up @@ -20,8 +20,6 @@ jobs:
# if an issue has any of these labels, it will be added
# to the corresponding project
- { project: 2, label: "release-blocker, deferred-blocker" }
- { project: 3, label: expert-subinterpreters }
- { project: 29, label: expert-asyncio }
- { project: 32, label: sprint }

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/verify-ensurepip-wheels.yml
@@ -1,4 +1,4 @@
name: Verify bundled pip and setuptools
name: Verify bundled wheels

on:
workflow_dispatch:
Expand Down Expand Up @@ -29,5 +29,5 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3'
- name: Compare checksums of bundled pip and setuptools to ones published on PyPI
- name: Compare checksum of bundled wheels to the ones published on PyPI
run: ./Tools/build/verify_ensurepip_wheels.py
11 changes: 8 additions & 3 deletions Doc/conf.py
Expand Up @@ -254,9 +254,14 @@
# Options for the link checker
# ----------------------------

# Ignore certain URLs.
linkcheck_ignore = [r'https://bugs.python.org/(issue)?\d+']

linkcheck_allowed_redirects = {
# bpo-NNNN -> BPO -> GH Issues
r'https://bugs.python.org/issue\?@action=redirect&bpo=\d+': 'https://github.com/python/cpython/issues/\d+',
# GH-NNNN used to refer to pull requests
r'https://github.com/python/cpython/issues/\d+': 'https://github.com/python/cpython/pull/\d+',
# :source:`something` linking files in the repository
r'https://github.com/python/cpython/tree/.*': 'https://github.com/python/cpython/blob/.*'
}

# Options for extensions
# ----------------------
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/optparse.rst
Expand Up @@ -2027,7 +2027,7 @@ Features of note:
values.ensure_value(attr, value)

If the ``attr`` attribute of ``values`` doesn't exist or is ``None``, then
ensure_value() first sets it to ``value``, and then returns 'value. This is
ensure_value() first sets it to ``value``, and then returns ``value``. This is
very handy for actions like ``"extend"``, ``"append"``, and ``"count"``, all
of which accumulate data in a variable and expect that variable to be of a
certain type (a list for the first two, an integer for the latter). Using
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/string.rst
Expand Up @@ -254,10 +254,10 @@ Some simple format string examples::
"Units destroyed: {players[0]}" # First element of keyword argument 'players'.

The *conversion* field causes a type coercion before formatting. Normally, the
job of formatting a value is done by the :meth:`__format__` method of the value
job of formatting a value is done by the :meth:`~object.__format__` method of the value
itself. However, in some cases it is desirable to force a type to be formatted
as a string, overriding its own definition of formatting. By converting the
value to a string before calling :meth:`__format__`, the normal formatting logic
value to a string before calling :meth:`~object.__format__`, the normal formatting logic
is bypassed.

Three conversion flags are currently supported: ``'!s'`` which calls :func:`str`
Expand Down
7 changes: 5 additions & 2 deletions Doc/library/venv.rst
Expand Up @@ -284,11 +284,14 @@ creation according to their needs, the :class:`EnvBuilder` class.

.. method:: upgrade_dependencies(context)

Upgrades the core venv dependency packages (currently ``pip`` and
``setuptools``) in the environment. This is done by shelling out to the
Upgrades the core venv dependency packages (currently ``pip``)
in the environment. This is done by shelling out to the
``pip`` executable in the environment.

.. versionadded:: 3.9
.. versionchanged:: 3.12

``setuptools`` is no longer a core venv dependency.

.. method:: post_setup(context)

Expand Down
7 changes: 5 additions & 2 deletions Doc/using/venv-create.inc
Expand Up @@ -61,12 +61,16 @@ The command, if run with ``-h``, will show the available options::
environment (pip is bootstrapped by default)
--prompt PROMPT Provides an alternative prompt prefix for this
environment.
--upgrade-deps Upgrade core dependencies: pip setuptools to the
--upgrade-deps Upgrade core dependencies (pip) to the
latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by
sourcing an activate script in its bin directory.

.. versionchanged:: 3.12

``setuptools`` is no longer a core venv dependency.

.. versionchanged:: 3.9
Add ``--upgrade-deps`` option to upgrade pip + setuptools to the latest on PyPI

Expand Down Expand Up @@ -104,4 +108,3 @@ invoked to bootstrap ``pip`` into the virtual environment.
Multiple paths can be given to ``venv``, in which case an identical virtual
environment will be created, according to the given options, at each provided
path.

20 changes: 19 additions & 1 deletion Doc/whatsnew/3.12.rst
Expand Up @@ -258,7 +258,7 @@ csv

* Add :data:`~csv.QUOTE_NOTNULL` and :data:`~csv.QUOTE_STRINGS` flags to
provide finer grained control of ``None`` and empty strings by
:class:`~csv.reader` and :class:`~csv.writer` objects.
:class:`~csv.writer` objects.

inspect
-------
Expand Down Expand Up @@ -731,6 +731,24 @@ Removed
project can be installed: it still provides ``distutils``.
(Contributed by Victor Stinner in :gh:`92584`.)

* Remove the bundled setuptools wheel from :mod:`ensurepip`,
and stop installing setuptools in environments created by :mod:`venv`.

``pip (>= 22.1)`` does not require setuptools to be installed in the
environment. ``setuptools``-based (and ``distutils``-based) packages
can still be used with ``pip install``, since pip will provide
``setuptools`` in the build environment it uses for building a
package.

``easy_install``, ``pkg_resources``, ``setuptools`` and ``distutils``
are no longer provided by default in environments created with
``venv`` or bootstrapped with ``ensurepip``, since they are part of
the ``setuptools`` package. For projects relying on these at runtime,
the ``setuptools`` project should be declared as a dependency and
installed separately (typically, using pip).

(Contributed by Pradyun Gedam in :gh:`95299`.)

* Removed many old deprecated :mod:`unittest` features:

- A number of :class:`~unittest.TestCase` method aliases:
Expand Down
9 changes: 7 additions & 2 deletions Lib/dataclasses.py
Expand Up @@ -1128,8 +1128,13 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,

if not getattr(cls, '__doc__'):
# Create a class doc-string.
cls.__doc__ = (cls.__name__ +
str(inspect.signature(cls)).replace(' -> None', ''))
try:
# In some cases fetching a signature is not possible.
# But, we surely should not fail in this case.
text_sig = str(inspect.signature(cls)).replace(' -> None', '')
except (TypeError, ValueError):
text_sig = ''
cls.__doc__ = (cls.__name__ + text_sig)

if match_args:
# I could probably compute this once
Expand Down
16 changes: 7 additions & 9 deletions Lib/ensurepip/__init__.py
Expand Up @@ -9,11 +9,9 @@


__all__ = ["version", "bootstrap"]
_PACKAGE_NAMES = ('setuptools', 'pip')
_SETUPTOOLS_VERSION = "65.5.0"
_PACKAGE_NAMES = ('pip',)
_PIP_VERSION = "23.0.1"
_PROJECTS = [
("setuptools", _SETUPTOOLS_VERSION, "py3"),
("pip", _PIP_VERSION, "py3"),
]

Expand Down Expand Up @@ -153,17 +151,17 @@ def _bootstrap(*, root=None, upgrade=False, user=False,

_disable_pip_configuration_settings()

# By default, installing pip and setuptools installs all of the
# By default, installing pip installs all of the
# following scripts (X.Y == running Python version):
#
# pip, pipX, pipX.Y, easy_install, easy_install-X.Y
# pip, pipX, pipX.Y
#
# pip 1.5+ allows ensurepip to request that some of those be left out
if altinstall:
# omit pip, pipX and easy_install
# omit pip, pipX
os.environ["ENSUREPIP_OPTIONS"] = "altinstall"
elif not default_pip:
# omit pip and easy_install
# omit pip
os.environ["ENSUREPIP_OPTIONS"] = "install"

with tempfile.TemporaryDirectory() as tmpdir:
Expand Down Expand Up @@ -271,14 +269,14 @@ def _main(argv=None):
action="store_true",
default=False,
help=("Make an alternate install, installing only the X.Y versioned "
"scripts (Default: pipX, pipX.Y, easy_install-X.Y)."),
"scripts (Default: pipX, pipX.Y)."),
)
parser.add_argument(
"--default-pip",
action="store_true",
default=False,
help=("Make a default pip install, installing the unqualified pip "
"and easy_install in addition to the versioned scripts."),
"in addition to the versioned scripts."),
)

args = parser.parse_args(argv)
Expand Down
Binary file not shown.
13 changes: 13 additions & 0 deletions Lib/test/test_dataclasses.py
Expand Up @@ -2297,6 +2297,19 @@ class C:

self.assertDocStrEqual(C.__doc__, "C(x:collections.deque=<factory>)")

def test_docstring_with_no_signature(self):
# See https://github.com/python/cpython/issues/103449
class Meta(type):
__call__ = dict
class Base(metaclass=Meta):
pass

@dataclass
class C(Base):
pass

self.assertDocStrEqual(C.__doc__, "C")


class TestInit(unittest.TestCase):
def test_base_has_init(self):
Expand Down
35 changes: 12 additions & 23 deletions Lib/test/test_ensurepip.py
Expand Up @@ -20,7 +20,6 @@ def test_version(self):
# Test version()
with tempfile.TemporaryDirectory() as tmpdir:
self.touch(tmpdir, "pip-1.2.3b1-py2.py3-none-any.whl")
self.touch(tmpdir, "setuptools-49.1.3-py3-none-any.whl")
with (unittest.mock.patch.object(ensurepip, '_PACKAGES', None),
unittest.mock.patch.object(ensurepip, '_WHEEL_PKG_DIR', tmpdir)):
self.assertEqual(ensurepip.version(), '1.2.3b1')
Expand All @@ -36,15 +35,12 @@ def test_get_packages_no_dir(self):

# use bundled wheel packages
self.assertIsNotNone(packages['pip'].wheel_name)
self.assertIsNotNone(packages['setuptools'].wheel_name)

def test_get_packages_with_dir(self):
# Test _get_packages() with a wheel package directory
setuptools_filename = "setuptools-49.1.3-py3-none-any.whl"
pip_filename = "pip-20.2.2-py2.py3-none-any.whl"

with tempfile.TemporaryDirectory() as tmpdir:
self.touch(tmpdir, setuptools_filename)
self.touch(tmpdir, pip_filename)
# not used, make sure that it's ignored
self.touch(tmpdir, "wheel-0.34.2-py2.py3-none-any.whl")
Expand All @@ -53,15 +49,12 @@ def test_get_packages_with_dir(self):
unittest.mock.patch.object(ensurepip, '_WHEEL_PKG_DIR', tmpdir)):
packages = ensurepip._get_packages()

self.assertEqual(packages['setuptools'].version, '49.1.3')
self.assertEqual(packages['setuptools'].wheel_path,
os.path.join(tmpdir, setuptools_filename))
self.assertEqual(packages['pip'].version, '20.2.2')
self.assertEqual(packages['pip'].wheel_path,
os.path.join(tmpdir, pip_filename))

# wheel package is ignored
self.assertEqual(sorted(packages), ['pip', 'setuptools'])
self.assertEqual(sorted(packages), ['pip'])


class EnsurepipMixin:
Expand Down Expand Up @@ -92,13 +85,13 @@ def test_basic_bootstrapping(self):
self.run_pip.assert_called_once_with(
[
"install", "--no-cache-dir", "--no-index", "--find-links",
unittest.mock.ANY, "setuptools", "pip",
unittest.mock.ANY, "pip",
],
unittest.mock.ANY,
)

additional_paths = self.run_pip.call_args[0][1]
self.assertEqual(len(additional_paths), 2)
self.assertEqual(len(additional_paths), 1)

def test_bootstrapping_with_root(self):
ensurepip.bootstrap(root="/foo/bar/")
Expand All @@ -107,7 +100,7 @@ def test_bootstrapping_with_root(self):
[
"install", "--no-cache-dir", "--no-index", "--find-links",
unittest.mock.ANY, "--root", "/foo/bar/",
"setuptools", "pip",
"pip",
],
unittest.mock.ANY,
)
Expand All @@ -118,7 +111,7 @@ def test_bootstrapping_with_user(self):
self.run_pip.assert_called_once_with(
[
"install", "--no-cache-dir", "--no-index", "--find-links",
unittest.mock.ANY, "--user", "setuptools", "pip",
unittest.mock.ANY, "--user", "pip",
],
unittest.mock.ANY,
)
Expand All @@ -129,7 +122,7 @@ def test_bootstrapping_with_upgrade(self):
self.run_pip.assert_called_once_with(
[
"install", "--no-cache-dir", "--no-index", "--find-links",
unittest.mock.ANY, "--upgrade", "setuptools", "pip",
unittest.mock.ANY, "--upgrade", "pip",
],
unittest.mock.ANY,
)
Expand All @@ -140,7 +133,7 @@ def test_bootstrapping_with_verbosity_1(self):
self.run_pip.assert_called_once_with(
[
"install", "--no-cache-dir", "--no-index", "--find-links",
unittest.mock.ANY, "-v", "setuptools", "pip",
unittest.mock.ANY, "-v", "pip",
],
unittest.mock.ANY,
)
Expand All @@ -151,7 +144,7 @@ def test_bootstrapping_with_verbosity_2(self):
self.run_pip.assert_called_once_with(
[
"install", "--no-cache-dir", "--no-index", "--find-links",
unittest.mock.ANY, "-vv", "setuptools", "pip",
unittest.mock.ANY, "-vv", "pip",
],
unittest.mock.ANY,
)
Expand All @@ -162,7 +155,7 @@ def test_bootstrapping_with_verbosity_3(self):
self.run_pip.assert_called_once_with(
[
"install", "--no-cache-dir", "--no-index", "--find-links",
unittest.mock.ANY, "-vvv", "setuptools", "pip",
unittest.mock.ANY, "-vvv", "pip",
],
unittest.mock.ANY,
)
Expand Down Expand Up @@ -239,7 +232,6 @@ def test_uninstall(self):
self.run_pip.assert_called_once_with(
[
"uninstall", "-y", "--disable-pip-version-check", "pip",
"setuptools",
]
)

Expand All @@ -250,7 +242,6 @@ def test_uninstall_with_verbosity_1(self):
self.run_pip.assert_called_once_with(
[
"uninstall", "-y", "--disable-pip-version-check", "-v", "pip",
"setuptools",
]
)

Expand All @@ -261,7 +252,6 @@ def test_uninstall_with_verbosity_2(self):
self.run_pip.assert_called_once_with(
[
"uninstall", "-y", "--disable-pip-version-check", "-vv", "pip",
"setuptools",
]
)

Expand All @@ -272,7 +262,7 @@ def test_uninstall_with_verbosity_3(self):
self.run_pip.assert_called_once_with(
[
"uninstall", "-y", "--disable-pip-version-check", "-vvv",
"pip", "setuptools",
"pip"
]
)

Expand Down Expand Up @@ -312,13 +302,13 @@ def test_basic_bootstrapping(self):
self.run_pip.assert_called_once_with(
[
"install", "--no-cache-dir", "--no-index", "--find-links",
unittest.mock.ANY, "setuptools", "pip",
unittest.mock.ANY, "pip",
],
unittest.mock.ANY,
)

additional_paths = self.run_pip.call_args[0][1]
self.assertEqual(len(additional_paths), 2)
self.assertEqual(len(additional_paths), 1)
self.assertEqual(exit_code, 0)

def test_bootstrapping_error_code(self):
Expand All @@ -344,7 +334,6 @@ def test_basic_uninstall(self):
self.run_pip.assert_called_once_with(
[
"uninstall", "-y", "--disable-pip-version-check", "pip",
"setuptools",
]
)

Expand Down

0 comments on commit 5a30cc3

Please sign in to comment.