Skip to content

Commit e8e8387

Browse files
committed
Issue 180: Fix not parsing pip.conf index urls
Signed-off-by: Cesar Lizarraga <[email protected]>
1 parent b4fa534 commit e8e8387

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/python_inspector/api.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#
1111

1212
import os
13+
import subprocess
1314
from netrc import netrc
1415
from typing import Dict
1516
from typing import List
@@ -71,6 +72,21 @@ def to_dict(self, generic_paths=False):
7172
"resolution": self.resolution,
7273
}
7374

75+
def pip_conf_get_index_urls() -> list:
76+
pip_index_url_cmd = "pip config get global.index-url"
77+
pip_extra_index_url_cmd = "pip config get global.extra-index-url"
78+
index_urls = subprocess.run(pip_index_url_cmd, capture_output=True)
79+
if index_urls.returncode != 0:
80+
index_urls = []
81+
else:
82+
index_urls = index_urls.stdout.decode("utf-8").split()
83+
extra_index_urls = subprocess.run(pip_extra_index_url_cmd, capture_output=True)
84+
if extra_index_urls.returncode != 0:
85+
extra_index_urls = []
86+
else:
87+
extra_index_urls = extra_index_urls.stdout.decode("utf-8").split()
88+
all_index_urls = [url for url in index_urls + extra_index_urls if url != ""]
89+
return all_index_urls
7490

7591
def resolve_dependencies(
7692
requirement_files=tuple(),
@@ -146,6 +162,11 @@ def resolve_dependencies(
146162

147163
files = []
148164

165+
pip_conf_index_urls = pip_conf_get_index_urls()
166+
167+
if pip_conf_index_urls != []:
168+
index_urls = tuple(pip_conf_index_urls) + tuple(index_urls)
169+
149170
if PYPI_SIMPLE_URL not in index_urls:
150171
index_urls = tuple([PYPI_SIMPLE_URL]) + tuple(index_urls)
151172

0 commit comments

Comments
 (0)