Skip to content

Commit 056a825

Browse files
committed
Fix 180: check for base_url_parts and give wheel its repo credentials
Signed-off-by: Cesar Lizarraga <[email protected]> Fix 180: Add env var for netrc file
1 parent d930547 commit 056a825

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/python_inspector/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def resolve_dependencies(
146146

147147
files = []
148148

149-
# if PYPI_SIMPLE_URL not in index_urls:
150-
# index_urls = tuple(index_urls) + tuple([PYPI_SIMPLE_URL])
149+
if PYPI_SIMPLE_URL not in index_urls:
150+
index_urls = tuple(index_urls) + tuple([PYPI_SIMPLE_URL])
151151

152152
# requirements
153153
for req_file in requirement_files:

src/python_inspector/resolve_cli.py

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def print_version(ctx, param, value):
121121
"--netrc",
122122
"netrc_file",
123123
type=click.Path(exists=True, readable=True, path_type=str, dir_okay=False),
124+
envvar="PYINSP_NETRC_FILE",
124125
metavar="NETRC-FILE",
125126
hidden=True,
126127
required=False,
@@ -162,6 +163,7 @@ def print_version(ctx, param, value):
162163
)
163164
@click.option(
164165
"--verbose",
166+
envvar="PYINSP_VERBOSE",
165167
is_flag=True,
166168
help="Enable verbose debug output.",
167169
)

src/python_inspector/utils_pypi.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import shutil
1717
import tempfile
1818
import time
19+
1920
from collections import defaultdict
2021
from typing import List
2122
from typing import NamedTuple
@@ -27,6 +28,7 @@
2728
import attr
2829
import packageurl
2930
import requests
31+
3032
from bs4 import BeautifulSoup
3133
from commoncode import fileutils
3234
from commoncode.hash import multi_checksums
@@ -215,7 +217,6 @@ def get_python_dot_version(version):
215217
class DistributionNotFound(Exception):
216218
pass
217219

218-
219220
def download_wheel(
220221
name,
221222
version,
@@ -252,6 +253,7 @@ def download_wheel(
252253
)
253254
continue
254255
for wheel in supported_and_valid_wheels:
256+
wheel.credentials = repo.credentials
255257
fetched_wheel_filename = wheel.download(
256258
dest_dir=dest_dir,
257259
verbose=verbose,
@@ -1130,7 +1132,8 @@ def to_filename(self):
11301132
pyvers = ".".join(self.python_versions)
11311133
abis = ".".join(self.abis)
11321134
plats = ".".join(self.platforms)
1133-
return f"{self.name}-{self.version}{build}-{pyvers}-{abis}-{plats}.whl"
1135+
name = f"{self.name}-{self.version}{build}-{pyvers}-{abis}-{plats}.whl"
1136+
return name
11341137

11351138
def is_pure(self):
11361139
"""
@@ -1593,16 +1596,6 @@ def fetch_links(
15931596
name using the `index_url` of this repository.
15941597
"""
15951598
package_url = f"{self.index_url}/{normalized_name}"
1596-
if len(package_url) >= 256:
1597-
base64_re = re.compile(f"https://(.*:.*)@(.*){normalized_name}")
1598-
match = base64_re.search(self.index_url)
1599-
if match:
1600-
auth = match.group(1)
1601-
username = auth.split(":")[0]
1602-
token = auth,split(":")[1]
1603-
remainder = match.group(2)
1604-
new_index_url = f"https://{username}:{token}@{remainder}"
1605-
package_url = f"{new_index_url}/{normalized_name}"
16061599
text = CACHE.get(
16071600
path_or_url=package_url,
16081601
credentials=self.credentials,
@@ -1645,7 +1638,10 @@ def resolve_relative_url(package_url, url):
16451638
path = urlunparse(
16461639
("", "", url_parts.path, url_parts.params, url_parts.query, url_parts.fragment)
16471640
)
1648-
resolved_url_parts = base_url_parts._replace(path=path)
1641+
if base_url_parts.path != "":
1642+
resolved_url_parts = base_url_parts._replace(path=base_url_parts.path + "/" + path)
1643+
else:
1644+
resolved_url_parts = base_url_parts._replace(path=path)
16491645
url = urlunparse(resolved_url_parts)
16501646
return url
16511647

@@ -1688,6 +1684,8 @@ def get(
16881684
True otherwise as treat as binary. `path_or_url` can be a path or a URL
16891685
to a file.
16901686
"""
1687+
1688+
16911689
cache_key = quote_plus(path_or_url.strip("/"))
16921690
cached = os.path.join(self.directory, cache_key)
16931691

@@ -1792,21 +1790,25 @@ def get_remote_file_content(
17921790
if verbose:
17931791
echo_func(f"DOWNLOADING: {url}")
17941792

1795-
auth = None
1793+
if TRACE:
1794+
print(f"DOWNLOADING: {url}")
1795+
17961796
if credentials:
17971797
auth = (credentials.get("login"), credentials.get("password"))
1798+
else:
1799+
auth = None
17981800

17991801
stream = requests.get(
18001802
url,
18011803
allow_redirects=True,
18021804
stream=True,
18031805
headers=headers,
1804-
auth=auth,
1806+
auth=auth
18051807
)
18061808

18071809
with stream as response:
18081810
status = response.status_code
1809-
if status != requests.codes.ok: # NOQA
1811+
if status != requests.codes.ok: # NOQA
18101812
if status == 429 and _delay < 20:
18111813
# too many requests: start some exponential delay
18121814
increased_delay = (_delay * 2) or 1

0 commit comments

Comments
 (0)