1
1
import os
2
+ import re
3
+
2
4
from itertools import permutations
3
5
4
6
EXTS = [".tar.gz" , ".zip" , ".tar" , ".tar.bz2" , ".tar.xz" , ".tgz" ]
5
-
7
+ PYPI_URLS = [ "https://pypi.io" , "https://files.pythonhosted.org" ]
6
8
7
9
def _ext_munger (url ):
8
10
for old_ext , new_ext in permutations (EXTS , 2 ):
@@ -48,23 +50,29 @@ def _v_munger(url):
48
50
49
51
50
52
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 ):
55
54
yield url .replace (old_d , new_d , 1 )
56
55
57
56
58
57
def _pypi_name_munger (url ):
59
58
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 )
65
64
65
+ # try the original url first, as a fallback (probably can't be removed?)
66
66
yield url
67
67
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
+
68
76
69
77
def _pypi_munger (url ):
70
78
names = [
@@ -141,7 +149,9 @@ def gen_transformed_urls(url):
141
149
url : str
142
150
The URL to transform.
143
151
"""
144
- yield from _gen_new_urls (
152
+ yielded = []
153
+
154
+ for new_url in _gen_new_urls (
145
155
url ,
146
156
[
147
157
_ext_munger ,
@@ -154,4 +164,7 @@ def gen_transformed_urls(url):
154
164
_pypi_name_munger ,
155
165
_github_munger ,
156
166
],
157
- )
167
+ ):
168
+ if new_url not in yielded :
169
+ yield new_url
170
+ yielded .append (new_url )
0 commit comments