Remove dependency on pkg_resources

Fixes issue that breaks execution on systems with older setuptools.

Change-Id: I3f86b038872ad868cea659ccfd89e87c450fbf46
This commit is contained in:
Sorin Sbarnea 2020-08-28 19:45:31 +01:00 committed by Sorin Sbarnea (zbr)
parent 8fb0751ddc
commit 0716fa10dc
2 changed files with 15 additions and 5 deletions

View File

@ -52,7 +52,6 @@ try:
except ImportError: except ImportError:
import ConfigParser as configparser import ConfigParser as configparser
import pkg_resources as prAPI
import os import os
import ast import ast
import subprocess import subprocess
@ -64,6 +63,16 @@ from ansible.module_utils.basic import AnsibleModule
log = list() 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): def get_sibling_python_packages(projects, tox_python):
'''Finds all python packages that zuul has cloned. '''Finds all python packages that zuul has cloned.
@ -157,7 +166,7 @@ def _get_package_root(name, sibling_packages):
try: try:
pkg_root = sibling_packages[name] pkg_root = sibling_packages[name]
except KeyError: except KeyError:
pkg_root = sibling_packages[prAPI.to_filename(name)] pkg_root = sibling_packages[to_filename(name)]
return pkg_root return pkg_root
@ -169,7 +178,7 @@ def find_installed_siblings(tox_python, package_name, sibling_python_packages):
"Found {name} python package installed".format( "Found {name} python package installed".format(
name=dep_name)) name=dep_name))
if (dep_name == package_name or 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 don't need to re-process ourself.
# We've filtered ourselves from the source dir list, # We've filtered ourselves from the source dir list,
# but let's be sure nothing is weird. # 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, name=dep_name,
root=sibling_python_packages[dep_name])) root=sibling_python_packages[dep_name]))
installed_sibling_packages.append(dep_name) installed_sibling_packages.append(dep_name)
elif prAPI.to_filename(dep_name) in sibling_python_packages: elif to_filename(dep_name) in sibling_python_packages:
real_name = prAPI.to_filename(dep_name) real_name = to_filename(dep_name)
log.append( log.append(
"Package {name} ({pkg_name}) on system in {root}".format( "Package {name} ({pkg_name}) on system in {root}".format(
name=dep_name, name=dep_name,

View File

@ -239,6 +239,7 @@
success-url: docs/ success-url: docs/
files: files:
- roles/fetch-sphinx-tarball/.* - roles/fetch-sphinx-tarball/.*
- roles/tox/library/.*
tags: all-platforms tags: all-platforms
- job: - job: