From ea9ab89829fe8db6f89ef002dc9223a9e1d52186 Mon Sep 17 00:00:00 2001 From: Maksim Malchuk Date: Fri, 5 Apr 2019 09:47:40 +0300 Subject: [PATCH] Move pypi to dib-python The latest Fedora/Ubuntu images don't ship python2 by default, so we need to use our dib-python wrapper for this so we work in python3 only environments. This change also correctly creates the pip.conf and .pydistutils.cfg files with trusted host extracted from the index-url. Related-bug: 1577105 Change-Id: Ibb5348af3e3bbe46b19affe90a8930a4b4ad4cad Signed-off-by: Maksim Malchuk --- diskimage_builder/elements/pypi/element-deps | 1 + ...00-configure-pypi-mirror => 04-configure-pypi-mirror} | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 diskimage_builder/elements/pypi/element-deps rename diskimage_builder/elements/pypi/pre-install.d/{00-configure-pypi-mirror => 04-configure-pypi-mirror} (90%) diff --git a/diskimage_builder/elements/pypi/element-deps b/diskimage_builder/elements/pypi/element-deps new file mode 100644 index 00000000..f9eb801e --- /dev/null +++ b/diskimage_builder/elements/pypi/element-deps @@ -0,0 +1 @@ +dib-python diff --git a/diskimage_builder/elements/pypi/pre-install.d/00-configure-pypi-mirror b/diskimage_builder/elements/pypi/pre-install.d/04-configure-pypi-mirror similarity index 90% rename from diskimage_builder/elements/pypi/pre-install.d/00-configure-pypi-mirror rename to diskimage_builder/elements/pypi/pre-install.d/04-configure-pypi-mirror index fc177a8f..9ad74c45 100755 --- a/diskimage_builder/elements/pypi/pre-install.d/00-configure-pypi-mirror +++ b/diskimage_builder/elements/pypi/pre-install.d/04-configure-pypi-mirror @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/local/bin/dib-python # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -16,6 +16,11 @@ from __future__ import print_function import os.path +try: + from urllib.parse import urlparse +except ImportError: + from urlparse import urlparse + def main(): home = os.path.expanduser("~") @@ -49,6 +54,7 @@ def main(): output.write('[global]\n') output.write('log = %s/pip.log\n' % (home,)) output.write('index-url = %s\n' % (indices[0],)) + output.write('trusted-host = %s\n' % (urlparse(indices[0]).hostname,)) if retries is not None: output.write('retries = %s\n' % retries) for index in indices[1:]: @@ -56,6 +62,7 @@ def main(): with open(home + '/.pydistutils.cfg', 'wt') as output: output.write('[easy_install]\n') output.write('index_url = %s\n' % (easy_index,)) + output.write('allow_hosts = %s\n' % (urlparse(easy_index).netloc,)) def backup_configs(home):