Add flake8 configuration. Fix style issues.

- Remove assignments to unused variables
- Rename variables shadowing builtins
- Fix all flake8 errors in tests
This commit is contained in:
Alex Wood 2015-05-08 10:58:56 -04:00
parent ea0ea51552
commit b0e85268c9
22 changed files with 61 additions and 39 deletions

View file

@ -1,5 +1,8 @@
# Import our builders so they can be referenced in config as tito.builder.Class
# regardless of which submodule they're in.
# flake8: noqa
from tito.builder.main import \
Builder, \
NoTgzBuilder, \

View file

@ -867,7 +867,6 @@ class MeadBuilder(Builder):
else:
self.maven_args.append('-q')
def tgz(self):
self._setup_sources()
@ -1060,18 +1059,18 @@ class MockBuilder(Builder):
def _build_in_mock(self):
if not self.speedup:
print("Initializing mock...")
output = run_command("mock %s -r %s --init" % (self.mock_cmd_args, self.mock_tag))
run_command("mock %s -r %s --init" % (self.mock_cmd_args, self.mock_tag))
else:
print("Skipping mock --init due to speedup option.")
print("Installing deps in mock...")
output = run_command("mock %s -r %s %s" % (
run_command("mock %s -r %s %s" % (
self.mock_cmd_args, self.mock_tag, self.srpm_location))
print("Building RPMs in mock...")
output = run_command('mock %s -r %s --rebuild %s' %
run_command('mock %s -r %s --rebuild %s' %
(self.mock_cmd_args, self.mock_tag, self.srpm_location))
mock_output_dir = os.path.join(self.rpmbuild_dir, "mockoutput")
output = run_command("mock %s -r %s --copyout /builddir/build/RPMS/ %s" %
run_command("mock %s -r %s --copyout /builddir/build/RPMS/ %s" %
(self.mock_cmd_args, self.mock_tag, mock_output_dir))
# Copy everything mock wrote out to /tmp/tito:

View file

@ -16,12 +16,11 @@ Tito's Command Line Interface
import sys
import os
import random
from optparse import OptionParser
from tito.common import find_git_root, error_out, debug, get_class_by_name, \
BUILDCONFIG_SECTION, DEFAULT_BUILDER, BUILDCONFIG_SECTION, DEFAULT_TAGGER, \
DEFAULT_BUILDER, BUILDCONFIG_SECTION, DEFAULT_TAGGER, \
create_builder, get_project_name, get_relative_project_dir, \
DEFAULT_BUILD_DIR, run_command, tito_config_dir
from tito.compat import RawConfigParser, getstatusoutput, getoutput
@ -29,7 +28,7 @@ from tito.exception import TitoException
# Hack for Python 2.4, seems to require we import these so they get compiled
# before we try to dynamically import them based on a string name.
import tito.tagger
import tito.tagger # NOQA
TITO_PROPS = "tito.props"
RELEASERS_CONF_FILENAME = "releasers.conf"

View file

@ -514,7 +514,7 @@ def check_tag_exists(tag, offline=False):
debug("Local tag SHA1: %s" % tag_sha1)
try:
repo_url = get_git_repo_url()
get_git_repo_url()
except:
sys.stderr.write('Warning: remote.origin do not exist. Assuming --offline, for remote tag checking.\n')
return
@ -593,7 +593,7 @@ def replace_spec_release(file_name, release):
if m:
print("%s%s" % (m.group(1), release))
else:
print line
print(line)
def scrape_version_and_release(template_file_name):

View file

@ -10,6 +10,9 @@
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
# flake8: noqa
"""
Compatibility library for Python 2.4 up through Python 3.
"""

View file

@ -1,3 +1,5 @@
# flake8: noqa
from tito.release.main import \
Releaser, \
RsyncReleaser, \

View file

@ -412,7 +412,7 @@ class DistGitMeadReleaser(DistGitReleaser):
print("Syncing local repo with %s" % self.mead_scm)
try:
run_command("git push %s %s" % (self.mead_scm, self.builder.build_tag))
except RunCommandException, e:
except RunCommandException as e:
if "rejected" in e.output:
if self._ask_yes_no("The remote rejected a push. Force push? [y/n] ", False):
run_command("git push --force %s %s" % (self.mead_scm, self.builder.build_tag))

View file

@ -1,3 +1,5 @@
# flake8: noqa
from tito.tagger.main import \
VersionTagger, \
ReleaseTagger, \

View file

@ -251,15 +251,15 @@ class VersionTagger(ConfigObject):
subprocess.call(editor.split() + [name])
os.lseek(fd, 0, 0)
file = os.fdopen(fd)
f = os.fdopen(fd)
for line in file.readlines():
for line in f.readlines():
if not line.startswith("#"):
out_f.write(line)
output = file.read()
output = f.read()
file.close()
f.close()
os.unlink(name)
if not found_changelog:

View file

@ -24,7 +24,7 @@ from os.path import join
from functional.fixture import TitoGitTestFixture, tito
from tito.compat import *
from tito.compat import * # NOQA
from tito.common import run_command
from tito.builder import GitAnnexBuilder

View file

@ -14,9 +14,8 @@
import os
import tempfile
from os.path import join
from tito.builder import Builder
from tito.common import *
from tito.common import run_command
from tito.compat import RawConfigParser
from functional.fixture import TitoGitTestFixture, tito

View file

@ -23,7 +23,7 @@ import tempfile
from os.path import join
from tito.common import run_command, tito_config_dir
from tito.compat import *
from tito.compat import * # NOQA
from functional.fixture import TitoGitTestFixture, tito
EXT_SRC_PKG = "extsrc"

View file

@ -22,7 +22,7 @@ from os.path import join
from tito.common import run_command, \
get_latest_tagged_version, tag_exists_locally
from functional.fixture import *
from functional.fixture import TitoGitTestFixture, tito
# A location where we can safely create a test git repository.
# WARNING: This location will be destroyed if present.

View file

@ -17,7 +17,7 @@ Functional Tests for the CoprReleaser.
from functional.fixture import TitoGitTestFixture
from tito.compat import *
from tito.compat import * # NOQA
from tito.release import CoprReleaser
PKG_NAME = "releaseme"

View file

@ -24,7 +24,7 @@ from os.path import join
from functional.fixture import TitoGitTestFixture, tito
from tito.compat import *
from tito.compat import * # NOQA
from tito.common import run_command
PKG_NAME = "releaseme"

View file

@ -13,8 +13,8 @@
# in this software or its documentation.
import os
from tito.common import *
from tito.builder import *
from tito.builder import Builder, UpstreamBuilder
from tito.common import tag_exists_locally, check_tag_exists
from tito.release import Releaser
from tito.compat import getoutput
from functional.fixture import TitoGitTestFixture, tito

View file

@ -14,7 +14,7 @@
from contextlib import contextmanager
from mock import mock_open, patch
from StringIO import StringIO
from itertools import repeat
@contextmanager
def open_mock(content, **kwargs):

View file

@ -13,15 +13,18 @@
# in this software or its documentation.
""" Pure unit tests for tito's common module. """
from tito.common import *
from tito import common
from tito.common import (replace_version, find_spec_like_file, increase_version,
search_for, compare_version, run_command_print, find_wrote_in_rpmbuild_output,
render_cheetah, increase_zstream, reset_release, find_file_with_extension,
normalize_class_name, extract_sha1, BugzillaExtractor
)
import unittest
from mock import Mock, patch, call, mock_open
from mock import Mock, patch, call
from textwrap import dedent
from unit import open_mock
from textwrap import dedent
class CommonTests(unittest.TestCase):
@ -167,26 +170,26 @@ class CommonTests(unittest.TestCase):
HelloWorld
Hello World
""")
with open_mock(content) as fh:
with open_mock(content):
results = search_for("foo", r"(Hello\s+World)", r"(HelloWorld)")
self.assertEquals(("Hello World",) , results[0])
self.assertEquals(("HelloWorld",) , results[1])
self.assertEquals(("Hello World",), results[0])
self.assertEquals(("HelloWorld",), results[1])
def test_search_for_gets_first_match(self):
content = dedent("""
HelloWorld
Hello World
""")
with open_mock(content) as fh:
with open_mock(content):
results = search_for("foo", r"(Hello.*)")
self.assertEquals(("HelloWorld",) , results[0])
self.assertEquals(("HelloWorld",), results[0])
def test_search_for_no_match(self):
content = dedent("""
HelloWorld
Goodbye World
""")
with open_mock(content) as fh:
with open_mock(content):
self.assertRaises(SystemExit, search_for, "foo", r"(NoMatch)")
@ -228,6 +231,7 @@ class CheetahRenderTest(unittest.TestCase):
self.assertEquals(call("/tmp/*.cheetah"), mock_glob.mock_calls[0])
self.assertEquals(call("temp_pickle"), mock_unlink.mock_calls[0])
class VersionMathTest(unittest.TestCase):
def test_increase_version_minor(self):
line = "1.0.0"

View file

@ -14,7 +14,7 @@
import os
import unittest
from tito.compat import *
from tito.compat import * # NOQA
UNIT_DIR = os.path.abspath(os.path.dirname(__file__))
REPO_DIR = os.path.join(UNIT_DIR, '..', '..')

View file

@ -22,7 +22,8 @@ http://docs.python.org/3.3/reference/lexical_analysis.html
"""
import pep8
from unit.fixture import *
from tito.compat import * # NOQA
from unit.fixture import TitoUnitTestFixture
class TestPep8(TitoUnitTestFixture):

View file

@ -1,7 +1,7 @@
import unittest
from tito.buildparser import BuildTargetParser
from tito.compat import *
from tito.compat import * # NOQA
from tito.exception import TitoException

10
tox.ini Normal file
View file

@ -0,0 +1,10 @@
# ignore errors:
# E12* are continuation line indention related
# E501 is line too long
# See http://pep8.readthedocs.org/en/latest/intro.html#id1
[flake8]
ignore=E124,E125,E127,E128,E501
# Exclude the build directory that distutils creates
exclude=build/*
max-line-length=120