summaryrefslogtreecommitdiff
path: root/tools/upip.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-05-15 15:46:16 +1000
committerDamien George <damien.p.george@gmail.com>2019-05-15 15:46:16 +1000
commit993ca572ca122811e93167617625afd0b3a5d751 (patch)
tree0253d2f6966335769263865d5b36ec8f89f647b6 /tools/upip.py
parenta474ddf959fab641ab65631a8e140cf5bbda2541 (diff)
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.
Diffstat (limited to 'tools/upip.py')
-rw-r--r--tools/upip.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/tools/upip.py b/tools/upip.py
index 7ecf61e54..e3b888516 100644
--- a/tools/upip.py
+++ b/tools/upip.py
@@ -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: