Add PEP8 check and fix related issues

- Add PEP8 section to tox.ini
- Add hacking to requirements to enforce OpenStack style requirements
- Fix formatting issues flagged by flake8 check
- Add copyright notices to all remaining files
- Update .gitignore file
- Fix an unused variable bug
- Fix a mutable default argument bug

Change-Id: I711efd8055f98e4ffc0bef706f25c6a335409aaa
This commit is contained in:
Levi Blackstone 2015-05-04 15:34:54 -05:00
parent 519bbeaab3
commit 4b2cd52264
4 changed files with 43 additions and 23 deletions

4
.gitignore vendored
View File

@ -52,3 +52,7 @@ coverage.xml
# Sphinx documentation # Sphinx documentation
docs/_build/ docs/_build/
# IDE Project Files
*.project
*.pydev*
*.idea

View File

@ -15,8 +15,9 @@
import logging import logging
from winchester.config import ConfigItem
from winchester.config import ConfigManager, ConfigSection, ConfigItem from winchester.config import ConfigManager
from winchester.config import ConfigSection
from winchester.db import DBInterface from winchester.db import DBInterface
from winchester import models from winchester import models
@ -25,18 +26,20 @@ logger = logging.getLogger(__name__)
class Impl(object): class Impl(object):
@classmethod @classmethod
def config_description(cls): def config_description(cls):
return dict(config_path=ConfigItem( return dict(
help="Path(s) to find additional config files", config_path=ConfigItem(
multiple=True, default='.'), help="Path(s) to find additional config files",
database=ConfigSection(help="Database connection info.", multiple=True, default='.'),
config_description=DBInterface.config_description()), database=ConfigSection(
) help="Database connection info.",
config_description=DBInterface.config_description()),
)
def __init__(self, config, scratchpad): def __init__(self, config, scratchpad):
"""config is a ConfigParser object. """config is a ConfigParser object.
Use the scratchpad to ensure we don't create multiple Use the scratchpad to ensure we don't create multiple
connections to the db. connections to the db.
""" """
@ -46,17 +49,18 @@ class Impl(object):
logger.debug("Quince is using Winchester config from %s" % target) logger.debug("Quince is using Winchester config from %s" % target)
quincy_config = ConfigManager.load_config_file(target) quincy_config = ConfigManager.load_config_file(target)
quincy_config = ConfigManager.wrap(quincy_config, quincy_config = ConfigManager.wrap(quincy_config,
self.config_description()) self.config_description())
scratchpad['quincy_config'] = quincy_config scratchpad['quincy_config'] = quincy_config
scratchpad['quincy_driver'] = DBInterface(quincy_config['database']) scratchpad['quincy_driver'] = DBInterface(
quincy_config['database'])
self.winchester_config = scratchpad['quincy_config'] self.winchester_config = scratchpad['quincy_config']
self.driver = scratchpad['quincy_driver'] self.driver = scratchpad['quincy_driver']
def find_streams(self, count=False, state=None, older_than=None, def find_streams(self, count=False, state=None, older_than=None,
younger_than=None, trigger_name=None, younger_than=None, trigger_name=None,
distinguishing_traits=None, mark=None, limit=None): distinguishing_traits=None, mark=None, limit=None):
if state is not None: if state is not None:
try: try:
@ -64,14 +68,16 @@ class Impl(object):
except KeyError: except KeyError:
logger.error("invalid stream state %s" % state) logger.error("invalid stream state %s" % state)
raise raise
return self.driver.find_streams(count=count, return self.driver.find_streams(
state=state, name=trigger_name, count=count,
younger_than=younger_than, older_than=older_than, state=state, name=trigger_name,
distinguishing_traits=distinguishing_traits, younger_than=younger_than,
mark=mark, limit=limit) older_than=older_than,
distinguishing_traits=distinguishing_traits,
mark=mark, limit=limit)
def get_stream(self, stream_id, details): def get_stream(self, stream_id, details):
stream = int(stream_id) stream_id = int(stream_id)
# Returns a list, but should be just one stream. # Returns a list, but should be just one stream.
return self.driver.find_streams(stream_id=stream_id, return self.driver.find_streams(stream_id=stream_id,
include_events=details) include_events=details)
@ -87,12 +93,12 @@ class Impl(object):
self.driver.reset_stream(stream) self.driver.reset_stream(stream)
def find_events(self, from_datetime=None, to_datetime=None, def find_events(self, from_datetime=None, to_datetime=None,
event_name=None, traits=[], event_name=None, traits=None,
mark=None, limit=None, count=False): mark=None, limit=None, count=False):
return self.driver.find_events(from_datetime=from_datetime, return self.driver.find_events(from_datetime=from_datetime,
to_datetime=to_datetime, to_datetime=to_datetime,
event_name=event_name, event_name=event_name,
traits=traits, traits=traits or [],
mark=mark, limit=limit, mark=mark, limit=limit,
count=count) count=count)

View File

@ -1,2 +1,3 @@
hacking>=0.10.0,<0.11
winchester >=0.0.dev0 winchester >=0.0.dev0
simport >=0.0.dev0 simport >=0.0.dev0

11
tox.ini
View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = py26,py27 envlist = py26,py27,pep8
[testenv] [testenv]
deps = deps =
@ -8,3 +8,12 @@ deps =
mock mock
commands = nosetests -d -v --with-coverage --cover-inclusive --cover-package quince [] commands = nosetests -d -v --with-coverage --cover-inclusive --cover-package quince []
[testenv:pep8]
commands =
flake8
[flake8]
ignore =
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,*db/__init__.py,*db/migrations/versions/*_.py
show-source = True