Skip to content

Commit

Permalink
Merge branch 'main' into pyright-initial-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed May 2, 2024
2 parents f9515c2 + dcfc833 commit 9883a9e
Show file tree
Hide file tree
Showing 44 changed files with 565 additions and 295 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ jobs:
- platform: ubuntu-latest
python: "3.10"
distutils: stdlib
# Python 3.8, 3.9 are on macos-13 but not macos-latest (macos-14-arm64)
# https://github.com/actions/setup-python/issues/850
# https://github.com/actions/setup-python/issues/696#issuecomment-1637587760
- {python: "3.8", platform: "macos-13"}
exclude:
- {python: "3.8", platform: "macos-latest"}
runs-on: ${{ matrix.platform }}
continue-on-error: ${{ matrix.python == '3.13' }}
env:
Expand Down Expand Up @@ -89,7 +95,8 @@ jobs:
shell: bash
run: |
rm -rf dist
pipx run build
# workaround for pypa/setuptools#4333
pipx run --pip-args 'pyproject-hooks!=1.1' build
echo "PRE_BUILT_SETUPTOOLS_SDIST=$(ls dist/*.tar.gz)" >> $GITHUB_ENV
echo "PRE_BUILT_SETUPTOOLS_WHEEL=$(ls dist/*.whl)" >> $GITHUB_ENV
rm -rf setuptools.egg-info # Avoid interfering with the other tests
Expand Down Expand Up @@ -122,6 +129,7 @@ jobs:
job:
- diffcov
- docs
- check-extern
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ v69.4.2
Bugfixes
--------

- Merged bugfix for pypa/distutils#246 (#27489545)
- Merged bugfix for pypa/distutils#246.


v69.4.1
Expand Down Expand Up @@ -119,7 +119,7 @@ Improved Documentation
----------------------

- Updated documentation referencing obsolete Python 3.7 code. -- by :user:`Avasam` (#4096)
- Changed ``versionadded`` for "Type information included by default" feature from ``v68.3.0`` to ``v69.0.0`` -- by :user:Avasam` (#4182)
- Changed ``versionadded`` for "Type information included by default" feature from ``v68.3.0`` to ``v69.0.0`` -- by :user:`Avasam` (#4182)
- Described the auto-generated files -- by :user:`VladimirFokow` (#4198)
- Updated "Quickstart" to describe the current status of ``setup.cfg`` and ``pyproject.toml`` -- by :user:`VladimirFokow` (#4200)

Expand Down
26 changes: 14 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
.. image:: https://img.shields.io/pypi/v/setuptools.svg
.. |pypi-version| image:: https://img.shields.io/pypi/v/setuptools.svg
:target: https://pypi.org/project/setuptools

.. image:: https://img.shields.io/pypi/pyversions/setuptools.svg
.. |py-version| image:: https://img.shields.io/pypi/pyversions/setuptools.svg

.. image:: https://github.com/pypa/setuptools/actions/workflows/main.yml/badge.svg
.. |test-badge| image:: https://github.com/pypa/setuptools/actions/workflows/main.yml/badge.svg
:target: https://github.com/pypa/setuptools/actions?query=workflow%3A%22tests%22
:alt: tests

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff
.. |ruff-badge| image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff

.. image:: https://img.shields.io/readthedocs/setuptools/latest.svg
:target: https://setuptools.pypa.io
.. |docs-badge| image:: https://img.shields.io/readthedocs/setuptools/latest.svg
:target: https://setuptools.pypa.io

.. image:: https://img.shields.io/badge/skeleton-2024-informational
.. |skeleton-badge| image:: https://img.shields.io/badge/skeleton-2024-informational
:target: https://blog.jaraco.com/skeleton

.. image:: https://img.shields.io/codecov/c/github/pypa/setuptools/master.svg?logo=codecov&logoColor=white
.. |codecov-badge| image:: https://img.shields.io/codecov/c/github/pypa/setuptools/master.svg?logo=codecov&logoColor=white
:target: https://codecov.io/gh/pypa/setuptools

.. image:: https://tidelift.com/badges/github/pypa/setuptools?style=flat
.. |tidelift-badge| image:: https://tidelift.com/badges/github/pypa/setuptools?style=flat
:target: https://tidelift.com/subscription/pkg/pypi-setuptools?utm_source=pypi-setuptools&utm_medium=readme

.. image:: https://img.shields.io/discord/803025117553754132
.. |discord-badge| image:: https://img.shields.io/discord/803025117553754132
:target: https://discord.com/channels/803025117553754132/815945031150993468
:alt: Discord

|pypi-version| |py-version| |test-badge| |ruff-badge| |docs-badge| |skeleton-badge| |codecov-badge| |discord-badge|

See the `Quickstart <https://setuptools.pypa.io/en/latest/userguide/quickstart.html>`_
and the `User's Guide <https://setuptools.pypa.io/en/latest/userguide/>`_ for
instructions on how to use Setuptools.
Expand Down
1 change: 1 addition & 0 deletions newsfragments/4255.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Treat ``EncodingWarning``s as errors in tests. -- by :user:`Avasam`
2 changes: 2 additions & 0 deletions newsfragments/4278.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix finder template for lenient editable installs of implicit nested namespaces
constructed by using ``package_dir`` to reorganise directory structure.
1 change: 1 addition & 0 deletions newsfragments/4280.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid leaking loop variable ``name`` in ``AbstractSandbox`` -- by :user:`Avasam`
2 changes: 2 additions & 0 deletions newsfragments/4308.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``setuptools_wheel`` fixture and avoid the recursive creation of
``build/lib/build/lib/build/...`` directories in the project root during tests.
7 changes: 7 additions & 0 deletions newsfragments/4309.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Further adoption of UTF-8 in ``setuptools``.
This change regards mostly files produced and consumed during the build process
(e.g. metadata files, script wrappers, automatically updated config files, etc..)
Although precautions were taken to minimize disruptions, some edge cases might
be subject to backwards incompatibility.

Support for ``"locale"`` encoding is now **deprecated**.
1 change: 1 addition & 0 deletions newsfragments/4312.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Uses RST substitution to put badges in 1 line.
1 change: 1 addition & 0 deletions newsfragments/4332.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modernized and refactored VCS handling in package_index.
44 changes: 37 additions & 7 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,8 +1524,7 @@ def run_script(self, script_name, namespace):
script_filename = self._fn(self.egg_info, script)
namespace['__file__'] = script_filename
if os.path.exists(script_filename):
with open(script_filename) as fid:
source = fid.read()
source = _read_utf8_with_fallback(script_filename)
code = compile(source, script_filename, 'exec')
exec(code, namespace, namespace)
else:
Expand Down Expand Up @@ -2175,11 +2174,10 @@ def non_empty_lines(path):
"""
Yield non-empty lines from file at path
"""
with open(path) as f:
for line in f:
line = line.strip()
if line:
yield line
for line in _read_utf8_with_fallback(path).splitlines():
line = line.strip()
if line:
yield line


def resolve_egg_link(path):
Expand Down Expand Up @@ -3323,3 +3321,35 @@ def _initialize_master_working_set():
# match order
list(map(working_set.add_entry, sys.path))
globals().update(locals())


# ---- 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.warns(msg, PkgResourcesDeprecationWarning, stacklevel=2)
with open(file, "r", encoding=fallback_encoding) as f:
return f.read()
2 changes: 2 additions & 0 deletions pkg_resources/_vendor/vendored.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ jaraco.text==3.7.0
importlib_resources==5.10.2
# required for importlib_resources on older Pythons
zipp==3.7.0
# required for jaraco.functools
more_itertools==10.2.0
# required for jaraco.context on older Pythons
backports.tarfile
9 changes: 9 additions & 0 deletions pkg_resources/extern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,21 @@ def install(self):
sys.meta_path.append(self)


# [[[cog
# import cog
# from tools.vendored import yield_root_package
# names = "\n".join(f" {x!r}," for x in yield_root_package('pkg_resources'))
# cog.outl(f"names = (\n{names}\n)")
# ]]]
names = (
'packaging',
'platformdirs',
'typing_extensions',
'jaraco',
'importlib_resources',
'zipp',
'more_itertools',
'backports',
)
# [[[end]]]
VendorImporter(__name__, names).install()
28 changes: 16 additions & 12 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,31 @@ filterwarnings=
# Fail on warnings
error

# Workarounds for pypa/setuptools#3810
# Can't use EncodingWarning as it doesn't exist on Python 3.9.
# These warnings only appear on Python 3.10+

## upstream

# Ensure ResourceWarnings are emitted
default::ResourceWarning

# python/mypy#17057
ignore:'encoding' argument not specified::mypy
ignore:'encoding' argument not specified::configparser
# ^-- ConfigParser is called by mypy,
# but ignoring the warning in `mypy` is not enough
# to make it work on PyPy

# realpython/pytest-mypy#152
ignore:'encoding' argument not specified::pytest_mypy

# python/cpython#100750
ignore:'encoding' argument not specified::platform
# TODO: Set encoding when openning/writing tmpdir files with pytest's LocalPath.open
# see pypa/setuptools#4326
ignore:'encoding' argument not specified::_pytest

# pypa/build#615
ignore:'encoding' argument not specified::build.env

# dateutil/dateutil#1284
ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning:dateutil.tz.tz
# Already fixed in pypa/distutils, but present in stdlib
ignore:'encoding' argument not specified::distutils

## end upstream

Expand Down Expand Up @@ -69,11 +78,6 @@ filterwarnings=
# https://github.com/pypa/setuptools/issues/3655
ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning

# Workarounds for pypa/setuptools#3810
# Can't use EncodingWarning as it doesn't exist on Python 3.9
default:'encoding' argument not specified
default:UTF-8 Mode affects locale.getpreferredencoding().

# Avoid errors when testing pkg_resources.declare_namespace
ignore:.*pkg_resources\.declare_namespace.*:DeprecationWarning

Expand Down
9 changes: 8 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ testing =
jaraco.path>=3.2.0
build[virtualenv]>=1.0.3
filelock>=3.4.0
ini2toml[lite]>=0.9
ini2toml[lite]>=0.14
tomli-w>=1.0.0
pytest-timeout
pytest-perf; \
Expand All @@ -78,6 +78,10 @@ testing =
tomli
# No Python 3.12 dependencies require importlib_metadata, but needed for type-checking since we import it directly
importlib_metadata
pytest-subprocess

# workaround for pypa/setuptools#4333
pyproject-hooks!=1.1

docs =
# upstream
Expand All @@ -98,6 +102,9 @@ docs =
sphinxcontrib-towncrier
sphinx-notfound-page >=1,<2

# workaround for pypa/setuptools#4333
pyproject-hooks!=1.1

ssl =

certs =
Expand Down
5 changes: 3 additions & 2 deletions setuptools/_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import importlib.util
import importlib.machinery
import tokenize

from importlib.util import module_from_spec

Expand Down Expand Up @@ -60,13 +61,13 @@ def find_module(module, paths=None):

if suffix in importlib.machinery.SOURCE_SUFFIXES:
kind = PY_SOURCE
file = tokenize.open(path)
elif suffix in importlib.machinery.BYTECODE_SUFFIXES:
kind = PY_COMPILED
file = open(path, 'rb')
elif suffix in importlib.machinery.EXTENSION_SUFFIXES:
kind = C_EXTENSION

if kind in {PY_SOURCE, PY_COMPILED}:
file = open(path, mode)
else:
path = None
suffix = mode = ''
Expand Down
2 changes: 1 addition & 1 deletion setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Previously, when a user or a command line tool (let's call it a "frontend")
needed to make a request of setuptools to take a certain action, for
example, generating a list of installation requirements, the frontend would
example, generating a list of installation requirements, the frontend
would call "setup.py egg_info" or "setup.py bdist_wheel" on the command line.
PEP 517 defines a different method of interfacing with setuptools. Rather
Expand Down
14 changes: 6 additions & 8 deletions setuptools/command/bdist_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __bootstrap__():
__bootstrap__()
"""
).lstrip()
with open(pyfile, 'w') as f:
with open(pyfile, 'w', encoding="utf-8") as f:
f.write(_stub_template % resource)


Expand Down Expand Up @@ -200,10 +200,9 @@ def run(self): # noqa: C901 # is too complex (14) # FIXME
log.info("writing %s", native_libs)
if not self.dry_run:
ensure_directory(native_libs)
libs_file = open(native_libs, 'wt')
libs_file.write('\n'.join(all_outputs))
libs_file.write('\n')
libs_file.close()
with open(native_libs, 'wt', encoding="utf-8") as libs_file:
libs_file.write('\n'.join(all_outputs))
libs_file.write('\n')
elif os.path.isfile(native_libs):
log.info("removing %s", native_libs)
if not self.dry_run:
Expand Down Expand Up @@ -350,9 +349,8 @@ def write_safety_flag(egg_dir, safe):
if safe is None or bool(safe) != flag:
os.unlink(fn)
elif safe is not None and bool(safe) == flag:
f = open(fn, 'wt')
f.write('\n')
f.close()
with open(fn, 'wt', encoding="utf-8") as f:
f.write('\n')


safety_flags = {
Expand Down
8 changes: 3 additions & 5 deletions setuptools/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,8 @@ def _write_stub_file(self, stub_file: str, ext: Extension, compile=False):
if compile and os.path.exists(stub_file):
raise BaseError(stub_file + " already exists! Please delete.")
if not self.dry_run:
f = open(stub_file, 'w')
f.write(
'\n'.join([
with open(stub_file, 'w', encoding="utf-8") as f:
content = '\n'.join([
"def __bootstrap__():",
" global __bootstrap__, __file__, __loader__",
" import sys, os, pkg_resources, importlib.util" + if_dl(", dl"),
Expand All @@ -366,8 +365,7 @@ def _write_stub_file(self, stub_file: str, ext: Extension, compile=False):
"__bootstrap__()",
"", # terminal \n
])
)
f.close()
f.write(content)
if compile:
self._compile_and_remove_stub(stub_file)

Expand Down

0 comments on commit 9883a9e

Please sign in to comment.