Skip to content

Commit

Permalink
more flake8 checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Apr 10, 2019
1 parent d4c0e18 commit 43bfb3b
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 55 deletions.
8 changes: 4 additions & 4 deletions core/dbt/clients/_jinja_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ def _expect_match(self, expected_name, *patterns, **kwargs):
match = self._first_match(*patterns, **kwargs)
if match is None:
msg = 'unexpected EOF, expected {}, got "{}"'.format(
expected_name, self.data[self.pos:]
)
expected_name, self.data[self.pos:]
)
dbt.exceptions.raise_compiler_error(msg)
return match

Expand Down Expand Up @@ -316,8 +316,8 @@ def _process_macro_default_arg(self):
if match.end() - match.start() == 1:
msg = (
'Unclosed quotation mark at position {}. Context:\n{}'
.format(self.pos, self.data[self.pos-20:self.pos+20])
)
.format(self.pos,
self.data[self.pos - 20:self.pos + 20]))
dbt.exceptions.raise_compiler_error(msg)
elif matchgroups.get('comma') is not None:
# small hack: if we hit a comma and there is one parenthesis
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _compile(self, source, filename):
linecache.cache[filename] = (
len(source),
None,
[line+'\n' for line in source.splitlines()],
[line + '\n' for line in source.splitlines()],
filename
)

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def tables(self):
'type': 'string',
'description': (
'Relative path to the originating file from the project root.'
),
),
},
'file_contents': {
'type': 'string',
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/contracts/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def skipped(self):
'type': 'array',
'items': {
'anyOf': [
RUN_MODEL_RESULT_CONTRACT,
PARTIAL_RESULT_CONTRACT,
RUN_MODEL_RESULT_CONTRACT,
PARTIAL_RESULT_CONTRACT,
]
},
'description': 'An array of results, one per model',
Expand Down
9 changes: 5 additions & 4 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ def __init__(self, typename, errors):
self.typename = typename
self.errors = errors
self.errors_message = ', '.join(errors)
msg = ('Invalid arguments passed to "{}" instance: {}'.format(
self.typename, self.errors_message))
msg = 'Invalid arguments passed to "{}" instance: {}'.format(
self.typename, self.errors_message
)
super(JSONValidationException, self).__init__(msg)

def __reduce__(self):
Expand Down Expand Up @@ -592,8 +593,8 @@ def raise_ambiguous_catalog_match(unique_id, match_1, match_2):

def get_match_string(match):
return "{}.{}".format(
match.get('metadata', {}).get('schema'),
match.get('metadata', {}).get('name'))
match.get('metadata', {}).get('schema'),
match.get('metadata', {}).get('name'))

raise_compiler_error(
'dbt found two relations in your warehouse with similar database '
Expand Down
6 changes: 4 additions & 2 deletions core/dbt/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,14 @@ def _check_resource_uniqueness(manifest):
existing_node = names_resources.get(name)
if existing_node is not None:
dbt.exceptions.raise_duplicate_resource_name(
existing_node, node)
existing_node, node
)

existing_alias = alias_resources.get(alias)
if existing_alias is not None:
dbt.exceptions.raise_ambiguous_alias(
existing_alias, node)
existing_alias, node
)

names_resources[name] = node
alias_resources[alias] = node
Expand Down
6 changes: 3 additions & 3 deletions core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ def _build_source_subparser(subparsers, base_subparser):

def _build_init_subparser(subparsers, base_subparser):
sub = subparsers.add_parser(
'init',
parents=[base_subparser],
help="Initialize a new DBT project.")
'init',
parents=[base_subparser],
help="Initialize a new DBT project.")
sub.add_argument('project_name', type=str, help='Name of the new project')
sub.set_defaults(cls=init_task.InitTask, which='init')
return sub
Expand Down
23 changes: 12 additions & 11 deletions core/dbt/node_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,22 @@ def _handle_internal_exception(self, e, ctx):
prefix = 'Internal error executing {}'.format(build_path)

error = "{prefix}\n{error}\n\n{note}".format(
prefix=dbt.ui.printer.red(prefix),
error=str(e).strip(),
note=INTERNAL_ERROR_STRING)
prefix=dbt.ui.printer.red(prefix),
error=str(e).strip(),
note=INTERNAL_ERROR_STRING
)
logger.debug(error)
return dbt.compat.to_string(e)

def _handle_generic_exception(self, e, ctx):
node_description = self.node.get('build_path')
if node_description is None:
node_description = self.node.unique_id
prefix = "Unhandled error while executing {description}".format(
description=node_description)

prefix = "Unhandled error while executing {}".format(node_description)
error = "{prefix}\n{error}".format(
prefix=dbt.ui.printer.red(prefix),
error=str(e).strip())
prefix=dbt.ui.printer.red(prefix),
error=str(e).strip()
)

logger.error(error)
logger.debug('', exc_info=True)
Expand Down Expand Up @@ -487,9 +487,10 @@ def after_execute(self, result):
class ArchiveRunner(ModelRunner):
def describe_node(self):
cfg = self.node.get('config', {})
return "archive {name} --> "\
"{target_database}.{target_schema}.{name}".format(
name=self.node.name, **cfg)
return (
"archive {name} --> {target_database}.{target_schema}.{name}"
.format(name=self.node.name, **cfg)
)

def print_result_line(self, result):
dbt.ui.printer.print_archive_result_line(result, self.node_index,
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _filter_validate(filepath, location, values, validate):
except dbt.exceptions.JSONValidationException as exc:
# we don't want to fail the full run, but we do want to fail
# parsing this file
warn_invalid(filepath, location, value, '- '+exc.msg)
warn_invalid(filepath, location, value, '- ' + exc.msg)
continue


Expand Down Expand Up @@ -383,7 +383,7 @@ def _build_raw_sql(self, test_namespace, target, test_type, test_args):

def _generate_test_name(self, target, test_type, test_args):
return get_nice_schema_test_name(
'source_'+test_type,
'source_' + test_type,
'{}_{}'.format(target['source']['name'], target['table']['name']),
test_args
)
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/parser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def process_refs_for_node(cls, manifest, current_project, node):
# this node to the graph b/c there is no destination node
node.config['enabled'] = False
dbt.utils.invalid_ref_fail_unless_test(
node, target_model_name, target_model_package,
disabled=(target_model is cls.DISABLED)
node, target_model_name, target_model_package,
disabled=(target_model is cls.DISABLED)
)

continue
Expand Down
11 changes: 6 additions & 5 deletions core/dbt/rpc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from jsonrpc.exceptions import JSONRPCDispatchException, \
JSONRPCInvalidParams, \
JSONRPCParseError, \
JSONRPCInvalidRequestException, \
JSONRPCInvalidRequest
from jsonrpc.exceptions import \
JSONRPCDispatchException, \
JSONRPCInvalidParams, \
JSONRPCParseError, \
JSONRPCInvalidRequestException, \
JSONRPCInvalidRequest
from jsonrpc import JSONRPCResponseManager
from jsonrpc.jsonrpc import JSONRPCRequest
from jsonrpc.jsonrpc2 import JSONRPC20Response
Expand Down
8 changes: 5 additions & 3 deletions core/dbt/semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
alpha_no_leading_zeros=_ALPHA_NO_LEADING_ZEROS,
alpha=_ALPHA)

_VERSION_REGEX = re.compile(r"""

_VERSION_REGEX_PAT_STR = r"""
^
{matchers}
{base_version_regex}
Expand All @@ -39,8 +40,9 @@
""".format(
matchers=_MATCHERS,
base_version_regex=_BASE_VERSION_REGEX,
version_extra_regex=_VERSION_EXTRA_REGEX),
re.VERBOSE)
version_extra_regex=_VERSION_EXTRA_REGEX)

_VERSION_REGEX = re.compile(_VERSION_REGEX_PAT_STR, re.VERBOSE)


class Matchers:
Expand Down
7 changes: 4 additions & 3 deletions core/dbt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def merge(*args):
return args[0]

lst = list(args)
last = lst.pop(len(lst)-1)
last = lst.pop(len(lst) - 1)

return _merge(merge(*lst), last)

Expand All @@ -190,7 +190,7 @@ def deep_merge(*args):
return copy.deepcopy(args[0])

lst = list(args)
last = copy.deepcopy(lst.pop(len(lst)-1))
last = copy.deepcopy(lst.pop(len(lst) - 1))

return _deep_merge(deep_merge(*lst), last)

Expand Down Expand Up @@ -422,7 +422,8 @@ def parse_cli_vars(var_string):
"of type '{}'".format(type_name))
except dbt.exceptions.ValidationException:
logger.error(
"The YAML provided in the --vars argument is not valid.\n")
"The YAML provided in the --vars argument is not valid.\n"
)
raise


Expand Down
10 changes: 5 additions & 5 deletions plugins/redshift/dbt/adapters/redshift/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def fetch_cluster_credentials(cls, db_user, db_name, cluster_id,

except boto_client.exceptions.ClientError as e:
raise dbt.exceptions.FailedToConnectException(
"Unable to get temporary Redshift cluster credentials: "
"{}".format(e))
"Unable to get temporary Redshift cluster credentials: {}"
.format(e))

@classmethod
def get_tmp_iam_cluster_credentials(cls, credentials):
Expand All @@ -136,8 +136,8 @@ def get_tmp_iam_cluster_credentials(cls, credentials):

if not cluster_id:
raise dbt.exceptions.FailedToConnectException(
"'cluster_id' must be provided in profile if IAM "
"authentication method selected")
"'cluster_id' must be provided in profile if IAM "
"authentication method selected")

cluster_creds = cls.fetch_cluster_credentials(
credentials.user,
Expand Down Expand Up @@ -167,4 +167,4 @@ def get_credentials(cls, credentials):

else:
raise dbt.exceptions.FailedToConnectException(
"Invalid 'method' in profile: '{}'".format(method))
"Invalid 'method' in profile: '{}'".format(method))
12 changes: 6 additions & 6 deletions plugins/snowflake/dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ def add_query(self, sql, auto_begin=True,

if cursor is None:
raise dbt.exceptions.RuntimeException(
"Tried to run an empty query on model '{}'. If you are "
"conditionally running\nsql, eg. in a model hook, make "
"sure your `else` clause contains valid sql!\n\n"
"Provided SQL:\n{}"
.format(self.nice_connection_name(), sql)
)
"Tried to run an empty query on model '{}'. If you are "
"conditionally running\nsql, eg. in a model hook, make "
"sure your `else` clause contains valid sql!\n\n"
"Provided SQL:\n{}"
.format(self.nice_connection_name(), sql)
)

return connection, cursor

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ envlist = unit-py27, unit-py36, integration-postgres-py27, integration-postgres-

[testenv:flake8]
basepython = python3.6
commands = /bin/bash -c '$(which flake8) core/dbt plugins/*/dbt'
commands = /bin/bash -c '$(which flake8) --select=E,W,F --ignore=W504 core/dbt plugins/*/dbt'
deps =
-r{toxinidir}/dev_requirements.txt

Expand Down

0 comments on commit 43bfb3b

Please sign in to comment.