From 47a6633a3101e059e9cf596f4860161b676bba1a Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 9 Oct 2016 02:12:31 +0300 Subject: [PATCH] upip: Don't parse MICROPYPATH, just use sys.path[1] as set by micropython. Makes POSIX and baremetal behavior simpler and more consistent. --- upip/upip.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/upip/upip.py b/upip/upip.py index 76e16ee6..6fece235 100644 --- a/upip/upip.py +++ b/upip/upip.py @@ -6,8 +6,6 @@ import uzlib import upip_utarfile as tarfile -DEFAULT_MICROPYPATH = "~/.micropython/lib:/usr/lib/micropython" - debug = False install_path = None cleanup_files = [] @@ -192,12 +190,8 @@ def install(to_install, install_path=None): def get_install_path(): global install_path if install_path is None: - if hasattr(os, "getenv"): - install_path = os.getenv("MICROPYPATH") - if install_path is None: - # sys.path[0] is current module's path - install_path = sys.path[1] - install_path = install_path.split(":", 1)[0] + # sys.path[0] is current module's path + install_path = sys.path[1] install_path = expandhome(install_path) return install_path @@ -213,11 +207,15 @@ def help(): upip - Simple PyPI package manager for MicroPython Usage: micropython -m upip install [-p ] ... | -r -If -p is not given, packages will be installed to first path component of -MICROPYPATH, or to ~/.micropython/lib/ by default. -Note: only MicroPython packages (usually, micropython-*) are supported for -installation, upip does not support arbitrary code in setup.py.""") - sys.exit(1) +If is not given, packages will be installed into sys.path[1] +(can be set from MICROPYPATH environment variable, if current system +supports that).""") + print("Current value of sys.path[1]:", sys.path[1]) + print("""\ + +Note: only MicroPython packages (usually, named micropython-*) are supported +for installation, upip does not support arbitrary code in setup.py. +""") def main(): global debug @@ -226,6 +224,7 @@ def main(): if len(sys.argv) < 2 or sys.argv[1] == "-h" or sys.argv[1] == "--help": help() + return if sys.argv[1] != "install": fatal("Only 'install' command supported") @@ -238,6 +237,7 @@ def main(): i += 1 if opt == "-h" or opt == "--help": help() + return elif opt == "-p": install_path = sys.argv[i] i += 1 @@ -258,6 +258,7 @@ def main(): to_install.extend(sys.argv[i:]) if not to_install: help() + return install(to_install)