From 8f176479c0282e564a87036704c515f746aab3a9 Mon Sep 17 00:00:00 2001
From: Chad Smith <chad.smith@canonical.com>
Date: Mon, 24 Apr 2017 17:57:04 +0000
Subject: make deb: Add devscripts dependency for make deb. Cleanup
 packages/bddeb.

Add a simple dependency check to "make deb" target for devscripts. Rework
a bit of the logic in package/bddeb to drop superfluous STD_NAMED_PACKAGES
to avoid duplication of requirements already listed in
(test-)?requiremets.txt. All "standard" packages can be assumed to have
either python3- or python- prefix if not listed in NONSTD_NAMED_PACKAGES.
This branch also moves logic inside write_debian_folder which is unneeded
up in main.

LP: #1685935
---
 packages/bddeb | 100 +++++++++++++++++++++------------------------------------
 1 file changed, 36 insertions(+), 64 deletions(-)

(limited to 'packages')

diff --git a/packages/bddeb b/packages/bddeb
index 79ac9768..f415209f 100755
--- a/packages/bddeb
+++ b/packages/bddeb
@@ -24,35 +24,17 @@ if "avoid-pep8-E402-import-not-top-of-file":
     from cloudinit import templater
     from cloudinit import util
 
-# Package names that will showup in requires to what we can actually
-# use in our debian 'control' file, this is a translation of the 'requires'
-# file pypi package name to a debian/ubuntu package name.
-STD_NAMED_PACKAGES = [
-    'configobj',
-    'coverage',
-    'jinja2',
-    'jsonpatch',
-    'oauthlib',
-    'prettytable',
-    'requests',
-    'six',
-    'httpretty',
-    'mock',
-    'nose',
-    'setuptools',
-    'flake8',
-    'hacking',
-    'unittest2',
-]
+# Package names that will showup in requires which have unique package names.
+# Format is '<pypi-name>': {'<python_major_version>': <pkg_name_or_none>, ...}.
 NONSTD_NAMED_PACKAGES = {
-    'argparse': ('python-argparse', None),
-    'contextlib2': ('python-contextlib2', None),
-    'cheetah': ('python-cheetah', None),
-    'pyserial': ('python-serial', 'python3-serial'),
-    'pyyaml': ('python-yaml', 'python3-yaml'),
-    'six': ('python-six', 'python3-six'),
-    'pep8': ('pep8', 'python3-pep8'),
-    'pyflakes': ('pyflakes', 'pyflakes'),
+    'argparse': {'2': 'python-argparse', '3': None},
+    'contextlib2': {'2': 'python-contextlib2', '3': None},
+    'cheetah': {'2': 'python-cheetah', '3': None},
+    'pyserial': {'2': 'python-serial', '3': 'python3-serial'},
+    'pyyaml': {'2': 'python-yaml', '3': 'python3-yaml'},
+    'six': {'2': 'python-six', '3': 'python3-six'},
+    'pep8': {'2': 'pep8', '3': 'python3-pep8'},
+    'pyflakes': {'2': 'pyflakes', '3': 'pyflakes'},
 }
 
 DEBUILD_ARGS = ["-S", "-d"]
@@ -68,8 +50,17 @@ def run_helper(helper, args=None, strip=True):
     return stdout
 
 
-def write_debian_folder(root, templ_data, pkgmap, pyver="3",
-                        append_requires=[]):
+def write_debian_folder(root, templ_data, is_python2, cloud_util_deps):
+    """Create a debian package directory with all rendered template files."""
+    print("Creating a debian/ folder in %r" % (root))
+    if is_python2:
+        pyver = "2"
+        python = "python"
+    else:
+        pyver = "3"
+        python = "python3"
+    pkgfmt = "{}-{}"
+
     deb_dir = util.abs_join(root, 'debian')
 
     # Just copy debian/ dir and then update files
@@ -91,21 +82,16 @@ def write_debian_folder(root, templ_data, pkgmap, pyver="3",
     pypi_test_pkgs = [p.lower().strip() for p in test_reqs]
 
     # Map to known packages
-    requires = append_requires
+    requires = ['cloud-utils | cloud-guest-utils'] if cloud_util_deps else []
     test_requires = []
     lists = ((pypi_pkgs, requires), (pypi_test_pkgs, test_requires))
     for pypilist, target in lists:
         for p in pypilist:
-            if p not in pkgmap:
-                raise RuntimeError(("Do not know how to translate pypi "
-                                    "dependency %r to a known package") % (p))
-            elif pkgmap[p]:
-                target.append(pkgmap[p])
-
-    if pyver == "3":
-        python = "python3"
-    else:
-        python = "python"
+            if p in NONSTD_NAMED_PACKAGES:
+                if NONSTD_NAMED_PACKAGES[p][pyver]:
+                    target.append(NONSTD_NAMED_PACKAGES[p][pyver])
+            else:  # Then standard package prefix
+                target.append(pkgfmt.format(python, p))
 
     templater.render_to_file(util.abs_join(find_root(),
                                            'packages', 'debian', 'control.in'),
@@ -124,8 +110,8 @@ def read_version():
     return json.loads(run_helper('read-version', ['--json']))
 
 
-def main():
-
+def get_parser():
+    """Setup and return an argument parser for bdeb tool."""
     parser = argparse.ArgumentParser()
     parser.add_argument("-v", "--verbose", dest="verbose",
                         help=("run verbosely"
@@ -162,7 +148,11 @@ def main():
 
     parser.add_argument("--signuser", default=False, action='store',
                         help="user to sign, see man dpkg-genchanges")
+    return parser
+
 
+def main():
+    parser = get_parser()
     args = parser.parse_args()
 
     if not args.sign:
@@ -177,18 +167,6 @@ def main():
     if args.verbose:
         capture = False
 
-    pkgmap = {}
-    for p in NONSTD_NAMED_PACKAGES:
-        pkgmap[p] = NONSTD_NAMED_PACKAGES[p][int(not args.python2)]
-
-    for p in STD_NAMED_PACKAGES:
-        if args.python2:
-            pkgmap[p] = "python-" + p
-            pyver = "2"
-        else:
-            pkgmap[p] = "python3-" + p
-            pyver = "3"
-
     templ_data = {'debian_release': args.release}
     with util.tempdir() as tdir:
 
@@ -208,16 +186,10 @@ def main():
         util.subp(cmd, capture=capture)
 
         xdir = util.abs_join(tdir, "cloud-init-%s" % ver_data['version_long'])
-
-        print("Creating a debian/ folder in %r" % (xdir))
-        if args.cloud_utils:
-            append_requires = ['cloud-utils | cloud-guest-utils']
-        else:
-            append_requires = []
-
         templ_data.update(ver_data)
-        write_debian_folder(xdir, templ_data, pkgmap,
-                            pyver=pyver, append_requires=append_requires)
+
+        write_debian_folder(xdir, templ_data, is_python2=args.python2,
+                            cloud_util_deps=args.cloud_utils)
 
         print("Running 'debuild %s' in %r" % (' '.join(args.debuild_args),
                                               xdir))
-- 
cgit v1.2.3


From 6b5369be71054a677b89fa8080f7ddd029ce4986 Mon Sep 17 00:00:00 2001
From: Scott Moser <smoser@brickies.net>
Date: Wed, 24 May 2017 09:36:57 -0400
Subject: tox/build: do not package depend on style requirements.

When the style/checking dependencies were updated in
test-requirements.txt, the debian package build dependencies created
by ./packages/bddeb were also updated.  Pycodestyle was added to the list
in order to pin its version.  That broke the package build for 16.04.  The
reason for this is simply that python3-pycodestyle is not available in
16.04.

The change here is to remove style dependencies from test-requirements,
and add them to the tox environments directly.  We had previously changed
the package build process to not run pep8 or flake8 simply to avoid having
to code to N different versions of style checkers (3bcb72c593f).

The link between package build and test-requirements still exists, though.
So future breakage can occur if any package is added to
test-requirements.txt (or requirements.txt) if the target distro release
does not have a python3-<packagename> in its archive.

There is also a bit of a tox.ini cleanup here, in that we do not have to
explictly list '-rrequirements.txt' as the setup.py pulls those in.  And
lastly, we drop the -rtest-requirements.txt from the base 'testenv', and
add these test requirements only to environments that need to run test.

Finally, a change to packages/debian/control.in to drop the build
dependencies that were listed for style checking and also a dependency
on iproute2 which was a bad unit test that has been previously fixed.
---
 packages/debian/control.in |  4 ----
 test-requirements.txt      |  6 ------
 tox.ini                    | 20 ++++++++++++--------
 3 files changed, 12 insertions(+), 18 deletions(-)

(limited to 'packages')

diff --git a/packages/debian/control.in b/packages/debian/control.in
index b58561e7..6c39d531 100644
--- a/packages/debian/control.in
+++ b/packages/debian/control.in
@@ -6,10 +6,6 @@ Maintainer: Scott Moser <smoser@ubuntu.com>
 Build-Depends: debhelper (>= 9),
                dh-python,
                dh-systemd,
-               iproute2,
-               pep8,
-               pyflakes,
-               python3-pyflakes | pyflakes (<< 1.1.0-2),
                ${python},
                ${test_requires},
                ${requires}
diff --git a/test-requirements.txt b/test-requirements.txt
index 1b39ea5c..d9d41b57 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -11,9 +11,3 @@ coverage
 # Only really needed on older versions of python
 contextlib2
 setuptools
-
-# Used for syle checking
-pycodestyle==2.3.1
-pyflakes==1.5.0
-flake8==3.3.0
-hacking==0.13.0
diff --git a/tox.ini b/tox.ini
index 03bb5f19..6276662d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -4,13 +4,16 @@ recreate = True
 
 [testenv]
 commands = python -m nose {posargs:tests/unittests}
-deps = -r{toxinidir}/test-requirements.txt
-       -r{toxinidir}/requirements.txt
 setenv =
     LC_ALL = en_US.utf-8
 
 [testenv:flake8]
 basepython = python3
+deps =
+    pycodestyle==2.3.1
+    pyflakes==1.5.0
+    flake8==3.3.0
+    hacking==0.13.0
 commands = {envpython} -m flake8 {posargs:cloudinit/ tests/ tools/}
 
 # https://github.com/gabrielfalcao/HTTPretty/issues/223
@@ -23,11 +26,17 @@ commands = {envpython} -m pylint {posargs:cloudinit}
 
 [testenv:py3]
 basepython = python3
+deps = -r{toxinidir}/test-requirements.txt
 commands = {envpython} -m nose {posargs:--with-coverage \
            --cover-erase --cover-branches --cover-inclusive \
            --cover-package=cloudinit tests/unittests}
 
+[testenv:py27]
+basepython = python2.7
+deps = -r{toxinidir}/test-requirements.txt
+
 [testenv:py26]
+deps = -r{toxinidir}/test-requirements.txt
 commands = nosetests {posargs:tests/unittests}
 setenv =
     LC_ALL = C
@@ -39,8 +48,7 @@ exclude = .venv,.tox,dist,doc,*egg,.git,build,tools
 
 [testenv:doc]
 basepython = python3
-deps = {[testenv]deps}
-       sphinx
+deps = sphinx
 commands = {envpython} -m sphinx {posargs:doc/rtd doc/rtd_html}
 
 [testenv:xenial]
@@ -63,10 +71,6 @@ deps =
     nose==1.3.7
     unittest2==1.1.0
     contextlib2==0.5.1
-    pep8==1.7.0
-    pyflakes==1.1.0
-    flake8==2.5.4
-    hacking==0.10.2
 
 [testenv:centos6]
 basepython = python2.6
-- 
cgit v1.2.3