Skip to content

Commit 7981744

Browse files
committed
also try mangling sdist urls to match pep625
1 parent b68ad6d commit 7981744

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

conda_forge_tick/url_transforms.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
2+
import re
3+
24
from itertools import permutations
35

46
EXTS = [".tar.gz", ".zip", ".tar", ".tar.bz2", ".tar.xz", ".tgz"]
5-
7+
PYPI_URLS = ["https://pypi.io", "https://files.pythonhosted.org"]
68

79
def _ext_munger(url):
810
for old_ext, new_ext in permutations(EXTS, 2):
@@ -48,23 +50,29 @@ 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")
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)
6564

65+
# try the original url first, as a fallback (probably can't be removed?)
6666
yield url
6767

68+
if not (is_sdist and is_pypi and has_version):
69+
return
70+
71+
# try static PEP625 name with PEP345 distribution name (_ not -)
72+
yield os.path.join(dn, '%s-{{ version }}.tar.gz' % dist_bn.replace("-", "_"))
73+
# many legacy names had - which would match the name
74+
yield os.path.join(dn, '%s-{{ version }}.tar.gz' % dist_bn)
75+
6876

6977
def _pypi_munger(url):
7078
names = [
@@ -141,7 +149,9 @@ def gen_transformed_urls(url):
141149
url : str
142150
The URL to transform.
143151
"""
144-
yield from _gen_new_urls(
152+
yielded = []
153+
154+
for new_url in _gen_new_urls(
145155
url,
146156
[
147157
_ext_munger,
@@ -154,4 +164,7 @@ def gen_transformed_urls(url):
154164
_pypi_name_munger,
155165
_github_munger,
156166
],
157-
)
167+
):
168+
if new_url not in yielded:
169+
yield new_url
170+
yielded.append(new_url)

0 commit comments

Comments
 (0)