From 1597d7956a0da68161f2e75932045648b8f7f66a Mon Sep 17 00:00:00 2001 From: Paul Morgan Date: Sat, 15 Feb 2014 22:44:11 +0000 Subject: [PATCH] add pep8 tests and fix lexical indentation for python3 These are the pep8 tests that break python3, such as mixing tabs and spaces for indentation. I ignored all the pep8 tests that seemed only stylistic, such as "visual" indentation. http://docs.python.org/3.3/reference/lexical_analysis.html --- setup.py | 2 +- src/tito/builder/__init__.py | 16 +++++----- src/tito/builder/fetch.py | 12 +++---- src/tito/builder/main.py | 41 ++++++++++++------------ src/tito/cli.py | 46 +++++++++++++-------------- src/tito/common.py | 26 +++++++-------- src/tito/release.py | 8 ++--- src/tito/tagger.py | 4 +-- test/functional/multiproject_tests.py | 2 +- test/unit/common-tests.py | 2 +- test/unit/pep8-tests.py | 8 +++++ 11 files changed, 88 insertions(+), 79 deletions(-) diff --git a/setup.py b/setup.py index fc434ef..c6b356e 100755 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ setup( 'Intended Audience :: Information Technology', 'Programming Language :: Python' ], -# test_suite = 'nose.collector', + #test_suite = 'nose.collector', ) diff --git a/src/tito/builder/__init__.py b/src/tito/builder/__init__.py index 97d1a42..300e40f 100644 --- a/src/tito/builder/__init__.py +++ b/src/tito/builder/__init__.py @@ -1,13 +1,13 @@ # Import our builders so they can be referenced in config as tito.builder.Class # regardless of which submodule they're in. from tito.builder.main import \ - Builder, \ - NoTgzBuilder, \ - GemBuilder, \ - CvsBuilder, \ - UpstreamBuilder, \ - SatelliteBuilder, \ - MockBuilder, \ - BrewDownloadBuilder + Builder, \ + NoTgzBuilder, \ + GemBuilder, \ + CvsBuilder, \ + UpstreamBuilder, \ + SatelliteBuilder, \ + MockBuilder, \ + BrewDownloadBuilder from tito.builder.fetch import FetchBuilder diff --git a/src/tito/builder/fetch.py b/src/tito/builder/fetch.py index 94e69fc..9390d3f 100644 --- a/src/tito/builder/fetch.py +++ b/src/tito/builder/fetch.py @@ -74,9 +74,9 @@ class FetchBuilder(ConfigObject, BuilderBase): def _get_rpmbuild_dir_options(self): return ('--define "_topdir %s" --define "_sourcedir %s" --define "_builddir %s" ' '--define "_srcrpmdir %s" --define "_rpmdir %s" ' % ( - self.rpmbuild_dir, - self.rpmbuild_sourcedir, self.rpmbuild_builddir, - self.rpmbuild_basedir, self.rpmbuild_basedir)) + self.rpmbuild_dir, + self.rpmbuild_sourcedir, self.rpmbuild_builddir, + self.rpmbuild_basedir, self.rpmbuild_basedir)) class SourceStrategy(object): @@ -136,9 +136,9 @@ class ArgSourceStrategy(SourceStrategy): self.spec_file = os.path.join(self.builder.rpmbuild_sourcedir, '%s.spec' % self.builder.project_name) shutil.copyfile( - os.path.join(self.builder.start_dir, '%s.spec' % - self.builder.project_name), - self.spec_file) + os.path.join(self.builder.start_dir, '%s.spec' % + self.builder.project_name), + self.spec_file) print(" %s.spec" % self.builder.project_name) # TODO: Make this a configurable strategy: diff --git a/src/tito/builder/main.py b/src/tito/builder/main.py index 6aed50a..233d06d 100644 --- a/src/tito/builder/main.py +++ b/src/tito/builder/main.py @@ -26,7 +26,8 @@ from tempfile import mkdtemp from tito.common import * from tito.common import scl_to_rpm_option, get_latest_tagged_version, \ - find_wrote_in_rpmbuild_output + find_wrote_in_rpmbuild_output +from tito.compat import * from tito.exception import RunCommandException from tito.release import * from tito.exception import TitoException @@ -80,7 +81,7 @@ class BuilderBase(object): self.rpmbuild_basedir = build_dir # Location where we do actual rpmbuilds self.rpmbuild_dir = mkdtemp(dir=self.rpmbuild_basedir, - prefix="rpmbuild-%s" % self.project_name) + prefix="rpmbuild-%s" % self.project_name) debug("Building in temp dir: %s" % self.rpmbuild_dir) self.rpmbuild_sourcedir = os.path.join(self.rpmbuild_dir, "SOURCES") self.rpmbuild_builddir = os.path.join(self.rpmbuild_dir, "BUILD") @@ -197,8 +198,8 @@ class BuilderBase(object): cmd = ('LC_ALL=C rpmbuild --define "_source_filedigest_algorithm md5" --define' ' "_binary_filedigest_algorithm md5" %s %s %s --nodeps -bs %s' % ( - rpmbuild_options, self._get_rpmbuild_dir_options(), - define_dist, self.spec_file)) + rpmbuild_options, self._get_rpmbuild_dir_options(), + define_dist, self.spec_file)) output = run_command(cmd) print(output) self.srpm_location = find_wrote_in_rpmbuild_output(output)[0] @@ -343,10 +344,10 @@ class Builder(ConfigObject, BuilderBase): self.display_version = self._get_display_version() self.git_commit_id = get_build_commit(tag=self.build_tag, - test=self.test) + test=self.test) self.relative_project_dir = get_relative_project_dir( - project_name=self.project_name, commit=self.git_commit_id) + project_name=self.project_name, commit=self.git_commit_id) tgz_base = self._get_tgz_name_and_ver() self.tgz_filename = tgz_base + ".tar.gz" @@ -474,9 +475,9 @@ class Builder(ConfigObject, BuilderBase): def _get_rpmbuild_dir_options(self): return ('--define "_topdir %s" --define "_sourcedir %s" --define "_builddir %s" --define ' '"_srcrpmdir %s" --define "_rpmdir %s" ' % ( - self.rpmbuild_dir, - self.rpmbuild_sourcedir, self.rpmbuild_builddir, - self.rpmbuild_basedir, self.rpmbuild_basedir)) + self.rpmbuild_dir, + self.rpmbuild_sourcedir, self.rpmbuild_builddir, + self.rpmbuild_basedir, self.rpmbuild_basedir)) def _get_tgz_name_and_ver(self): """ @@ -545,9 +546,9 @@ class NoTgzBuilder(Builder): """ return ('--define "_topdir %s" --define "_sourcedir %s" --define "_builddir %s" ' '--define "_srcrpmdir %s" --define "_rpmdir %s" ' % ( - self.rpmbuild_dir, - self.rpmbuild_gitcopy, self.rpmbuild_builddir, - self.rpmbuild_basedir, self.rpmbuild_basedir)) + self.rpmbuild_dir, + self.rpmbuild_gitcopy, self.rpmbuild_builddir, + self.rpmbuild_basedir, self.rpmbuild_basedir)) def _setup_test_specfile(self): """ Override parent behavior. """ @@ -797,7 +798,7 @@ class UpstreamBuilder(NoTgzBuilder): tgz_filename = "%s.tar.gz" % prefix commit = get_build_commit(tag=self.upstream_tag) relative_dir = get_relative_project_dir( - project_name=self.upstream_name, commit=commit) + project_name=self.upstream_name, commit=commit) tgz_fullpath = os.path.join(self.rpmbuild_sourcedir, tgz_filename) print("Creating %s from git tag: %s..." % (tgz_filename, commit)) create_tgz(self.git_root, prefix, commit, relative_dir, @@ -934,9 +935,9 @@ class UpstreamBuilder(NoTgzBuilder): """ return ('--define "_topdir %s" --define "_sourcedir %s" --define "_builddir %s" ' '--define "_srcrpmdir %s" --define "_rpmdir %s" ' % ( - self.rpmbuild_dir, - self.rpmbuild_sourcedir, self.rpmbuild_builddir, - self.rpmbuild_basedir, self.rpmbuild_basedir)) + self.rpmbuild_dir, + self.rpmbuild_sourcedir, self.rpmbuild_builddir, + self.rpmbuild_basedir, self.rpmbuild_basedir)) # Legacy class name for backward compatability: @@ -1172,8 +1173,8 @@ class ExternalSourceBuilder(ConfigObject, BuilderBase): self.spec_file = os.path.join(self.rpmbuild_sourcedir, '%s.spec' % self.project_name) shutil.copyfile( - os.path.join(self.start_dir, '%s.spec' % self.project_name), - self.spec_file) + os.path.join(self.start_dir, '%s.spec' % self.project_name), + self.spec_file) print(" %s.spec" % self.project_name) # TODO: Make this a configurable strategy: @@ -1242,8 +1243,8 @@ class ExternalSourceBuilder(ConfigObject, BuilderBase): def _get_rpmbuild_dir_options(self): return ('--define "_sourcedir %s" --define "_builddir %s" ' '--define "_srcrpmdir %s" --define "_rpmdir %s" ' % ( - self.rpmbuild_sourcedir, self.rpmbuild_builddir, - self.rpmbuild_basedir, self.rpmbuild_basedir)) + self.rpmbuild_sourcedir, self.rpmbuild_builddir, + self.rpmbuild_basedir, self.rpmbuild_basedir)) def _setup_test_specfile(self): """ Override parent behavior. """ diff --git a/src/tito/cli.py b/src/tito/cli.py index ccecd79..a422f0e 100644 --- a/src/tito/cli.py +++ b/src/tito/cli.py @@ -170,7 +170,7 @@ class BaseCliModule(object): debug("Added lib dir to PYTHONPATH: %s" % lib_dir) else: print("WARNING: lib_dir specified but does not exist: %s" % - lib_dir) + lib_dir) def _read_config(self): """ @@ -200,8 +200,8 @@ class BaseCliModule(object): # Verify the config contains what we need from it: required_global_config = [ - (GLOBALCONFIG_SECTION, DEFAULT_BUILDER), - (GLOBALCONFIG_SECTION, DEFAULT_TAGGER), + (GLOBALCONFIG_SECTION, DEFAULT_BUILDER), + (GLOBALCONFIG_SECTION, DEFAULT_TAGGER), ] for section, option in required_global_config: if not config.has_section(section) or not \ @@ -285,7 +285,7 @@ class BaseCliModule(object): # tagged before they existed, check for a Makefile with # NO_TAR_GZ defined and make some assumptions based on that. cmd = "git show %s:%s%s | grep NO_TAR_GZ" % \ - (tag, relative_dir, "Makefile") + (tag, relative_dir, "Makefile") debug(cmd) (status, output) = commands.getstatusoutput(cmd) if status == 0 and output != "": @@ -388,12 +388,12 @@ class BuildModule(BaseCliModule): args = self._parse_builder_args() kwargs = { - 'dist': self.options.dist, - 'test': self.options.test, - 'offline': self.options.offline, - 'auto_install': self.options.auto_install, - 'rpmbuild_options': self.options.rpmbuild_options, - 'scl': self.options.scl, + 'dist': self.options.dist, + 'test': self.options.test, + 'offline': self.options.offline, + 'auto_install': self.options.auto_install, + 'rpmbuild_options': self.options.rpmbuild_options, + 'scl': self.options.scl, } builder = create_builder(package_name, build_tag, @@ -616,22 +616,22 @@ class ReleaseModule(BaseCliModule): # TODO: support list values builder_args[key] = val kwargs = { - 'builder_args': builder_args, - 'offline': self.options.offline + 'builder_args': builder_args, + 'offline': self.options.offline } releaser = releaser_class( - name=package_name, - tag=build_tag, - build_dir=build_dir, - config=self.config, - user_config=self.user_config, - target=target, - releaser_config=releaser_config, - no_cleanup=self.options.no_cleanup, - test=self.options.test, - auto_accept=self.options.auto_accept, - **kwargs) + name=package_name, + tag=build_tag, + build_dir=build_dir, + config=self.config, + user_config=self.user_config, + target=target, + releaser_config=releaser_config, + no_cleanup=self.options.no_cleanup, + test=self.options.test, + auto_accept=self.options.auto_accept, + **kwargs) releaser.release(dry_run=self.options.dry_run, no_build=self.options.no_build, diff --git a/src/tito/common.py b/src/tito/common.py index 22c9e9e..bbb6f0f 100644 --- a/src/tito/common.py +++ b/src/tito/common.py @@ -142,13 +142,13 @@ def create_builder(package_name, build_tag, # Instantiate the builder: builder = builder_class( - name=package_name, - tag=build_tag, - build_dir=build_dir, - config=config, - user_config=user_config, - args=args, - **kwargs) + name=package_name, + tag=build_tag, + build_dir=build_dir, + config=config, + user_config=user_config, + args=args, + **kwargs) return builder @@ -247,8 +247,8 @@ def tag_exists_remotely(tag): def get_local_tag_sha1(tag): tag_sha1 = run_command( - "git ls-remote ./. --tag %s | awk '{ print $1 ; exit }'" - % tag) + "git ls-remote ./. --tag %s | awk '{ print $1 ; exit }'" + % tag) tag_sha1 = extract_sha1(tag_sha1) return tag_sha1 @@ -434,8 +434,8 @@ def get_build_commit(tag, test=False): return get_latest_commit(".") else: tag_sha1 = run_command( - "git ls-remote ./. --tag %s | awk '{ print $1 ; exit }'" - % tag) + "git ls-remote ./. --tag %s | awk '{ print $1 ; exit }'" + % tag) tag_sha1 = extract_sha1(tag_sha1) commit_id = run_command('git rev-list --max-count=1 %s' % tag_sha1) return commit_id @@ -478,8 +478,8 @@ def get_commit_timestamp(sha1_or_tag): version regardless of when they are generated. """ output = run_command( - "git rev-list --timestamp --max-count=1 %s | awk '{print $1}'" - % sha1_or_tag) + "git rev-list --timestamp --max-count=1 %s | awk '{print $1}'" + % sha1_or_tag) return output diff --git a/src/tito/release.py b/src/tito/release.py index 0cc1ee6..822712a 100644 --- a/src/tito/release.py +++ b/src/tito/release.py @@ -122,13 +122,13 @@ class Releaser(ConfigObject): for opt in self.GLOBAL_REQUIRED_CONFIG: if not self.releaser_config.has_option(self.target, opt): raise TitoException( - "Release target '%s' missing required option '%s'" % - (self.target, opt)) + "Release target '%s' missing required option '%s'" % + (self.target, opt)) for opt in self.REQUIRED_CONFIG: if not self.releaser_config.has_option(self.target, opt): raise TitoException( - "Release target '%s' missing required option '%s'" % - (self.target, opt)) + "Release target '%s' missing required option '%s'" % + (self.target, opt)) # TODO: accomodate 'builder.*' for yum releaser and we can use this: #for opt in self.releaser_config.options(self.target): diff --git a/src/tito/tagger.py b/src/tito/tagger.py index 6ec5f4f..bedcb74 100644 --- a/src/tito/tagger.py +++ b/src/tito/tagger.py @@ -56,7 +56,7 @@ class VersionTagger(ConfigObject): self.project_name = get_project_name(tag=None) self.relative_project_dir = self._get_relative_project_dir( - self.git_root) # i.e. java/ + self.git_root) # i.e. java/ self.spec_file = os.path.join(self.full_project_dir, self.spec_file_name) @@ -139,7 +139,7 @@ class VersionTagger(ConfigObject): print("Undoing tag: %s" % tag) if not tag_exists_locally(tag): raise TitoException( - "Cannot undo tag that does not exist locally.") + "Cannot undo tag that does not exist locally.") if not self.offline and tag_exists_remotely(tag): raise TitoException("Cannot undo tag that has been pushed.") diff --git a/test/functional/multiproject_tests.py b/test/functional/multiproject_tests.py index 7970dcb..432475a 100644 --- a/test/functional/multiproject_tests.py +++ b/test/functional/multiproject_tests.py @@ -21,7 +21,7 @@ import os from os.path import join from tito.common import run_command, \ - get_latest_tagged_version, tag_exists_locally + get_latest_tagged_version, tag_exists_locally from fixture import * # A location where we can safely create a test git repository. diff --git a/test/unit/common-tests.py b/test/unit/common-tests.py index b8cc84b..2c16608 100644 --- a/test/unit/common-tests.py +++ b/test/unit/common-tests.py @@ -191,7 +191,7 @@ class ExtractBugzillasTest(unittest.TestCase): def test_multi_line(self): commit_log = "- 123456: Did something interesting.\n- Another commit.\n" \ - "- 456789: A third commit." + "- 456789: A third commit." results = extract_bzs(commit_log) self.assertEquals(2, len(results)) self.assertEquals("Resolves: #123456 - Did something interesting.", diff --git a/test/unit/pep8-tests.py b/test/unit/pep8-tests.py index 34fe572..7f1050d 100644 --- a/test/unit/pep8-tests.py +++ b/test/unit/pep8-tests.py @@ -32,12 +32,20 @@ class TestPep8(TitoUnitTestFixture): def test_conformance(self): tests = [ # http://pep8.readthedocs.org/en/latest/intro.html#error-codes + 'E101', # indentation contains mixed spaces and tabs + 'E111', # indentation is not a multiple of four + 'E112', # expected an indented block + 'E113', # unexpected indentation + 'E121', # continuation line indentation is not a multiple of four + 'E122', # continuation line missing indentation or outdented + 'E126', # continuation line over-indented for hanging indent 'E2', # whitespace errors 'E3', # blank line errors 'E4', # import errors 'E502', # the backslash is redundant between brackets 'E7', # statement errors 'E9', # runtime errors (SyntaxError, IndentationError, IOError) + 'W1', # indentation warnings 'W2', # whitespace warnings 'W3', # blank line warnings 'W6', # deprecated features