summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2023-01-15 20:23:28 -0500
committerGitHub <noreply@github.com>2023-01-15 20:23:28 -0500
commit217d9267e017aed6ddff36fa47d82ceb475cbf22 (patch)
treebb2a615671f86bf18f8ef85593d0aedc6b4639bc /setuptools
parentef49c0a46de2e21287aff52033fd7ed460bb5c0e (diff)
parent0a6cd4fc60a5ac61ab8f57a52d171ef4d2837067 (diff)
downloadpython-setuptools-git-217d9267e017aed6ddff36fa47d82ceb475cbf22.tar.gz
Merge pull request #2822 from pypa/debt/remove-legacy-version
Remove reliance on LegacyVersion
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/command/egg_info.py2
-rw-r--r--setuptools/package_index.py40
-rw-r--r--setuptools/tests/test_dist_info.py50
-rw-r--r--setuptools/tests/test_packageindex.py2
4 files changed, 52 insertions, 42 deletions
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index 95c81845..1885efb0 100644
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -155,7 +155,7 @@ class InfoCommon:
if self.tag_build:
version += self.tag_build
if self.tag_date:
- version += time.strftime("-%Y%m%d")
+ version += time.strftime("%Y%m%d")
return version
vtags = property(tags)
diff --git a/setuptools/package_index.py b/setuptools/package_index.py
index 362e26f3..bec41835 100644
--- a/setuptools/package_index.py
+++ b/setuptools/package_index.py
@@ -169,39 +169,35 @@ def distros_for_filename(filename, metadata=None):
def interpret_distro_name(
location, basename, metadata, py_version=None, precedence=SOURCE_DIST, platform=None
):
- """Generate alternative interpretations of a source distro name
+ """Generate the interpretation of a source distro name
Note: if `location` is a filesystem filename, you should call
``pkg_resources.normalize_path()`` on it before passing it to this
routine!
"""
- # Generate alternative interpretations of a source distro name
- # Because some packages are ambiguous as to name/versions split
- # e.g. "adns-python-1.1.0", "egenix-mx-commercial", etc.
- # So, we generate each possible interpretation (e.g. "adns, python-1.1.0"
- # "adns-python, 1.1.0", and "adns-python-1.1.0, no version"). In practice,
- # the spurious interpretations should be ignored, because in the event
- # there's also an "adns" package, the spurious "python-1.1.0" version will
- # compare lower than any numeric version number, and is therefore unlikely
- # to match a request for it. It's still a potential problem, though, and
- # in the long run PyPI and the distutils should go for "safe" names and
- # versions in distribution archive names (sdist and bdist).
parts = basename.split('-')
if not py_version and any(re.match(r'py\d\.\d$', p) for p in parts[2:]):
# it is a bdist_dumb, not an sdist -- bail out
return
- for p in range(1, len(parts) + 1):
- yield Distribution(
- location,
- metadata,
- '-'.join(parts[:p]),
- '-'.join(parts[p:]),
- py_version=py_version,
- precedence=precedence,
- platform=platform,
- )
+ # find the pivot (p) that splits the name from the version.
+ # infer the version as the first item that has a digit.
+ for p in range(len(parts)):
+ if parts[p][:1].isdigit():
+ break
+ else:
+ p = len(parts)
+
+ yield Distribution(
+ location,
+ metadata,
+ '-'.join(parts[:p]),
+ '-'.join(parts[p:]),
+ py_version=py_version,
+ precedence=precedence,
+ platform=platform
+ )
def unique_values(func):
diff --git a/setuptools/tests/test_dist_info.py b/setuptools/tests/test_dist_info.py
index 350e6429..45b0d7fb 100644
--- a/setuptools/tests/test_dist_info.py
+++ b/setuptools/tests/test_dist_info.py
@@ -19,19 +19,18 @@ read = partial(pathlib.Path.read_text, encoding="utf-8")
class TestDistInfo:
- metadata_base = DALS("""
+ metadata_base = DALS(
+ """
Metadata-Version: 1.2
Requires-Dist: splort (==4)
Provides-Extra: baz
Requires-Dist: quux (>=1.1); extra == 'baz'
- """)
+ """
+ )
@classmethod
def build_metadata(cls, **kwargs):
- lines = (
- '{key}: {value}\n'.format(**locals())
- for key, value in kwargs.items()
- )
+ lines = ('{key}: {value}\n'.format(**locals()) for key, value in kwargs.items())
return cls.metadata_base + ''.join(lines)
@pytest.fixture
@@ -59,8 +58,7 @@ class TestDistInfo:
def test_distinfo(self, metadata):
dists = dict(
- (d.project_name, d)
- for d in pkg_resources.find_distributions(metadata)
+ (d.project_name, d) for d in pkg_resources.find_distributions(metadata)
)
assert len(dists) == 2, dists
@@ -84,13 +82,16 @@ class TestDistInfo:
assert d.extras == ['baz']
def test_invalid_version(self, tmp_path):
+ """
+ Supplying an invalid version crashes dist_info.
+ """
config = "[metadata]\nname=proj\nversion=42\n[egg_info]\ntag_build=invalid!!!\n"
(tmp_path / "setup.cfg").write_text(config, encoding="utf-8")
msg = re.compile("invalid version", re.M | re.I)
- output = run_command("dist_info", cwd=tmp_path)
- assert msg.search(output)
- dist_info = next(tmp_path.glob("*.dist-info"))
- assert dist_info.name.startswith("proj-42")
+ proc = run_command_inner("dist_info", cwd=tmp_path, check=False)
+ assert proc.returncode
+ assert msg.search(proc.stdout)
+ assert not list(tmp_path.glob("*.dist-info"))
def test_tag_arguments(self, tmp_path):
config = """
@@ -116,7 +117,7 @@ class TestDistInfo:
def test_output_dir(self, tmp_path, keep_egg_info):
config = "[metadata]\nname=proj\nversion=42\n"
(tmp_path / "setup.cfg").write_text(config, encoding="utf-8")
- out = (tmp_path / "__out")
+ out = tmp_path / "__out"
out.mkdir()
opts = ["--keep-egg-info"] if keep_egg_info else []
run_command("dist_info", "--output-dir", out, *opts, cwd=tmp_path)
@@ -133,7 +134,9 @@ class TestWheelCompatibility:
"""Make sure the .dist-info directory produced with the ``dist_info`` command
is the same as the one produced by ``bdist_wheel``.
"""
- SETUPCFG = DALS("""
+
+ SETUPCFG = DALS(
+ """
[metadata]
name = {name}
version = {version}
@@ -149,7 +152,8 @@ class TestWheelCompatibility:
executable-name = my_package.module:function
discover =
myproj = my_package.other_module:function
- """)
+ """
+ )
EGG_INFO_OPTS = [
# Related: #3088 #2872
@@ -189,7 +193,17 @@ class TestWheelCompatibility:
assert read(dist_info / file) == read(wheel_dist_info / file)
-def run_command(*cmd, **kwargs):
- opts = {"stderr": subprocess.STDOUT, "text": True, **kwargs}
+def run_command_inner(*cmd, **kwargs):
+ opts = {
+ "stderr": subprocess.STDOUT,
+ "stdout": subprocess.PIPE,
+ "text": True,
+ 'check': True,
+ **kwargs,
+ }
cmd = [sys.executable, "-c", "__import__('setuptools').setup()", *map(str, cmd)]
- return subprocess.check_output(cmd, **opts)
+ return subprocess.run(cmd, **opts)
+
+
+def run_command(*args, **kwargs):
+ return run_command_inner(*args, **kwargs).stdout
diff --git a/setuptools/tests/test_packageindex.py b/setuptools/tests/test_packageindex.py
index 7b0bf112..8b5356dc 100644
--- a/setuptools/tests/test_packageindex.py
+++ b/setuptools/tests/test_packageindex.py
@@ -180,7 +180,7 @@ class TestPackageIndex:
for v, vc in versions:
dists = list(
setuptools.package_index.distros_for_url(
- 'http://example.com/example.zip#egg=example-' + v
+ 'http://example.com/example-foo.zip#egg=example-foo-' + v
)
)
assert dists[0].version == ''