From 76ddfc439fab813e8bdc397297f30e0494222ff2 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Thu, 5 Feb 2015 16:30:25 -0800 Subject: [PATCH] Namespace PYPI_MIRROR_URL vars with DIB We have a good pattern of namespacing env vars with DIB_. Add support for DIB_PYPI_MIRROR_URL* and maintain backwards compat support. Change-Id: I434c9d1b14cd571b20754c9ad7cd64c936f8399a --- elements/pypi/README.rst | 24 +++++++++---------- .../pre-install.d/00-configure-pypi-mirror | 12 ++++++++-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/elements/pypi/README.rst b/elements/pypi/README.rst index 468972a5a..e0dfc17f8 100644 --- a/elements/pypi/README.rst +++ b/elements/pypi/README.rst @@ -16,18 +16,18 @@ To disable the pypi.python.org index without using --offline (e.g. when working behind a corporate firewall that prohibits pypi.python.org) set DIB\_NO\_PYPI\_PIP to any non-empty value. -To use an arbitrary mirror set PYPI\_MIRROR\_URL=http[s]://somevalue/ +To use an arbitrary mirror set DIB\_PYPI\_MIRROR\_URL=http[s]://somevalue/ -Additional mirrors can be added by exporting PYPI\_MIRROR\_URL\_1=... etc. Only -the one mirror can be used by easy-install, but since wheels need to be in the -first mirror to be used, the last listed mirror is used as the pydistutils -index. NB: The sort order for these variables is a simple string sort - if -you have more than 9 additional mirrors, some care will be needed. +Additional mirrors can be added by exporting DIB\_PYPI\_MIRROR\_URL\_1=... etc. +Only the one mirror can be used by easy-install, but since wheels need to be in +the first mirror to be used, the last listed mirror is used as the pydistutils +index. NB: The sort order for these variables is a simple string sort - if you +have more than 9 additional mirrors, some care will be needed. A typical use of this element is thus: -export PYPI\_MIRROR\_URL=http://site/pypi/Ubuntu-13.10 -export PYPI\_MIRROR\_URL\_1=http://site/pypi/ -export PYPI\_MIRROR\_URL\_2=file:///tmp/pypi +export DIB\_PYPI\_MIRROR\_URL=http://site/pypi/Ubuntu-13.10 +export DIB\_PYPI\_MIRROR\_URL\_1=http://site/pypi/ +export DIB\_PYPI\_MIRROR\_URL\_2=file:///tmp/pypi [devpi-server](https://git.openstack.org/cgit/openstack-infra/pypi-mirro://pypi.python.org/pypi/devpi-server) can be useful in making a partial PyPI mirror suitable for building images. For @@ -41,9 +41,9 @@ instance: * Re-export your variables to point at the new mirror: - export PYPI\_MIRROR\_URL=http://machinename:3141/ - unset PYPI\__MIRROR\_URL\_1 - unset PYPI\__MIRROR\_URL\_1 + export DIB\_PYPI\_MIRROR\_URL=http://machinename:3141/ + unset DIB\_PYPI\__MIRROR\_URL\_1 + unset DIB\_PYPI\__MIRROR\_URL\_2 The next time packages are installed, they'll be cached on the local devpi server; subsequent runs pointed at the same mirror will use the local cache if diff --git a/elements/pypi/pre-install.d/00-configure-pypi-mirror b/elements/pypi/pre-install.d/00-configure-pypi-mirror index 1a217b7cb..c1d3b55bc 100755 --- a/elements/pypi/pre-install.d/00-configure-pypi-mirror +++ b/elements/pypi/pre-install.d/00-configure-pypi-mirror @@ -21,8 +21,16 @@ def main(): home = os.path.expanduser("~") backup_configs(home) indices = [] - if os.environ.get('PYPI_MIRROR_URL'): - candidates = [k for k in os.environ if k.startswith('PYPI_MIRROR_URL')] + if (os.environ.get('DIB_PYPI_MIRROR_URL') or + os.environ.get('PYPI_MIRROR_URL')): + candidates = [k for k in os.environ if + k.startswith('DIB_PYPI_MIRROR_URL')] + back_compat = [k for k in os.environ if + k.startswith('PYPI_MIRROR_URL')] + if len(back_compat) > 0: + print('DEPRECATION WARNING: Please use DIB_PYPI_MIRROR_URL* rather' + ' than PYPI_MIRROR_URL*') + candidates += back_compat indices = list(map(os.environ.get, sorted(candidates))) else: indices = ['file:///tmp/pypi']