Skip to content

Commit efadfca

Browse files
authored
Merge pull request #2794 from bollwyvl/check-pep625-sdist-urls
Also try mangling sdist urls to match pep625
2 parents 2c96e01 + 2bea2c2 commit efadfca

File tree

2 files changed

+300
-12
lines changed

2 files changed

+300
-12
lines changed

conda_forge_tick/url_transforms.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
2+
import re
23
from itertools import permutations
34

45
EXTS = [".tar.gz", ".zip", ".tar", ".tar.bz2", ".tar.xz", ".tgz"]
6+
PYPI_URLS = ["https://pypi.io", "https://files.pythonhosted.org"]
57

68

79
def _ext_munger(url):
@@ -48,23 +50,42 @@ def _v_munger(url):
4850

4951

5052
def _pypi_domain_munger(url):
51-
for old_d, new_d in permutations(
52-
["https://pypi.io", "https://files.pythonhosted.org"],
53-
2,
54-
):
53+
for old_d, new_d in permutations(PYPI_URLS, 2):
5554
yield url.replace(old_d, new_d, 1)
5655

5756

5857
def _pypi_name_munger(url):
5958
bn = os.path.basename(url)
60-
if (
61-
url.startswith("https://pypi.io")
62-
or url.startswith("https://files.pythonhosted.org")
63-
) and ("{{ version }}" in bn and "{{ name" not in bn):
64-
yield os.path.join(os.path.dirname(url), "{{ name }}-{{ version }}.tar.gz")
65-
59+
dn = os.path.dirname(url)
60+
dist_bn = os.path.basename(os.path.dirname(url))
61+
is_sdist = url.endswith(".tar.gz")
62+
is_pypi = any(url.startswith(pypi) for pypi in PYPI_URLS)
63+
has_version = re.search(r"\{\{\s*version", bn)
64+
has_name = re.search(r"\{\{\s*name", bn)
65+
66+
# try the original URL first, as a fallback (probably can't be removed?)
6667
yield url
6768

69+
if is_pypi and has_version and not has_name:
70+
yield os.path.join(dn, "{{ name }}-{{ version }}.tar.gz")
71+
72+
if not (is_sdist and is_pypi and has_version):
73+
return
74+
75+
# try static PEP625 name with PEP345 distribution name (_ not -)
76+
patterns = [
77+
# fully normalized
78+
r"[\.\-]+",
79+
# older, partial normalization
80+
r"[\-]+",
81+
]
82+
83+
for pattern in patterns:
84+
for dist_bn_case in {dist_bn, dist_bn.lower()}:
85+
yield os.path.join(
86+
dn, "%s-{{ version }}.tar.gz" % re.sub(pattern, "_", dist_bn_case)
87+
)
88+
6889

6990
def _pypi_munger(url):
7091
names = [
@@ -141,7 +162,9 @@ def gen_transformed_urls(url):
141162
url : str
142163
The URL to transform.
143164
"""
144-
yield from _gen_new_urls(
165+
yielded = set()
166+
167+
for new_url in _gen_new_urls(
145168
url,
146169
[
147170
_ext_munger,
@@ -154,4 +177,7 @@ def gen_transformed_urls(url):
154177
_pypi_name_munger,
155178
_github_munger,
156179
],
157-
)
180+
):
181+
if new_url not in yielded:
182+
yield new_url
183+
yielded.add(new_url)

0 commit comments

Comments
 (0)