From 0716fa10dcbf318dda1c223bfba9e2b93be737c9 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 28 Aug 2020 19:45:31 +0100 Subject: [PATCH] Remove dependency on pkg_resources Fixes issue that breaks execution on systems with older setuptools. Change-Id: I3f86b038872ad868cea659ccfd89e87c450fbf46 --- .../library/tox_install_sibling_packages.py | 19 ++++++++++++++----- zuul-tests.d/python-jobs.yaml | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/roles/tox/library/tox_install_sibling_packages.py b/roles/tox/library/tox_install_sibling_packages.py index 408f4e336..bb7319c6a 100644 --- a/roles/tox/library/tox_install_sibling_packages.py +++ b/roles/tox/library/tox_install_sibling_packages.py @@ -52,7 +52,6 @@ try: except ImportError: import ConfigParser as configparser -import pkg_resources as prAPI import os import ast import subprocess @@ -64,6 +63,16 @@ from ansible.module_utils.basic import AnsibleModule log = list() +def to_filename(name): + """Convert a project or version name to its filename-escaped form + Any '-' characters are currently replaced with '_'. + + Implementation vendored from pkg_resources.to_filename in order to avoid + adding an extra runtime dependency. + """ + return name.replace('-', '_') + + def get_sibling_python_packages(projects, tox_python): '''Finds all python packages that zuul has cloned. @@ -157,7 +166,7 @@ def _get_package_root(name, sibling_packages): try: pkg_root = sibling_packages[name] except KeyError: - pkg_root = sibling_packages[prAPI.to_filename(name)] + pkg_root = sibling_packages[to_filename(name)] return pkg_root @@ -169,7 +178,7 @@ def find_installed_siblings(tox_python, package_name, sibling_python_packages): "Found {name} python package installed".format( name=dep_name)) if (dep_name == package_name or - prAPI.to_filename(dep_name) == package_name): + to_filename(dep_name) == package_name): # We don't need to re-process ourself. # We've filtered ourselves from the source dir list, # but let's be sure nothing is weird. @@ -183,8 +192,8 @@ def find_installed_siblings(tox_python, package_name, sibling_python_packages): name=dep_name, root=sibling_python_packages[dep_name])) installed_sibling_packages.append(dep_name) - elif prAPI.to_filename(dep_name) in sibling_python_packages: - real_name = prAPI.to_filename(dep_name) + elif to_filename(dep_name) in sibling_python_packages: + real_name = to_filename(dep_name) log.append( "Package {name} ({pkg_name}) on system in {root}".format( name=dep_name, diff --git a/zuul-tests.d/python-jobs.yaml b/zuul-tests.d/python-jobs.yaml index cb5173d2d..7e5caaa57 100644 --- a/zuul-tests.d/python-jobs.yaml +++ b/zuul-tests.d/python-jobs.yaml @@ -239,6 +239,7 @@ success-url: docs/ files: - roles/fetch-sphinx-tarball/.* + - roles/tox/library/.* tags: all-platforms - job: