Skip to content

Commit

Permalink
Import dependencies naturally and ensure they're available by appendi…
Browse files Browse the repository at this point in the history
…ng the vendor dir to sys.path.
  • Loading branch information
jaraco committed Jul 2, 2024
1 parent a330bd4 commit 515e738
Show file tree
Hide file tree
Showing 28 changed files with 60 additions and 54 deletions.
3 changes: 3 additions & 0 deletions setuptools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import functools
import os
import re
import sys
from typing import TYPE_CHECKING

sys.path.append(os.path.dirname(__file__) + '/_vendor')

import _distutils_hack.override # noqa: F401
import distutils.core
from distutils.errors import DistutilsOptionError
Expand Down
8 changes: 4 additions & 4 deletions setuptools/_core_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from distutils.util import rfc822_escape

from . import _normalization, _reqs
from .extern.packaging.markers import Marker
from .extern.packaging.requirements import Requirement
from .extern.packaging.utils import canonicalize_name, canonicalize_version
from .extern.packaging.version import Version
from packaging.markers import Marker
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name, canonicalize_version
from packaging.version import Version
from .warnings import SetuptoolsDeprecationWarning


Expand Down
6 changes: 3 additions & 3 deletions setuptools/_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import itertools

from .errors import OptionError
from .extern.jaraco.text import yield_lines
from .extern.jaraco.functools import pass_none
from jaraco.text import yield_lines
from jaraco.functools import pass_none
from ._importlib import metadata
from ._itertools import ensure_unique
from .extern.more_itertools import consume
from more_itertools import consume


def ensure_valid(ep):
Expand Down
4 changes: 2 additions & 2 deletions setuptools/_importlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def disable_importlib_metadata_finder(metadata):


if sys.version_info < (3, 10):
from setuptools.extern import importlib_metadata as metadata
import importlib_metadata as metadata

disable_importlib_metadata_finder(metadata)
else:
import importlib.metadata as metadata


if sys.version_info < (3, 9):
from setuptools.extern import importlib_resources as resources
import importlib_resources as resources
else:
import importlib.resources as resources # noqa: F401
4 changes: 2 additions & 2 deletions setuptools/_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import re

from .extern import packaging
import packaging

# https://packaging.python.org/en/latest/specifications/core-metadata/#name
_VALID_NAME = re.compile(r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.I)
Expand Down Expand Up @@ -54,7 +54,7 @@ def safe_version(version: str) -> str:
>>> safe_version("ubuntu lts")
Traceback (most recent call last):
...
setuptools.extern.packaging.version.InvalidVersion: Invalid version: 'ubuntu.lts'
packaging.version.InvalidVersion: Invalid version: 'ubuntu.lts'
"""
v = version.replace(' ', '.')
try:
Expand Down
4 changes: 2 additions & 2 deletions setuptools/_reqs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from functools import lru_cache
from typing import Callable, Iterable, Iterator, TypeVar, Union, overload

import setuptools.extern.jaraco.text as text
from setuptools.extern.packaging.requirements import Requirement
import jaraco.text as text
from packaging.requirements import Requirement

_T = TypeVar("_T")
_StrOrIter = Union[str, Iterable[str]]
Expand Down
4 changes: 2 additions & 2 deletions setuptools/command/_requirestxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from typing import Dict, Mapping, TypeVar

from .. import _reqs
from ..extern.jaraco.text import yield_lines
from ..extern.packaging.requirements import Requirement
from jaraco.text import yield_lines
from packaging.requirements import Requirement


# dict can work as an ordered set
Expand Down
10 changes: 5 additions & 5 deletions setuptools/command/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from zipfile import ZIP_DEFLATED, ZIP_STORED

from .. import Command, __version__
from ..extern.wheel.metadata import pkginfo_to_metadata
from ..extern.packaging import tags
from ..extern.packaging import version as _packaging_version
from ..extern.wheel.wheelfile import WheelFile
from wheel.metadata import pkginfo_to_metadata
from packaging import tags
from packaging import version as _packaging_version
from wheel.wheelfile import WheelFile

if TYPE_CHECKING:
import types
Expand Down Expand Up @@ -68,7 +68,7 @@ def get_platform(archive_root: str | None) -> str:
"""Return our platform name 'win32', 'linux_x86_64'"""
result = sysconfig.get_platform()
if result.startswith("macosx") and archive_root is not None:
from ..extern.wheel.macosx_libfile import calculate_macosx_platform_tag
from wheel.macosx_libfile import calculate_macosx_platform_tag

result = calculate_macosx_platform_tag(archive_root, result)
elif _is_32bit_interpreter():
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pathlib import Path
from typing import Iterable, Iterator

from ..extern.more_itertools import unique_everseen
from more_itertools import unique_everseen
from ..warnings import SetuptoolsDeprecationWarning


Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
import pkg_resources
from ..compat import py39, py311
from .._path import ensure_directory
from ..extern.jaraco.text import yield_lines
from jaraco.text import yield_lines


# Turn on PEP440Warnings
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/editable_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def _safely_run(self, cmd_name: str):
)

def _create_wheel_file(self, bdist_wheel):
from ..extern.wheel.wheelfile import WheelFile
from wheel.wheelfile import WheelFile

dist_info = self.get_finalized_command("dist_info")
dist_name = dist_info.name
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import setuptools.unicode_utils as unicode_utils
from setuptools.glob import glob

from setuptools.extern import packaging
import packaging
from ..warnings import SetuptoolsDeprecationWarning


Expand Down
4 changes: 2 additions & 2 deletions setuptools/command/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
)
from .._importlib import metadata
from setuptools import Command
from setuptools.extern.more_itertools import unique_everseen
from setuptools.extern.jaraco.functools import pass_none
from more_itertools import unique_everseen
from jaraco.functools import pass_none


class ScanningLoader(TestLoader):
Expand Down
2 changes: 1 addition & 1 deletion setuptools/compat/py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
if sys.version_info >= (3, 11):
import tomllib
else: # pragma: no cover
from setuptools.extern import tomli as tomllib
import tomli as tomllib
2 changes: 1 addition & 1 deletion setuptools/config/_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _project_urls(dist: Distribution, val: dict, _root_dir):


def _python_requires(dist: Distribution, val: dict, _root_dir):
from setuptools.extern.packaging.specifiers import SpecifierSet
from packaging.specifiers import SpecifierSet

_set_config(dist, "python_requires", SpecifierSet(val))

Expand Down
4 changes: 2 additions & 2 deletions setuptools/config/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def read_files(
(By default ``root_dir`` is the current directory).
"""
from setuptools.extern.more_itertools import always_iterable
from more_itertools import always_iterable

root_dir = os.path.abspath(root_dir or os.getcwd())
_filepaths = (os.path.join(root_dir, path) for path in always_iterable(filepaths))
Expand Down Expand Up @@ -287,7 +287,7 @@ def find_packages(
:rtype: list
"""
from setuptools.discovery import construct_package_dir
from setuptools.extern.more_itertools import unique_everseen, always_iterable
from more_itertools import unique_everseen, always_iterable

if namespaces:
from setuptools.discovery import PEP420PackageFinder as PackageFinder
Expand Down
2 changes: 1 addition & 1 deletion setuptools/config/pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _ensure_previously_set(self, dist: Distribution, field: str):
def _expand_directive(
self, specifier: str, directive, package_dir: Mapping[str, str]
):
from setuptools.extern.more_itertools import always_iterable
from more_itertools import always_iterable

with _ignore_errors(self.ignore_option_errors):
root_dir = self.root_dir
Expand Down
8 changes: 4 additions & 4 deletions setuptools/config/setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

from .._path import StrPath
from ..errors import FileError, OptionError
from ..extern.packaging.markers import default_environment as marker_env
from ..extern.packaging.requirements import InvalidRequirement, Requirement
from ..extern.packaging.specifiers import SpecifierSet
from ..extern.packaging.version import InvalidVersion, Version
from packaging.markers import default_environment as marker_env
from packaging.requirements import InvalidRequirement, Requirement
from packaging.specifiers import SpecifierSet
from packaging.version import InvalidVersion, Version
from ..warnings import SetuptoolsDeprecationWarning
from . import expand

Expand Down
2 changes: 1 addition & 1 deletion setuptools/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from . import _imp
from ._imp import find_module, PY_COMPILED, PY_FROZEN, PY_SOURCE
from .extern.packaging.version import Version
from packaging.version import Version


__all__ = ['Require', 'find_module']
Expand Down
10 changes: 5 additions & 5 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
from distutils.fancy_getopt import translate_longopt
from distutils.util import strtobool

from .extern.more_itertools import partition, unique_everseen
from .extern.ordered_set import OrderedSet
from .extern.packaging.markers import InvalidMarker, Marker
from .extern.packaging.specifiers import InvalidSpecifier, SpecifierSet
from .extern.packaging.version import Version
from more_itertools import partition, unique_everseen
from ordered_set import OrderedSet
from packaging.markers import InvalidMarker, Marker
from packaging.specifiers import InvalidSpecifier, SpecifierSet
from packaging.version import Version

from . import _entry_points
from . import _normalization
Expand Down
3 changes: 2 additions & 1 deletion setuptools/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import subprocess
import distutils.errors
from typing import TYPE_CHECKING
from setuptools.extern.more_itertools import unique_everseen

from more_itertools import unique_everseen

# https://github.com/python/mypy/issues/8166
if not TYPE_CHECKING and platform.system() == 'Windows':
Expand Down
3 changes: 2 additions & 1 deletion setuptools/package_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
from distutils.errors import DistutilsError
from fnmatch import translate
from setuptools.wheel import Wheel
from setuptools.extern.more_itertools import unique_everseen

from more_itertools import unique_everseen

from .unicode_utils import _read_utf8_with_fallback, _cfg_read_utf8_with_fallback

Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/config/test_setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from distutils.errors import DistutilsOptionError, DistutilsFileError
from setuptools.dist import Distribution, _Distribution
from setuptools.config.setupcfg import ConfigHandler, read_configuration
from setuptools.extern.packaging.requirements import InvalidRequirement
from packaging.requirements import InvalidRequirement
from setuptools.warnings import SetuptoolsDeprecationWarning
from ..textwrap import DALS

Expand Down
6 changes: 3 additions & 3 deletions setuptools/tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
remove_readonly_exc,
)
from setuptools.dist import Distribution
from setuptools.extern.packaging import tags
from packaging import tags

DEFAULT_FILES = {
"dummy_dist-1.0.dist-info/top_level.txt",
Expand Down Expand Up @@ -598,12 +598,12 @@ def _fake_import(name: str, *args, **kwargs):
return importlib.__import__(name, *args, **kwargs)

with suppress(KeyError):
monkeypatch.delitem(sys.modules, "setuptools.extern.wheel.macosx_libfile")
monkeypatch.delitem(sys.modules, "wheel.macosx_libfile")

# Install an importer shim that refuses to load ctypes
monkeypatch.setattr(builtins, "__import__", _fake_import)
with pytest.raises(ModuleNotFoundError, match="No module named ctypes"):
import setuptools.extern.wheel.macosx_libfile
import wheel.macosx_libfile # noqa: F401

# Unload and reimport the bdist_wheel command module to make sure it won't try to
# import ctypes
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_extern.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pickle

from setuptools import Distribution
from setuptools.extern import ordered_set
import ordered_set


def test_reimport_extern():
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_setuptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import setuptools.depends as dep
from setuptools.depends import Require

from setuptools.extern.packaging.version import Version
from packaging.version import Version


@pytest.fixture(autouse=True)
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from jaraco import path

from pkg_resources import Distribution, PathMetadata, PY_MAJOR
from setuptools.extern.packaging.utils import canonicalize_name
from setuptools.extern.packaging.tags import parse_tag
from packaging.utils import canonicalize_name
from packaging.tags import parse_tag
from setuptools.wheel import Wheel

from .contexts import tempdir
Expand Down
7 changes: 4 additions & 3 deletions setuptools/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import zipfile
import contextlib

from packaging.version import Version as parse_version
from packaging.tags import sys_tags
from packaging.utils import canonicalize_name

from distutils.util import get_platform

import setuptools
from setuptools.extern.packaging.version import Version as parse_version
from setuptools.extern.packaging.tags import sys_tags
from setuptools.extern.packaging.utils import canonicalize_name
from setuptools.command.egg_info import write_requirements, _egg_basename
from setuptools.archive_util import _unpack_zipfile_obj

Expand Down

0 comments on commit 515e738

Please sign in to comment.