Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rely on packaging and pkg_resources internal to pip. #343

Merged
merged 19 commits into from
Sep 14, 2022
Merged
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 setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ install_requires =
attrs>=19.2
cached_property
distlib>=0.2.8
packaging>=19.0
pep517>=0.5.0
pip>=22.2
platformdirs
Expand All @@ -52,7 +51,6 @@ install_requires =
setuptools>=40.8
tomlkit>=0.5.3
vistir==0.6.1
pyparsing<3.0.0

[options.extras_require]
tests =
Expand Down
3 changes: 0 additions & 3 deletions src/requirementslib/environment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding=utf-8 -*-
from __future__ import absolute_import, print_function

import os

from platformdirs import user_cache_dir
Expand Down
4 changes: 1 addition & 3 deletions src/requirementslib/models/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import hashlib
import json
import os
import pathlib
import sys

import vistir
from packaging.requirements import Requirement
from pip._internal.utils.hashes import FAVORITE_HASH
from pip._internal.vcs.versioncontrol import VcsSupport
from pip._vendor.cachecontrol.cache import DictCache
from pip._vendor.packaging.requirements import Requirement
from platformdirs import user_cache_dir

from .utils import as_tuple, get_pinned_version, key_from_req, lookup_table
Expand Down
27 changes: 6 additions & 21 deletions src/requirementslib/models/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
# -*- coding=utf-8 -*-

import atexit
import contextlib
import copy
import functools
import os
from contextlib import ExitStack
from json import JSONDecodeError

import attr
import requests
from packaging.markers import Marker
from packaging.utils import canonicalize_name
from packaging.version import parse
from pip._internal.cache import WheelCache
from pip._internal.models.format_control import FormatControl
from pip._internal.operations.build.build_tracker import get_build_tracker
from pip._internal.req.constructors import install_req_from_line
from pip._internal.req.req_install import InstallRequirement
from pip._internal.req.req_set import RequirementSet
from pip._internal.utils.temp_dir import TempDirectory, global_tempdir_manager
from pip._vendor.packaging.markers import Marker
from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.packaging.version import parse
from vistir.compat import fs_str
from vistir.contextmanagers import temp_environ
from vistir.path import create_tracked_tempdir
Expand All @@ -35,7 +32,6 @@
from .setup_info import SetupInfo
from .utils import (
clean_requires_python,
fix_requires_python_marker,
format_requirement,
full_groupby,
is_pinned_requirement,
Expand All @@ -46,23 +42,12 @@
)

if MYPY_RUNNING:
from typing import (
Any,
Dict,
Generator,
List,
Optional,
Set,
Text,
Tuple,
TypeVar,
Union,
)
from typing import Any, Dict, List, Optional, Set, Text, TypeVar, Union

from packaging.requirements import Requirement as PackagingRequirement
from pip._internal.commands.base_command import Command
from pip._internal.commands import Command
from pip._internal.index.package_finder import PackageFinder
from pip._internal.models.candidate import InstallationCandidate
from pip._vendor.packaging.requirements import Requirement as PackagingRequirement

TRequirement = TypeVar("TRequirement")
RequirementType = TypeVar(
Expand Down
3 changes: 0 additions & 3 deletions src/requirementslib/models/lockfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function

import copy
import itertools
import os
Expand Down
11 changes: 5 additions & 6 deletions src/requirementslib/models/markers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# -*- coding: utf-8 -*-
import itertools
import operator
import re
from collections.abc import Mapping, Set
from functools import lru_cache, reduce

import attr
import distlib.markers
from packaging.markers import InvalidMarker, Marker
from packaging.specifiers import LegacySpecifier, Specifier, SpecifierSet
from packaging.version import parse
from distlib import markers
from pip._vendor.packaging.markers import InvalidMarker, Marker
from pip._vendor.packaging.specifiers import LegacySpecifier, Specifier, SpecifierSet
from pip._vendor.packaging.version import parse
from vistir.misc import dedup

from ..environment import MYPY_RUNNING
Expand Down Expand Up @@ -514,7 +513,7 @@ def get_contained_pyversions(marker):
return set()
# Use the distlib dictionary parser to create a dictionary 'trie' which is a bit
# easier to reason about
marker_dict = distlib.markers.parse_marker(marker_str)[0]
marker_dict = markers.parse_marker(marker_str)[0]
version_set = set()
pyversions, _ = parse_marker_dict(marker_dict)
if isinstance(pyversions, set):
Expand Down
42 changes: 20 additions & 22 deletions src/requirementslib/models/metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding=utf-8 -*-
import datetime
import functools
import io
Expand All @@ -12,15 +11,15 @@
from typing import Sequence

import attr
import distlib.metadata
import distlib.wheel
import requests
import vistir
from packaging.markers import Marker
from packaging.requirements import Requirement as PackagingRequirement
from packaging.specifiers import Specifier, SpecifierSet
from packaging.tags import Tag
from packaging.version import _BaseVersion, parse
from distlib import wheel
from distlib.metadata import Metadata
from pip._vendor.packaging.markers import Marker
from pip._vendor.packaging.requirements import Requirement as PackagingRequirement
from pip._vendor.packaging.specifiers import Specifier, SpecifierSet
from pip._vendor.packaging.tags import Tag
from pip._vendor.packaging.version import _BaseVersion, parse

from ..environment import MYPY_RUNNING
from .markers import (
Expand All @@ -47,7 +46,6 @@
Any,
Callable,
Dict,
Generator,
Generic,
Iterator,
List,
Expand Down Expand Up @@ -137,7 +135,7 @@ def validate_digest(inst, attrib, value):


def get_local_wheel_metadata(wheel_file):
# type: (str) -> Optional[distlib.metadata.Metadata]
# type: (str) -> Optional[Metadata]
parsed_metadata = None
with io.open(wheel_file, "rb") as fh:
with zipfile.ZipFile(fh, mode="r", compression=zipfile.ZIP_DEFLATED) as zf:
Expand All @@ -149,7 +147,7 @@ def get_local_wheel_metadata(wheel_file):
if metadata is None:
raise RuntimeError("No metadata found in wheel: {0}".format(wheel_file))
with zf.open(metadata, "r") as metadata_fh:
parsed_metadata = distlib.metadata.Metadata(fileobj=metadata_fh)
parsed_metadata = Metadata(fileobj=metadata_fh)
return parsed_metadata


Expand All @@ -165,7 +163,7 @@ def get_remote_sdist_metadata(line):


def get_remote_wheel_metadata(whl_file):
# type: (str) -> Optional[distlib.metadata.Metadata]
# type: (str) -> Optional[Metadata]
parsed_metadata = None
data = io.BytesIO()
with vistir.contextmanagers.open_file(whl_file) as fp:
Expand All @@ -180,7 +178,7 @@ def get_remote_wheel_metadata(whl_file):
if metadata is None:
raise RuntimeError("No metadata found in wheel: {0}".format(whl_file))
with zf.open(metadata, "r") as metadata_fh:
parsed_metadata = distlib.metadata.Metadata(fileobj=metadata_fh)
parsed_metadata = Metadata(fileobj=metadata_fh)
return parsed_metadata


Expand Down Expand Up @@ -258,11 +256,11 @@ def as_line(self):
markers = [marker_from_specifier(str(s)) for s in specifiers]
py_version_part = reduce(merge_markers, markers)
if self.markers:
line_str = "{0}; {1}".format(line_str, str(self.markers))
line_str = "{0} ; {1}".format(line_str, str(self.markers))
if py_version_part:
line_str = "{0} and {1}".format(line_str, py_version_part)
elif py_version_part and not self.markers:
line_str = "{0}; {1}".format(line_str, py_version_part)
line_str = "{0} ; {1}".format(line_str, py_version_part)
return line_str

def pin(self):
Expand Down Expand Up @@ -350,7 +348,7 @@ def from_info(cls, info):
marker_str = "{0!s}".format(marker)
req_str = "{0}=={1}".format(info.name, info.version)
if marker_str:
req_str = "{0}; {1}".format(req_str, marker_str)
req_str = "{0} ; {1}".format(req_str, marker_str)
req = PackagingRequirement(req_str)
requires_python_str = (
info.requires_python if info.requires_python is not None else ""
Expand Down Expand Up @@ -570,7 +568,7 @@ def pep508_url(self):
markers = self.markers
req_str = "{0} @ {1}#egg={0}".format(self.name, self.url)
if markers:
req_str = "{0}; {1}".format(req_str, markers)
req_str = "{0} ; {1}".format(req_str, markers)
return req_str

def get_markers_from_wheel(self):
Expand Down Expand Up @@ -644,7 +642,7 @@ def create(cls, release_dict, name=None):
release_url = cls(**filter_dict(creation_kwargs)) # type: ignore
if release_url.is_wheel:
supported_tags = [
parse_tag(Tag(*tag)) for tag in distlib.wheel.Wheel(release_url.url).tags
parse_tag(Tag(*tag)) for tag in wheel.Wheel(release_url.url).tags
]
release_url = attr.evolve(release_url, tags=supported_tags)
return release_url
Expand Down Expand Up @@ -858,8 +856,8 @@ def get_latest_lockfile(self):
def wheels(self):
# type: () -> Iterator[ReleaseUrl]
for release in self.sort_releases():
for wheel in release.wheels:
yield wheel
for w in release.wheels:
yield w

def sdists(self):
# type: () -> Iterator[ReleaseUrl]
Expand Down Expand Up @@ -1060,8 +1058,8 @@ def latest_sdist(self):
@property
def latest_wheels(self):
# type: () -> Iterator[ReleaseUrl]
for wheel in self.urls.wheels:
yield wheel
for w in self.urls.wheels:
yield w

@property
def dependencies(self):
Expand Down
4 changes: 0 additions & 4 deletions src/requirementslib/models/pipfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, print_function, unicode_literals

import copy
import itertools
import os
Expand Down
8 changes: 2 additions & 6 deletions src/requirementslib/models/project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding=utf-8 -*-

from __future__ import absolute_import, print_function, unicode_literals

import collections
import io
import os
Expand All @@ -10,8 +6,8 @@
import plette
import plette.models
import tomlkit
from packaging.markers import Marker
from packaging.utils import canonicalize_name
from pip._vendor.packaging.markers import Marker
from pip._vendor.packaging.utils import canonicalize_name

SectionDifference = collections.namedtuple("SectionDifference", ["inthis", "inthat"])
FileDifference = collections.namedtuple("FileDifference", ["default", "develop"])
Expand Down
Loading