Skip to content

Commit

Permalink
drop pkg_resources from bdist_wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Mar 10, 2023
1 parent e2e4d1f commit 0c6b17f
Show file tree
Hide file tree
Showing 3 changed files with 647 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from __future__ import annotations

import importlib.metadata
import os
import re
import shutil
Expand All @@ -21,20 +22,38 @@
from shutil import rmtree
from zipfile import ZIP_DEFLATED, ZIP_STORED

import pkg_resources
from setuptools import Command

from . import __version__ as wheel_version
from .macosx_libfile import calculate_macosx_platform_tag
from .metadata import pkginfo_to_metadata
from .util import log
from .vendored.packaging import tags
from .vendored.packaging import version as _packaging_version
from .wheelfile import WheelFile

safe_name = pkg_resources.safe_name
safe_version = pkg_resources.safe_version

def safe_name(name):
"""Convert an arbitrary string to a standard distribution name
Any runs of non-alphanumeric/. characters are replaced with a single '-'.
"""
return re.sub("[^A-Za-z0-9.]+", "-", name)


def safe_version(version):
"""
Convert an arbitrary string to a standard version string
"""
try:
# normalize the version
return str(_packaging_version.Version(version))
except _packaging_version.InvalidVersion:
version = version.replace(" ", ".")
return re.sub("[^A-Za-z0-9.]+", "-", version)


setuptools_major_version = int(
pkg_resources.get_distribution("setuptools").version.split(".")[0]
importlib.metadata.distribution("setuptools").version.split(".")[0]
)

PY_LIMITED_API_PATTERN = r"cp3\d"
Expand Down
61 changes: 61 additions & 0 deletions src/wheel/vendored/packaging/_structures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.


class InfinityType:
def __repr__(self) -> str:
return "Infinity"

def __hash__(self) -> int:
return hash(repr(self))

def __lt__(self, other: object) -> bool:
return False

def __le__(self, other: object) -> bool:
return False

def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__)

def __gt__(self, other: object) -> bool:
return True

def __ge__(self, other: object) -> bool:
return True

def __neg__(self: object) -> "NegativeInfinityType":
return NegativeInfinity


Infinity = InfinityType()


class NegativeInfinityType:
def __repr__(self) -> str:
return "-Infinity"

def __hash__(self) -> int:
return hash(repr(self))

def __lt__(self, other: object) -> bool:
return True

def __le__(self, other: object) -> bool:
return True

def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__)

def __gt__(self, other: object) -> bool:
return False

def __ge__(self, other: object) -> bool:
return False

def __neg__(self: object) -> InfinityType:
return Infinity


NegativeInfinity = NegativeInfinityType()
Loading

0 comments on commit 0c6b17f

Please sign in to comment.