16
16
import shutil
17
17
import tempfile
18
18
import time
19
- import re
20
19
21
20
from collections import defaultdict
22
21
from typing import List
30
29
import packageurl
31
30
import requests
32
31
33
- from requests .auth import AuthBase , HTTPBasicAuth
34
-
35
32
from bs4 import BeautifulSoup
36
33
from commoncode import fileutils
37
34
from commoncode .hash import multi_checksums
102
99
103
100
"""
104
101
105
- TRACE = True
106
- TRACE_DEEP = True
102
+ TRACE = False
103
+ TRACE_DEEP = False
107
104
TRACE_ULTRA_DEEP = False
108
105
109
106
# Supported environments
@@ -220,31 +217,6 @@ def get_python_dot_version(version):
220
217
class DistributionNotFound (Exception ):
221
218
pass
222
219
223
- class HTTPUrlAuth (AuthBase ):
224
- """Modifies the URL to contain the credentials aka https://user:[email protected] """
225
- def __init__ (self , username , password ):
226
- self .username = username
227
- self .password = password
228
-
229
- def __eq__ (self , other ):
230
- return all (
231
- [
232
- self .username == getattr (other , "username" , None ),
233
- self .password == getattr (other , "password" , None ),
234
- ]
235
- )
236
-
237
- def __ne__ (self , other ):
238
- return not self == other
239
-
240
- def __call__ (self , r ):
241
- url_re = re .compile ("(https?://)(.*)" )
242
- match = url_re .search (r .url )
243
- if match :
244
- url = f"{ match .group (1 )} { self .username } :{ self .password } @{ match .group (2 )} "
245
- r .url = url
246
- return r
247
-
248
220
def download_wheel (
249
221
name ,
250
222
version ,
@@ -281,6 +253,7 @@ def download_wheel(
281
253
)
282
254
continue
283
255
for wheel in supported_and_valid_wheels :
256
+ wheel .credentials = repo .credentials
284
257
fetched_wheel_filename = wheel .download (
285
258
dest_dir = dest_dir ,
286
259
verbose = verbose ,
@@ -653,10 +626,6 @@ def get_best_download_url(self, repos=tuple()):
653
626
654
627
for repo in repos :
655
628
package = repo .get_package_version (name = self .name , version = self .version )
656
- if TRACE :
657
- print (f"Repo: { repo = } " )
658
- print (f"get_best_download_url: { self .name = } and { self .version = } " )
659
- print (f"{ repo .index_url = } " )
660
629
if not package :
661
630
if TRACE :
662
631
print (
@@ -693,9 +662,6 @@ def download(
693
662
)
694
663
695
664
# FIXME:
696
- if TRACE :
697
- print (f"utils_pypi.py -> download() => { self .path_or_url = } " )
698
- print (f"utils_pypi.py -> download() => { dest_dir = } " )
699
665
fetch_and_save (
700
666
path_or_url = self .path_or_url ,
701
667
dest_dir = dest_dir ,
@@ -1153,7 +1119,7 @@ def is_supported_by_tags(self, tags):
1153
1119
"""
1154
1120
Return True is this wheel is compatible with one of a list of PEP 425 tags.
1155
1121
"""
1156
- if TRACE_ULTRA_DEEP :
1122
+ if TRACE_DEEP :
1157
1123
print ()
1158
1124
print ("is_supported_by_tags: tags:" , tags )
1159
1125
print ("self.tags:" , self .tags )
@@ -1169,8 +1135,6 @@ def to_filename(self):
1169
1135
abis = "." .join (self .abis )
1170
1136
plats = "." .join (self .platforms )
1171
1137
name = f"{ self .name } -{ self .version } { build } -{ pyvers } -{ abis } -{ plats } .whl"
1172
- if TRACE :
1173
- print (f"The wheel filename is: { name = } " )
1174
1138
return name
1175
1139
1176
1140
def is_pure (self ):
@@ -1634,18 +1598,6 @@ def fetch_links(
1634
1598
name using the `index_url` of this repository.
1635
1599
"""
1636
1600
package_url = f"{ self .index_url } /{ normalized_name } "
1637
- if TRACE :
1638
- print (f"utils_pypi.py -> fetch_links() => { package_url = } " )
1639
- # if len(package_url) >= 256:
1640
- # base64_re = re.compile(f"https://(.*:.*)@(.*){normalized_name}")
1641
- # match = base64_re.search(self.index_url)
1642
- # if match:
1643
- # auth = match.group(1)
1644
- # username = auth.split(":")[0]
1645
- # token = auth.split(":")[1]
1646
- # remainder = match.group(2)
1647
- # new_index_url = f"https://{username}:auth_token@{remainder}"
1648
- # package_url = f"{new_index_url}/{normalized_name}"
1649
1601
text = CACHE .get (
1650
1602
path_or_url = package_url ,
1651
1603
credentials = self .credentials ,
@@ -1688,7 +1640,10 @@ def resolve_relative_url(package_url, url):
1688
1640
path = urlunparse (
1689
1641
("" , "" , url_parts .path , url_parts .params , url_parts .query , url_parts .fragment )
1690
1642
)
1691
- resolved_url_parts = base_url_parts ._replace (path = path )
1643
+ if base_url_parts .path != "" :
1644
+ resolved_url_parts = base_url_parts ._replace (path = base_url_parts .path + "/" + path )
1645
+ else :
1646
+ resolved_url_parts = base_url_parts ._replace (path = path )
1692
1647
url = urlunparse (resolved_url_parts )
1693
1648
return url
1694
1649
@@ -1731,15 +1686,13 @@ def get(
1731
1686
True otherwise as treat as binary. `path_or_url` can be a path or a URL
1732
1687
to a file.
1733
1688
"""
1689
+
1690
+
1734
1691
cache_key = quote_plus (path_or_url .strip ("/" ))
1735
1692
cached = os .path .join (self .directory , cache_key )
1736
- if TRACE :
1737
- print (f"Cache.get() => { path_or_url = } " )
1738
- print (f"Cache.get() => { cache_key = } " )
1739
- print (f"Cache.get() => { cached = } " )
1740
1693
1741
1694
if force or not os .path .exists (cached ):
1742
- if TRACE :
1695
+ if TRACE_DEEP :
1743
1696
print (f" FILE CACHE MISS: { path_or_url } " )
1744
1697
content = get_file_content (
1745
1698
path_or_url = path_or_url ,
@@ -1753,7 +1706,7 @@ def get(
1753
1706
fo .write (content )
1754
1707
return content
1755
1708
else :
1756
- if TRACE :
1709
+ if TRACE_DEEP :
1757
1710
print (f" FILE CACHE HIT: { path_or_url } " )
1758
1711
return get_local_file_content (path = cached , as_text = as_text )
1759
1712
@@ -1773,7 +1726,7 @@ def get_file_content(
1773
1726
remote URL. Return the content as bytes is `as_text` is False.
1774
1727
"""
1775
1728
if path_or_url .startswith ("https://" ):
1776
- if TRACE :
1729
+ if TRACE_DEEP :
1777
1730
print (f"Fetching: { path_or_url } " )
1778
1731
_headers , content = get_remote_file_content (
1779
1732
url = path_or_url ,
@@ -1839,13 +1792,11 @@ def get_remote_file_content(
1839
1792
if verbose :
1840
1793
echo_func (f"DOWNLOADING: { url } " )
1841
1794
1842
- # if credentials and not change_auth:
1843
- # auth = HTTPUrlAuth(credentials.get("login"), credentials.get("password"))
1844
- # elif credentials and change_auth:
1845
- # auth = HTTPBasicAuth(credentials.get("login"), credentials.get("password"))
1795
+ if TRACE :
1796
+ print (f"DOWNLOADING: { url } " )
1846
1797
1847
1798
if credentials :
1848
- auth = HTTPBasicAuth (credentials .get ("login" ), credentials .get ("password" ))
1799
+ auth = (credentials .get ("login" ), credentials .get ("password" ))
1849
1800
else :
1850
1801
auth = None
1851
1802
@@ -1859,15 +1810,8 @@ def get_remote_file_content(
1859
1810
1860
1811
with stream as response :
1861
1812
status = response .status_code
1862
- if TRACE :
1863
- print (f"The status is { status } " )
1864
- print (f"The full response is: { response } " )
1865
- print (f"The response url is: { response .url } " )
1866
- # print(f"The original prepared request headers are: {response.request.headers}")
1867
1813
if status != requests .codes .ok : # NOQA
1868
1814
if status == 429 and _delay < 20 :
1869
- if TRACE :
1870
- print ("Delay exponentially..." )
1871
1815
# too many requests: start some exponential delay
1872
1816
increased_delay = (_delay * 2 ) or 1
1873
1817
@@ -1903,8 +1847,6 @@ def fetch_and_save(
1903
1847
errors. Treats the content as text if as_text is True otherwise as treat as
1904
1848
binary.
1905
1849
"""
1906
- if TRACE :
1907
- print (f"fetch_and_save() => { path_or_url = } " )
1908
1850
content = CACHE .get (
1909
1851
path_or_url = path_or_url ,
1910
1852
credentials = credentials ,
0 commit comments