diff --git a/checkmate/db.py b/checkmate/db.py index 3bcbc26b..09b5113d 100644 --- a/checkmate/db.py +++ b/checkmate/db.py @@ -11,6 +11,14 @@ LOG = logging.getLogger(__name__) +NAMING_CONVENTIONS = { + "ix": "ix__%(column_0_label)s", + "uq": "uq__%(table_name)s__%(column_0_name)s", + "ck": "ck__%(table_name)s__%(constraint_name)s", + "fk": "fk__%(table_name)s__%(column_0_name)s__%(referred_table_name)s", + "pk": "pk__%(table_name)s", +} + class BaseClass: """Functions common to all SQLAlchemy models.""" @@ -32,15 +40,7 @@ def __repr__(self): # alembic after creation much easier. See: # http://docs.sqlalchemy.org/en/latest/core/constraints.html#configuring-constraint-naming-conventions cls=BaseClass, - metadata=sqlalchemy.MetaData( - naming_convention={ - "ix": "ix__%(column_0_label)s", - "uq": "uq__%(table_name)s__%(column_0_name)s", - "ck": "ck__%(table_name)s__%(constraint_name)s", - "fk": "fk__%(table_name)s__%(column_0_name)s__%(referred_table_name)s", - "pk": "pk__%(table_name)s", - } - ), + metadata=sqlalchemy.MetaData(naming_convention=NAMING_CONVENTIONS), ) @@ -115,11 +115,11 @@ def _session(request): # pragma: no cover @request.add_finished_callback def close_the_sqlalchemy_session(_request): # pylint: disable=unused-variable connections = ( - session.transaction._connections # pylint:disable=protected-access,no-member + session.transaction._connections # pylint:disable=protected-access ) if len(connections) > 1: LOG.warning("closing an unclosed DB session") - session.close() # pylint:disable=no-member + session.close() return session diff --git a/checkmate/migrations/env.py b/checkmate/migrations/env.py index 67134697..1892f594 100644 --- a/checkmate/migrations/env.py +++ b/checkmate/migrations/env.py @@ -1,5 +1,5 @@ # We didn't write this, so we don't care -# pylint: disable=fixme,no-member +# pylint: disable=no-member import os from logging.config import fileConfig @@ -7,6 +7,8 @@ from alembic import context from sqlalchemy import MetaData, engine_from_config, pool +from checkmate.db import NAMING_CONVENTIONS + # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config @@ -19,16 +21,7 @@ # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata -# FIXME: This duplicates the naming_convention in checkmate/db.py. -target_metadata = MetaData( - naming_convention={ - "ix": "ix__%(column_0_label)s", - "uq": "uq__%(table_name)s__%(column_0_name)s", - "ck": "ck__%(table_name)s__%(constraint_name)s", - "fk": "fk__%(table_name)s__%(column_0_name)s__%(referred_table_name)s", - "pk": "pk__%(table_name)s", - } -) +target_metadata = MetaData(naming_convention=NAMING_CONVENTIONS) # other values from the config, defined by the needs of env.py, # can be acquired: # my_important_option = config.get_main_option("my_important_option") diff --git a/requirements/lint.txt b/requirements/lint.txt index c20e6d58..d76fba08 100644 --- a/requirements/lint.txt +++ b/requirements/lint.txt @@ -13,7 +13,7 @@ amqp==5.0.2 # -r requirements/requirements.txt # -r requirements/tests.txt # kombu -astroid==2.4.2 +astroid==2.5.1 # via pylint attrs==20.3.0 # via @@ -232,7 +232,7 @@ pycparser==2.20 # cffi pydocstyle==5.1.1 # via -r requirements/lint.in -pylint==2.6.0 +pylint==2.7.2 # via -r requirements/lint.in pyparsing==2.4.7 # via @@ -314,7 +314,6 @@ six==1.15.0 # via # -r requirements/requirements.txt # -r requirements/tests.txt - # astroid # click-repl # cryptography # google-auth diff --git a/tests/.pylintrc b/tests/.pylintrc index caf186b3..f85ba0fd 100644 --- a/tests/.pylintrc +++ b/tests/.pylintrc @@ -27,3 +27,16 @@ disable=bad-continuation, [REPORTS] output-format=colorized score=no + +[SIMILARITIES] +# Minimum lines number of a similarity. +min-similarity-lines=4 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=yes