Skip to content

Commit

Permalink
linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
silasary committed Apr 24, 2018
1 parent 1ec45d2 commit 4d3ada2
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Expand Up @@ -77,7 +77,7 @@ disable=long-builtin,backtick,old-raise-syntax,unichr-builtin,old-octal-literal,
file-builtin,coerce-method,next-method-called,oct-method,range-builtin-not-iterating,
parameter-unpacking,missing-docstring,too-few-public-methods,too-many-return-statements,
too-many-branches,too-many-statements,locally-disabled,invalid-sequence-index,len-as-condition,
wrong-import-order,line-too-long
wrong-import-order,line-too-long,ungrouped-imports


[REPORTS]
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Expand Up @@ -34,8 +34,7 @@ lint:
@echo
@echo "******************************** Lint *****************************************"
@echo
@pylint --generate-rcfile | grep -v "ignored-modules=" >.pylintrc.tmp
@find . -name "*.py" | grep -v .git | grep -v logsite_migrations | xargs pylint --ignored-modules=alembic,MySQLdb,flask_sqlalchemy --ignore=logsite_migrations --rcfile=.pylintrc.tmp --reports=n -f parseable; (ret=$$?; echo; rm -f .pylintrc.tmp && exit $$ret)
@python3 dev.py pylint
@mypy --ignore-missing-imports .
@isort --check-only --skip=''

Expand Down
13 changes: 2 additions & 11 deletions decksite/view.py
Expand Up @@ -14,27 +14,18 @@
from magic import oracle, rotation, tournaments
from shared import dtutil
from shared.container import Container
from shared_web import template
from shared_web.base_view import BaseView

NUM_MOST_COMMON_CARDS_TO_LIST = 10

# pylint: disable=no-self-use, too-many-public-methods
class View:
class View(BaseView):
def __init__(self):
# Set some pointless instance vars to keep Codacy happy.
self.decks = []
self.active_runs_text = None
self.is_very_large = None

def template(self):
return self.__class__.__name__.lower()

def content(self):
return template.render(self)

def page(self):
return template.render_name('page', self)

def home_url(self):
return url_for('home')

Expand Down
23 changes: 23 additions & 0 deletions dev.py
@@ -0,0 +1,23 @@
import os
import sys

LINT_PATHS = [o for o in os.listdir('.') if os.path.isdir(o) and os.path.exists(os.path.join(o, '__init__.py'))]
LINT_PATHS.extend([o for o in os.listdir('.') if os.path.isfile(o) and os.path.splitext(o)[1] == '.py'])

def run() -> None:
cmd = sys.argv[1].lower()

if cmd in ('lint', 'pylint'):
lint()

def lint() -> None:
args = sys.argv[2:] or ['--rcfile=.pylintrc', # Load rcfile first.
'--ignored-modules=alembic,MySQLdb,flask_sqlalchemy', # override ignored-modules (codacy hack)
'--reports=n', '-f', 'parseable'
]
args.extend(LINT_PATHS)
import pylint.lint
pylint.lint.Run(args)

if __name__ == '__main__':
run()
3 changes: 2 additions & 1 deletion logsite/smoke_test.py
Expand Up @@ -3,7 +3,6 @@
import pytest

from logsite.main import APP
from shared_web import template


class SmokeTest(unittest.TestCase):
Expand Down Expand Up @@ -35,3 +34,5 @@ def test_some_pages(self):
self.assertEqual(result.status_code, 200)
result = self.app.get('/recent.json')
self.assertEqual(result.status_code, 200)
result = self.app.get('/stats.json')
self.assertEqual(result.status_code, 200)
13 changes: 2 additions & 11 deletions logsite/view.py
@@ -1,21 +1,12 @@
from flask import url_for

from shared_web import template
from shared_web.base_view import BaseView

from . import APP


# pylint: disable=no-self-use, too-many-public-methods
class View:
def template(self):
return self.__class__.__name__.lower()

def content(self):
return template.render(self)

def page(self):
return template.render_name('page', self)

class View(BaseView):
def home_url(self):
return url_for('home')

Expand Down
2 changes: 1 addition & 1 deletion shared/dtutil.py
Expand Up @@ -28,7 +28,7 @@ def ts2dt(ts: float) -> datetime.datetime:

# Converts a timezone-aware UTC datetime into a UTC timestamp (seconds).
def dt2ts(dt: datetime.datetime) -> float:
assert dt.tzinfo is not None, "datetime must be timezone aware."
assert dt.tzinfo is not None, 'datetime must be timezone aware.'
return dt.timestamp()

# Converts the given string in the format `format` to a timezone-aware UTC datetime assuming the original string is in timezone `tz`.
Expand Down
13 changes: 13 additions & 0 deletions shared_web/base_view.py
@@ -0,0 +1,13 @@
from . import template


# pylint: disable=no-self-use, too-many-public-methods
class BaseView:
def template(self):
return self.__class__.__name__.lower()

def content(self):
return template.render(self)

def page(self):
return template.render_name('page', self)

0 comments on commit 4d3ada2

Please sign in to comment.