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
|
debug = False
|
||||||
|
index_urls = ["https://micropython.org/pi", "https://pypi.org/pypi"]
|
||||||
install_path = None
|
install_path = None
|
||||||
cleanup_files = []
|
cleanup_files = []
|
||||||
gzdict_sz = 16 + 15
|
gzdict_sz = 16 + 15
|
||||||
@ -156,11 +157,16 @@ def url_open(url):
|
|||||||
|
|
||||||
|
|
||||||
def get_pkg_metadata(name):
|
def get_pkg_metadata(name):
|
||||||
f = url_open("https://pypi.org/pypi/%s/json" % name)
|
for url in index_urls:
|
||||||
try:
|
try:
|
||||||
return json.load(f)
|
f = url_open("%s/%s/json" % (url, name))
|
||||||
finally:
|
except NotFoundError:
|
||||||
f.close()
|
continue
|
||||||
|
try:
|
||||||
|
return json.load(f)
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
|
raise NotFoundError("Package not found")
|
||||||
|
|
||||||
|
|
||||||
def fatal(msg, exc=None):
|
def fatal(msg, exc=None):
|
||||||
@ -261,6 +267,7 @@ for installation, upip does not support arbitrary code in setup.py.
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
global debug
|
global debug
|
||||||
|
global index_urls
|
||||||
global install_path
|
global install_path
|
||||||
install_path = None
|
install_path = None
|
||||||
|
|
||||||
@ -294,6 +301,9 @@ def main():
|
|||||||
if l[0] == "#":
|
if l[0] == "#":
|
||||||
continue
|
continue
|
||||||
to_install.append(l.rstrip())
|
to_install.append(l.rstrip())
|
||||||
|
elif opt == "-i":
|
||||||
|
index_urls = [sys.argv[i]]
|
||||||
|
i += 1
|
||||||
elif opt == "--debug":
|
elif opt == "--debug":
|
||||||
debug = True
|
debug = True
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user