tools/upip.py: Add support for multiple index URLs with custom default.
The user can now select their own package index by either passing the "-i" command line option, or setting the upip.index_urls variable (before doing an install). The https://micropython.org/pi package index hosts packages from micropython-lib and will be searched first when installing a package. If a package is not found here then it will fallback to PyPI.
This commit is contained in:
parent
a474ddf959
commit
993ca572ca
|
@ -16,6 +16,7 @@ gc.collect()
|
|||
|
||||
|
||||
debug = False
|
||||
index_urls = ["https://micropython.org/pi", "https://pypi.org/pypi"]
|
||||
install_path = None
|
||||
cleanup_files = []
|
||||
gzdict_sz = 16 + 15
|
||||
|
@ -156,11 +157,16 @@ def url_open(url):
|
|||
|
||||
|
||||
def get_pkg_metadata(name):
|
||||
f = url_open("https://pypi.org/pypi/%s/json" % name)
|
||||
try:
|
||||
return json.load(f)
|
||||
finally:
|
||||
f.close()
|
||||
for url in index_urls:
|
||||
try:
|
||||
f = url_open("%s/%s/json" % (url, name))
|
||||
except NotFoundError:
|
||||
continue
|
||||
try:
|
||||
return json.load(f)
|
||||
finally:
|
||||
f.close()
|
||||
raise NotFoundError("Package not found")
|
||||
|
||||
|
||||
def fatal(msg, exc=None):
|
||||
|
@ -261,6 +267,7 @@ for installation, upip does not support arbitrary code in setup.py.
|
|||
|
||||
def main():
|
||||
global debug
|
||||
global index_urls
|
||||
global install_path
|
||||
install_path = None
|
||||
|
||||
|
@ -294,6 +301,9 @@ def main():
|
|||
if l[0] == "#":
|
||||
continue
|
||||
to_install.append(l.rstrip())
|
||||
elif opt == "-i":
|
||||
index_urls = [sys.argv[i]]
|
||||
i += 1
|
||||
elif opt == "--debug":
|
||||
debug = True
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue