Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add flake8 configuration. Fix style issues.
- Remove assignments to unused variables
- Rename variables shadowing builtins
- Fix all flake8 errors in tests
  • Loading branch information
awood committed May 18, 2015
1 parent ea0ea51 commit b0e8526
Show file tree
Hide file tree
Showing 22 changed files with 61 additions and 39 deletions.
3 changes: 3 additions & 0 deletions src/tito/builder/__init__.py
@@ -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, \
Expand Down
9 changes: 4 additions & 5 deletions src/tito/builder/main.py
Expand Up @@ -867,7 +867,6 @@ def __init__(self, name=None, tag=None, build_dir=None,
else:
self.maven_args.append('-q')


def tgz(self):
self._setup_sources()

Expand Down Expand Up @@ -1060,18 +1059,18 @@ def cleanup(self):
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:
Expand Down
5 changes: 2 additions & 3 deletions src/tito/cli.py
Expand Up @@ -16,20 +16,19 @@

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
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"
Expand Down
4 changes: 2 additions & 2 deletions src/tito/common.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions src/tito/compat.py
Expand Up @@ -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.
"""
Expand Down
2 changes: 2 additions & 0 deletions src/tito/release/__init__.py
@@ -1,3 +1,5 @@
# flake8: noqa

from tito.release.main import \
Releaser, \
RsyncReleaser, \
Expand Down
2 changes: 1 addition & 1 deletion src/tito/release/distgit.py
Expand Up @@ -412,7 +412,7 @@ def _sync_mead_scm(self):
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))
Expand Down
2 changes: 2 additions & 0 deletions src/tito/tagger/__init__.py
@@ -1,3 +1,5 @@
# flake8: noqa

from tito.tagger.main import \
VersionTagger, \
ReleaseTagger, \
Expand Down
8 changes: 4 additions & 4 deletions src/tito/tagger/main.py
Expand Up @@ -251,15 +251,15 @@ def _make_changelog(self):
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:
Expand Down
2 changes: 1 addition & 1 deletion test/functional/build_gitannex_tests.py
Expand Up @@ -24,7 +24,7 @@

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

Expand Down
3 changes: 1 addition & 2 deletions test/functional/builder_tests.py
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/functional/fetch_tests.py
Expand Up @@ -23,7 +23,7 @@
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"
Expand Down
2 changes: 1 addition & 1 deletion test/functional/multiproject_tests.py
Expand Up @@ -22,7 +22,7 @@

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.
Expand Down
2 changes: 1 addition & 1 deletion test/functional/release_copr_tests.py
Expand Up @@ -17,7 +17,7 @@

from functional.fixture import TitoGitTestFixture

from tito.compat import *
from tito.compat import * # NOQA
from tito.release import CoprReleaser

PKG_NAME = "releaseme"
Expand Down
2 changes: 1 addition & 1 deletion test/functional/release_yum_tests.py
Expand Up @@ -24,7 +24,7 @@

from functional.fixture import TitoGitTestFixture, tito

from tito.compat import *
from tito.compat import * # NOQA
from tito.common import run_command

PKG_NAME = "releaseme"
Expand Down
4 changes: 2 additions & 2 deletions test/functional/singleproject_tests.py
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/unit/__init__.py
Expand Up @@ -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):
Expand All @@ -30,4 +30,4 @@ def open_mock(content, **kwargs):
rv.content_out = lambda: content_out.getvalue()
rv.__iter__.return_value = iter(stream.readlines())
rv.read.return_value = stream.read()
yield rv
yield rv
24 changes: 14 additions & 10 deletions test/unit/common_tests.py
Expand Up @@ -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):

Expand Down Expand Up @@ -167,26 +170,26 @@ def test_search_for(self):
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)")


Expand Down Expand Up @@ -228,6 +231,7 @@ def test_renders_cheetah_missing_result(self, mock_tempfile, mock_run_command, m
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"
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixture.py
Expand Up @@ -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, '..', '..')
Expand Down
3 changes: 2 additions & 1 deletion test/unit/pep8_tests.py
Expand Up @@ -22,7 +22,8 @@
"""

import pep8
from unit.fixture import *
from tito.compat import * # NOQA
from unit.fixture import TitoUnitTestFixture


class TestPep8(TitoUnitTestFixture):
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_build_target_parser.py
@@ -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


Expand Down
10 changes: 10 additions & 0 deletions tox.ini
@@ -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

0 comments on commit b0e8526

Please sign in to comment.