summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorParide Legovini <paride.legovini@canonical.com>2020-05-02 02:57:24 +0200
committerGitHub <noreply@github.com>2020-05-01 18:57:24 -0600
commit4d2684848722cb2d469ad4fa60999bf81cf7056e (patch)
tree2246e875479392fb7e38ee16bbe0815df7d89308 /tools
parent70dbccbbb27f7cc3f2decd692d41403f0d745c62 (diff)
downloadvyos-cloud-init-4d2684848722cb2d469ad4fa60999bf81cf7056e.tar.gz
vyos-cloud-init-4d2684848722cb2d469ad4fa60999bf81cf7056e.zip
Adapt the package building scripts to use Python 3 (#231)
Since upstream cloud-init has dropped python2 support, adapt remaining package build scripts and tools to python3 only Changes: * Do not template debian/rules as python3 is the only supported version * Drop six from requirements.txt * Makefile: drop everything related to Python 2 * run-container: install the CI deps only on ubuntu|debian * read-version: update the shebang to use Python 3 * brpm: read_dependencies(): drop unused argument * read-dependencies: switch to Py3 and drop the --python-version option * pkg-deps.json: drop the Python version field and update the redhat deps * pkg-deps.json: drop the unittest2 and contextlib2 renames * Update RPM the spec file to use Python 3 when building the RPM * bddeb: drop support for Python 2
Diffstat (limited to 'tools')
-rwxr-xr-xtools/read-dependencies32
-rwxr-xr-xtools/run-container5
-rwxr-xr-xtools/run-pyflakes3
-rwxr-xr-xtools/run-pyflakes32
4 files changed, 14 insertions, 28 deletions
diff --git a/tools/read-dependencies b/tools/read-dependencies
index 75d08a34..666e24f5 100755
--- a/tools/read-dependencies
+++ b/tools/read-dependencies
@@ -9,7 +9,7 @@ try:
from argparse import ArgumentParser
except ImportError:
raise RuntimeError(
- 'Could not import python-argparse. Please install python-argparse '
+ 'Could not import argparse. Please install python3-argparse '
'package to continue')
import json
@@ -73,8 +73,8 @@ DISTRO_INSTALL_PKG_CMD = {
# List of base system packages required to enable ci automation
CI_SYSTEM_BASE_PKGS = {
'common': ['make', 'sudo', 'tar'],
- 'redhat': ['python-tox'],
- 'centos': ['python-tox'],
+ 'redhat': ['python3-tox'],
+ 'centos': ['python3-tox'],
'ubuntu': ['devscripts', 'python3-dev', 'libssl-dev', 'tox', 'sbuild'],
'debian': ['devscripts', 'python3-dev', 'libssl-dev', 'tox', 'sbuild']}
@@ -99,7 +99,7 @@ def get_parser():
parser.add_argument(
'-s', '--system-pkg-names', action='store_true', default=False,
dest='system_pkg_names',
- help='The name of the distro to generate package deps for.')
+ help='Generate distribution package names (python3-pkgname).')
parser.add_argument(
'-i', '--install', action='store_true', default=False,
dest='install',
@@ -109,12 +109,6 @@ def get_parser():
dest='test_distro',
help='Additionally install continuous integration system packages '
'required for build and test automation.')
- parser.add_argument(
- '-v', '--python-version', type=str, dest='python_version',
- default=None, choices=["2", "3"],
- help='Override the version of python we want to generate system '
- 'package dependencies for. Defaults to the version of python '
- 'this script is called with')
return parser
@@ -132,6 +126,9 @@ def get_package_deps_from_json(topdir, distro):
deps = json.loads(stream.read())
if distro is None:
return {}
+ if deps.get(distro): # If we have a specific distro defined, use it.
+ return deps[distro]
+ # Use generic distro dependency map via DISTRO_PKG_TYPE_MAP
return deps[DISTRO_PKG_TYPE_MAP[distro]]
@@ -155,27 +152,20 @@ def parse_pip_requirements(requirements_path):
return dep_names
-def translate_pip_to_system_pkg(pip_requires, renames, python_ver):
+def translate_pip_to_system_pkg(pip_requires, renames):
"""Translate pip package names to distro-specific package names.
@param pip_requires: List of versionless pip package names to translate.
@param renames: Dict containg special case renames from pip name to system
package name for the distro.
- @param python_ver: Optional python version string "2" or "3". When None,
- use the python version that is calling this script via sys.version_info.
"""
- if python_ver is None:
- python_ver = str(sys.version_info[0])
- if python_ver == "2":
- prefix = "python-"
- else:
- prefix = "python3-"
+ prefix = "python3-"
standard_pkg_name = "{0}{1}"
translated_names = []
for pip_name in pip_requires:
pip_name = pip_name.lower()
# Find a rename if present for the distro package and python version
- rename = renames.get(pip_name, {}).get(python_ver, None)
+ rename = renames.get(pip_name, "")
if rename:
translated_names.append(rename)
else:
@@ -222,7 +212,7 @@ def main(distro):
deps_from_json = get_package_deps_from_json(topd, args.distro)
renames = deps_from_json.get('renames', {})
translated_pip_names = translate_pip_to_system_pkg(
- pip_pkg_names, renames, args.python_version)
+ pip_pkg_names, renames)
all_deps = []
if args.distro:
all_deps.extend(
diff --git a/tools/run-container b/tools/run-container
index a7a552ec..7212550e 100755
--- a/tools/run-container
+++ b/tools/run-container
@@ -463,9 +463,8 @@ main() {
return
}
- inside_as_cd "$name" root "$cdir" \
- python3 ./tools/read-dependencies "--distro=${OS_NAME}" \
- --test-distro || {
+ local rdcmd=(python3 tools/read-dependencies "--distro=${OS_NAME}" --install --test-distro)
+ inside_as_cd "$name" root "$cdir" "${rdcmd[@]}" || {
errorrc "FAIL: failed to install dependencies with read-dependencies"
return
}
diff --git a/tools/run-pyflakes b/tools/run-pyflakes
index b3759a94..179afebe 100755
--- a/tools/run-pyflakes
+++ b/tools/run-pyflakes
@@ -1,6 +1,5 @@
#!/bin/bash
-PYTHON_VERSION=${PYTHON_VERSION:-2}
CR="
"
pycheck_dirs=( "cloudinit/" "tests/" "tools/" )
@@ -12,7 +11,7 @@ else
files=( "$@" )
fi
-cmd=( "python${PYTHON_VERSION}" -m "pyflakes" "${files[@]}" )
+cmd=( "python3" -m "pyflakes" "${files[@]}" )
echo "Running: " "${cmd[@]}" 1>&2
exec "${cmd[@]}"
diff --git a/tools/run-pyflakes3 b/tools/run-pyflakes3
deleted file mode 100755
index e9f0863d..00000000
--- a/tools/run-pyflakes3
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-PYTHON_VERSION=3 exec "${0%/*}/run-pyflakes" "$@"