summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2023-01-24 00:03:03 +0000
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2023-01-24 01:14:45 +0000
commite5681c0e0d1292921a84dac61ba56e3cda8d857f (patch)
treea0b6a336af42726888813f2e98f6f93685415058 /setuptools
parentdd7b8fbccaefc5d8cb0ec8bfc3fe57f5695617f3 (diff)
downloadpython-setuptools-git-e5681c0e0d1292921a84dac61ba56e3cda8d857f.tar.gz
Centralize usage of pkg_resources from dist.py to installer.py
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/dist.py12
-rw-r--r--setuptools/installer.py62
2 files changed, 53 insertions, 21 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py
index f6504855..49d1ac6b 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -42,7 +42,6 @@ from setuptools.monkey import get_unpatched
from setuptools.config import setupcfg, pyprojecttoml
from setuptools.discovery import ConfigDiscovery
-import pkg_resources
from setuptools.extern.packaging import version
from . import _reqs
from . import _entry_points
@@ -888,14 +887,9 @@ class Distribution(_Distribution):
def fetch_build_eggs(self, requires):
"""Resolve pre-setup requirements"""
- resolved_dists = pkg_resources.working_set.resolve(
- _reqs.parse(requires),
- installer=self.fetch_build_egg,
- replace_conflicting=True,
- )
- for dist in resolved_dists:
- pkg_resources.working_set.add(dist, replace=True)
- return resolved_dists
+ from setuptools.installer import _fetch_build_eggs
+
+ return _fetch_build_eggs(self, requires)
def finalize_options(self):
"""
diff --git a/setuptools/installer.py b/setuptools/installer.py
index b7096df1..e9a7567a 100644
--- a/setuptools/installer.py
+++ b/setuptools/installer.py
@@ -6,9 +6,10 @@ import tempfile
import warnings
from distutils import log
from distutils.errors import DistutilsError
+from functools import partial
-import pkg_resources
-from setuptools.wheel import Wheel
+from . import _reqs
+from .wheel import Wheel
from ._deprecation_warning import SetuptoolsDeprecationWarning
@@ -20,20 +21,34 @@ def _fixup_find_links(find_links):
return find_links
-def fetch_build_egg(dist, req): # noqa: C901 # is too complex (16) # FIXME
+def fetch_build_egg(dist, req):
"""Fetch an egg needed for building.
Use pip/wheel to fetch/build a wheel."""
- warnings.warn(
- "setuptools.installer is deprecated. Requirements should "
- "be satisfied by a PEP 517 installer.",
- SetuptoolsDeprecationWarning,
+ _DeprecatedInstaller.warn(stacklevel=2)
+ _warn_wheel_not_available(dist)
+ return _fetch_build_egg_no_warn(dist, req)
+
+
+def _fetch_build_eggs(dist, requires):
+ import pkg_resources # Delay import to avoid unnecessary side-effects
+
+ _DeprecatedInstaller.warn(stacklevel=3)
+ _warn_wheel_not_available(dist)
+
+ resolved_dists = pkg_resources.working_set.resolve(
+ _reqs.parse(requires, pkg_resources.Requirement), # required for compatibility
+ installer=partial(_fetch_build_egg_no_warn, dist), # avoid warning twice
+ replace_conflicting=True,
)
- # Warn if wheel is not available
- try:
- pkg_resources.get_distribution('wheel')
- except pkg_resources.DistributionNotFound:
- dist.announce('WARNING: The wheel package is not available.', log.WARN)
+ for dist in resolved_dists:
+ pkg_resources.working_set.add(dist, replace=True)
+ return resolved_dists
+
+
+def _fetch_build_egg_no_warn(dist, req): # noqa: C901 # is too complex (16) # FIXME
+ import pkg_resources # Delay import to avoid unnecessary side-effects
+
# Ignore environment markers; if supplied, it is required.
req = strip_marker(req)
# Take easy_install options into account, but do not override relevant
@@ -98,7 +113,30 @@ def strip_marker(req):
calling pip with something like `babel; extra == "i18n"`, which
would always be ignored.
"""
+ import pkg_resources # Delay import to avoid unnecessary side-effects
+
# create a copy to avoid mutating the input
req = pkg_resources.Requirement.parse(str(req))
req.marker = None
return req
+
+
+def _warn_wheel_not_available(dist):
+ import pkg_resources # Delay import to avoid unnecessary side-effects
+
+ try:
+ pkg_resources.get_distribution('wheel')
+ except pkg_resources.DistributionNotFound:
+ dist.announce('WARNING: The wheel package is not available.', log.WARN)
+
+
+class _DeprecatedInstaller(SetuptoolsDeprecationWarning):
+ @classmethod
+ def warn(cls, stacklevel=1):
+ warnings.warn(
+ "setuptools.installer and fetch_build_eggs are deprecated. "
+ "Requirements should be satisfied by a PEP 517 installer. "
+ "If you are using pip, you can try `pip install --use-pep517`.",
+ cls,
+ stacklevel=stacklevel+1
+ )