Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ recursive-include tests *.py
recursive-include setuptools/tests *.html
recursive-include docs *.py *.txt *.rst *.conf *.css *.css_t Makefile indexsidebar.html
recursive-include setuptools/_vendor *
recursive-include pkg_resources *.py *.txt
recursive-include pkg_resources/tests/data *
recursive-include tools *
recursive-include newsfragments *
include *.py
Expand Down
1 change: 0 additions & 1 deletion bootstrap.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ install_requires = setuptools.dist:check_requirements
extras_require = setuptools.dist:check_extras
entry_points = setuptools.dist:check_entry_points
exclude_package_data = setuptools.dist:check_package_data
namespace_packages = setuptools.dist:check_nsp

[egg_info.writers]
PKG-INFO = setuptools.command.egg_info:write_pkg_info
Expand Down
1 change: 0 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def pytest_configure(config):
'setuptools/tests/mod_with_constant.py',
'setuptools/_distutils',
'_distutils_hack',
'pkg_resources/tests/data',
'setuptools/_vendor',
'setuptools/config/_validate_pyproject',
'setuptools/modified.py',
Expand Down
3 changes: 1 addition & 2 deletions docs/development/developer-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ cannot be declared as they won't be resolved soon enough to build
setuptools from source. Eventually, this limitation may be lifted as
PEP 517/518 reach ubiquitous adoption, but for now, Setuptools
cannot declare dependencies other than through
``setuptools/_vendor/vendored.txt`` and
``pkg_resources/_vendor/vendored.txt``.
``setuptools/_vendor/vendored.txt``.

All the dependencies specified in these files are "vendorized" using a
simple Python script ``tools/vendor.py``.
Expand Down
22 changes: 0 additions & 22 deletions docs/references/keywords.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,28 +407,6 @@ extensions).
``setup_requires`` or ``tests_require``. They will also be written into
the egg's metadata for use during install by tools that support them.

.. _keyword/namespace_packages:

``namespace_packages``
.. warning::
The ``namespace_packages`` implementation relies on ``pkg_resources``.
However, ``pkg_resources`` has some undesirable behaviours, and
Setuptools intends to obviate its usage in the future. Therefore,
``namespace_packages`` was deprecated in favor of native/implicit
namespaces (:pep:`420`). Check :doc:`the Python Packaging User Guide
<PyPUG:guides/packaging-namespace-packages>` for more information.

A list of strings naming the project's "namespace packages". A namespace
package is a package that may be split across multiple project
distributions. For example, Zope 3's ``zope`` package is a namespace
package, because subpackages like ``zope.interface`` and ``zope.publisher``
may be distributed separately. The egg runtime system can automatically
merge such subpackages into a single parent package at runtime, as long
as you declare them in each project that contains any subpackages of the
namespace package, and as long as the namespace package's ``__init__.py``
does not contain any code other than a namespace declaration. See the
section on :ref:`Namespace Packages` for more information.

.. _keyword/test_suite:

``test_suite``
Expand Down
5 changes: 0 additions & 5 deletions docs/userguide/declarative_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ packages find:, find_namespace:, list-comma [#
package_dir dict
package_data section [#opt-1]_
exclude_package_data section
namespace_packages list-comma [#opt-5]_
py_modules list-comma 34.4.0
data_files section 40.6.0 [#opt-4]_
======================= =================================== =============== ====================
Expand Down Expand Up @@ -304,10 +303,6 @@ data_files section 40.6.0 [#
.. [#opt-4] ``data_files`` is deprecated and should be avoided.
Please check :doc:`/userguide/datafiles` for more information.

.. [#opt-5] ``namespace_packages`` is deprecated in favour of native/implicit
namespaces (:pep:`420`). Check :doc:`the Python Packaging User Guide
<PyPUG:guides/packaging-namespace-packages>` for more information.

.. [#opt-6] ``file:`` directives for reading requirements are supported since version 62.6.
The format for the file resembles a ``requirements.txt`` file,
however please keep in mind that all non-comment lines must conform with :pep:`508`
Expand Down
62 changes: 2 additions & 60 deletions docs/userguide/package_discovery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -508,71 +508,13 @@ Legacy Namespace Packages
The fact you can create namespace packages so effortlessly above is credited
to :pep:`420`. It used to be more
cumbersome to accomplish the same result. Historically, there were two methods
to create namespace packages. One is the ``pkg_resources`` style supported by
``setuptools`` and the other one being ``pkgutils`` style offered by
to create namespace packages. One is the ``pkg_resources`` style that was
supported by ``setuptools`` and the other one being ``pkgutils`` style offered by
``pkgutils`` module in Python. Both are now considered *deprecated* despite the
fact they still linger in many existing packages. These two differ in many
subtle yet significant aspects and you can find out more on `Python packaging
user guide <https://packaging.python.org/guides/packaging-namespace-packages/>`_.


``pkg_resource`` style namespace package
----------------------------------------
This is the method ``setuptools`` directly supports. Starting with the same
layout, there are two pieces you need to add to it. First, an ``__init__.py``
file directly under your namespace package directory that contains the
following:

.. code-block:: python

__import__("pkg_resources").declare_namespace(__name__)

And the ``namespace_packages`` keyword in your ``setup.cfg`` or ``setup.py``:

.. tab:: setup.cfg

.. code-block:: ini

[options]
namespace_packages = timmins

.. tab:: setup.py

.. code-block:: python

setup(
# ...
namespace_packages=['timmins']
)

And your directory should look like this

.. code-block:: bash

foo
├── pyproject.toml # AND/OR setup.cfg, setup.py
└── src
└── timmins
├── __init__.py
└── foo
└── __init__.py

Repeat the same for other packages and you can achieve the same result as
the previous section.

``pkgutil`` style namespace package
-----------------------------------
This method is almost identical to the ``pkg_resource`` except that the
``namespace_packages`` declaration is omitted and the ``__init__.py``
file contains the following:

.. code-block:: python

__path__ = __import__('pkgutil').extend_path(__path__, __name__)

The project layout remains the same and ``pyproject.toml/setup.cfg`` remains the same.


----


Expand Down
24 changes: 9 additions & 15 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ exclude = (?x)(
# These are vendored
| ^setuptools/_vendor/
| ^setuptools/_distutils/
# Duplicate module name
| ^pkg_resources/tests/data/my-test-package-source/setup.py$
)

[mypy-setuptools.*]
disable_error_code =
# DistributionMetadata.license_files and DistributionMetadata.license_file
Expand All @@ -43,30 +42,25 @@ disable_error_code =
# See issue described below about distutils across Python versions
has-type,

# - pkg_resources tests create modules that won't exists statically before the test is run.
# Let's ignore all "import-not-found" since, if an import really wasn't found, then the test would fail.
[mypy-pkg_resources.tests.*]
disable_error_code = import-not-found

# - distutils doesn't exist on Python 3.12, unfortunately, this means typing
# will be missing for subclasses of distutils on Python 3.12 until either:
# - support for `SETUPTOOLS_USE_DISTUTILS=stdlib` is dropped (#3625)
# for setuptools to import `_distutils` directly
# - or non-stdlib distutils typings are exposed
# distutils doesn't exist on Python 3.12, unfortunately, this means typing
# will be missing for subclasses of distutils on Python 3.12 until either:
# - support for `SETUPTOOLS_USE_DISTUTILS=stdlib` is dropped (#3625)
# for setuptools to import `_distutils` directly
# - or non-stdlib distutils typings are exposed
[mypy-distutils.*]
ignore_missing_imports = True

# - wheel: does not intend on exposing a programmatic API https://github.com/pypa/wheel/pull/610#issuecomment-2081687671
[mypy-wheel.*]
follow_untyped_imports = True
# - The following are not marked as py.typed:

# The following are not marked as py.typed:
# - jaraco: Since mypy 1.12, the root name of the untyped namespace package gets called-out too
# - jaraco.develop: https://github.com/jaraco/jaraco.develop/issues/22
# - jaraco.envs: https://github.com/jaraco/jaraco.envs/issues/7
# - jaraco.packaging: https://github.com/jaraco/jaraco.packaging/issues/20
# - jaraco.path: https://github.com/jaraco/jaraco.path/issues/2
# - jaraco.text: https://github.com/jaraco/jaraco.text/issues/17
[mypy-jaraco,jaraco.develop.*,jaraco.envs,jaraco.packaging.*,jaraco.path,jaraco.text]
[mypy-jaraco,jaraco.develop.*,jaraco.envs,jaraco.packaging.*,jaraco.path]
follow_untyped_imports = True

# Even when excluding a module, import issues can show up due to following import
Expand Down
1 change: 1 addition & 0 deletions newsfragments/5175.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cleanup `pkg_resources` dependencies and configuration -- by :user:`Avasam`
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ core = [
"tomli>=2.0.1; python_version < '3.11'",
"wheel>=0.43.0",

# pkg_resources
"platformdirs >= 4.2.2", # Made ctypes optional (see #4461)

# for distutils
"jaraco.functools >= 4",
"more_itertools",
Expand Down Expand Up @@ -175,7 +172,6 @@ keywords = "setuptools.dist:Distribution._finalize_setup_keywords"

[project.entry-points."distutils.setup_keywords"]
eager_resources = "setuptools.dist:assert_string_list"
namespace_packages = "setuptools.dist:check_nsp"
extras_require = "setuptools.dist:check_extras"
install_requires = "setuptools.dist:check_requirements"
setup_requires = "setuptools.dist:check_requirements"
Expand All @@ -194,7 +190,6 @@ PKG-INFO = "setuptools.command.egg_info:write_pkg_info"
"requires.txt" = "setuptools.command.egg_info:write_requirements"
"entry_points.txt" = "setuptools.command.egg_info:write_entries"
"eager_resources.txt" = "setuptools.command.egg_info:overwrite_arg"
"namespace_packages.txt" = "setuptools.command.egg_info:overwrite_arg"
"top_level.txt" = "setuptools.command.egg_info:write_toplevel_names"
"dependency_links.txt" = "setuptools.command.egg_info:overwrite_arg"

Expand Down
3 changes: 0 additions & 3 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ ignore = [
[lint.per-file-ignores]
# Suppress nuisance warnings about module-import-not-at-top-of-file (E402) due to workaround for #4476
"setuptools/__init__.py" = ["E402"]
# pkg_resources is due for removal, not worth fixing existing errors
"pkg_resources/__init__.py" = ["E402", "ANN204"]
"pkg_resources/tests/test_resources.py" = ["PT031"]

[lint.isort]
combine-as-imports = true
Expand Down
5 changes: 1 addition & 4 deletions setuptools/_distutils/command/install_egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ def get_outputs(self):
return self.outputs


# The following routines are taken from setuptools' pkg_resources module and
# can be replaced by importing them from pkg_resources once it is included
# in the stdlib.

# The following routines were taken from setuptools' pkg_resources module which no longer exists

def safe_name(name):
"""Convert an arbitrary string to a standard distribution name
Expand Down
19 changes: 3 additions & 16 deletions setuptools/_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from collections.abc import Iterable
from typing import TYPE_CHECKING, TypedDict

from ._importlib import metadata, resources
from ._importlib import resources

if TYPE_CHECKING:
from typing_extensions import Self
Expand Down Expand Up @@ -134,10 +134,7 @@ class ScriptWriter:
try:
from importlib.metadata import distribution
except ImportError:
try:
from importlib_metadata import distribution
except ImportError:
from pkg_resources import load_entry_point
from importlib_metadata import distribution


def importlib_load_entry_point(spec, group, name):
Expand All @@ -149,13 +146,9 @@ def importlib_load_entry_point(spec, group, name):
)
return next(matches).load()


globals().setdefault('load_entry_point', importlib_load_entry_point)


if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(load_entry_point(%(spec)r, %(group)r, %(name)r)())
sys.exit(importlib_load_entry_point(%(spec)r, %(group)r, %(name)r)())
"""
).lstrip()

Expand All @@ -168,12 +161,6 @@ def get_args(cls, dist, header=None):
console_scripts and gui_scripts entry points.
"""

# If distribution is not an importlib.metadata.Distribution, assume
# it's a pkg_resources.Distribution and transform it.
if not hasattr(dist, 'entry_points'):
SetuptoolsWarning.emit("Unsupported distribution encountered.")
dist = metadata.Distribution.at(dist.egg_info)

if header is None:
header = cls.get_header()
spec = f'{dist.name}=={dist.version}'
Expand Down
19 changes: 0 additions & 19 deletions setuptools/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from ..warnings import SetuptoolsDeprecationWarning

import distutils.command.build_py as orig
import distutils.errors
from distutils.util import convert_path

_IMPLICIT_DATA_FILES = ('*.pyi', 'py.typed')
Expand Down Expand Up @@ -249,24 +248,6 @@ def check_package(self, package, package_dir):
init_py = orig.build_py.check_package(self, package, package_dir)
self.packages_checked[package] = init_py

if not init_py or not self.distribution.namespace_packages:
return init_py

for pkg in self.distribution.namespace_packages:
if pkg == package or pkg.startswith(package + '.'):
break
else:
return init_py

with open(init_py, 'rb') as f:
contents = f.read()
if b'declare_namespace' not in contents:
raise distutils.errors.DistutilsError(
f"Namespace package problem: {package} is a namespace package, but "
"its\n__init__.py does not call declare_namespace()! Please "
'fix it.\n(See the setuptools manual under '
'"Namespace Packages" for details.)\n"'
)
return init_py

def initialize_options(self):
Expand Down
Loading
Loading