diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..ff28fee5f --- /dev/null +++ b/.flake8 @@ -0,0 +1,15 @@ +[flake8] + +# We have YAPF set to wrap at 80, but that's not always possible, so we set the +# limit a bit higher here. +max-line-length = 100 + +# Ignore + +# E111 indentation is not a multiple of four +# E121 continuation line under-indented for hanging indent +# E126 continuation line over-indented for hanging indent +# E261 at least two spaces before inline comment + +ignore = E111,E121,E126,E261 + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5742d7618..ddf023707 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,14 @@ +- repo: git://github.com/pre-commit/pre-commit-hooks + sha: a11d9314b22d8f8c7556443875b731ef05965464 + hooks: + - id: trailing-whitespace - repo: git://github.com/pre-commit/mirrors-yapf - sha: v0.16.0 + sha: v0.16.0 hooks: - id: yapf - args: [--in-place, --style=./yapf_style.cfg] - + args: + - --in-place +- repo: git://github.com/pre-commit/pre-commit-hooks + sha: a11d9314b22d8f8c7556443875b731ef05965464 + hooks: + - id: flake8 diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 000000000..64acdb545 --- /dev/null +++ b/.style.yapf @@ -0,0 +1,50 @@ +[style] +based_on_style = pep8 + +ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT = True + +ALLOW_MULTILINE_DICTIONARY_KEYS = False +ALLOW_MULTILINE_LAMBDAS = True + +BLANK_LINE_BEFORE_CLASS_DOCSTRING = False +BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = False + +COALESCE_BRACKETS = True + +COLUMN_LIMIT = 80 + +CONTINUATION_INDENT_WIDTH = 2 + +DEDENT_CLOSING_BRACKETS = True + +EACH_DICT_ENTRY_ON_SEPARATE_LINE = True + +INDENT_DICTIONARY_VALUE = True +INDENT_WIDTH = 2 + +JOIN_MULTIPLE_LINES = False + +SPACE_BETWEEN_ENDING_COMMA_AND_CLOSING_BRACKET = False + +SPACES_AROUND_DEFAULT_OR_NAMED_ASSIGN = False +SPACES_AROUND_POWER_OPERATOR = False +SPACES_BEFORE_COMMENT = 1 + +SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED = True + +SPLIT_BEFORE_BITWISE_OPERATOR = False +SPLIT_BEFORE_DICT_SET_GENERATOR = False +SPLIT_BEFORE_FIRST_ARGUMENT = True +SPLIT_BEFORE_LOGICAL_OPERATOR = False +SPLIT_BEFORE_NAMED_ASSIGNS = False + +SPLIT_PENALTY_AFTER_OPENING_BRACKET = 30 +SPLIT_PENALTY_AFTER_UNARY_OPERATOR = 10000 +SPLIT_PENALTY_BEFORE_IF_EXPR = 50 +SPLIT_PENALTY_BITWISE_OPERATOR = 300 +SPLIT_PENALTY_EXCESS_CHARACTER = 200 +SPLIT_PENALTY_FOR_ADDED_LINE_SPLIT = 30 +SPLIT_PENALTY_IMPORT_NAMES = 0 +SPLIT_PENALTY_LOGICAL_OPERATOR = 300 + +USE_TABS = False diff --git a/d1_common_python/src/d1_common/cert/subject_info.py b/d1_common_python/src/d1_common/cert/subject_info.py index 7bb7a6bb8..fb199bcf1 100644 --- a/d1_common_python/src/d1_common/cert/subject_info.py +++ b/d1_common_python/src/d1_common/cert/subject_info.py @@ -20,7 +20,7 @@ """Extract a set of subjects from a DataONE SubjectInfo structure Subjects are extracted from the SubjectInfo using the following algorithm: - + - Start with empty set of subjects - Perform recursive search with detection of circular dependencies, starting with Subject. @@ -38,9 +38,6 @@ - Recursively add those subjects. """ -# Stdlib -import logging - # 3rd party import pyxb @@ -52,7 +49,7 @@ def extract_subjects(subject_info_xml, primary_str): """Extract a set of equivalent and group membership subjects from SubjectInfo - + {primary_str} is a DataONE subject, typically a DataONE compliant serialization of the DN of the DataONE X.509 v3 certificate extension from which the SubjectInfo was extracted. @@ -114,7 +111,7 @@ def _add_person_is_member_of(equivalent_set, subject_info_pyxb, person_pyxb): def _add_person_equivalent_subjects( - equivalent_set, subject_info_pyxb, person_pyxb + equivalent_set, subject_info_pyxb, person_pyxb ): for equivalent_pyxb in person_pyxb.equivalentIdentity: _add_subject(equivalent_set, subject_info_pyxb, equivalent_pyxb.value()) diff --git a/d1_common_python/src/d1_common/cert/x509.py b/d1_common_python/src/d1_common/cert/x509.py index a7b7fc53e..eea993dc4 100644 --- a/d1_common_python/src/d1_common/cert/x509.py +++ b/d1_common_python/src/d1_common/cert/x509.py @@ -84,14 +84,12 @@ def _deserialize_pem(cert_pem): def _extract_dataone_subject_from_dn(cert_obj): return ( ','.join( - reversed( - [ - '{}={}'.format( - OID_TO_SHORT_NAME_DICT. - get(v.oid.dotted_string, v.oid.dotted_string), _escape(v.value) - ) for v in cert_obj.subject - ] - ) + reversed([ + '{}={}'.format( + OID_TO_SHORT_NAME_DICT.get(v.oid.dotted_string, v.oid.dotted_string), + _escape(v.value) + ) for v in cert_obj.subject + ]) ) ) diff --git a/yapf_style.cfg b/yapf_style.cfg deleted file mode 100644 index f25003722..000000000 --- a/yapf_style.cfg +++ /dev/null @@ -1,129 +0,0 @@ -[style] -based_on_style = pep8 - -SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED = True - -#ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT=True -# Align closing bracket with visual indentation. - -#ALLOW_MULTILINE_LAMBDAS=False -# Allow lambdas to be formatted on more than one line. - -#BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=False -# Insert a blank line before a 'def' or 'class' immediately nested -# within another 'def' or 'class'. -# -# For example: -# -# class Foo: -# # <------ this blank line -# def method(): -# ... - -COLUMN_LIMIT=80 -# The column limit. - -CONTINUATION_INDENT_WIDTH=2 -# Indent width used for line continuations. - -DEDENT_CLOSING_BRACKETS=True -# Put closing brackets on a separate line, dedented, if the bracketed -# expression can't fit in a single line. Applies to all kinds of brackets, -# including function definitions and calls. -# -# For example: -# -# config = { -# 'key1': 'value1', -# 'key2': 'value2', -# } # <--- this bracket is dedented and on a separate line -# -# time_series = self.remote_client.query_entity_counters( -# entity='dev3246.region1', -# key='dns.query_latency_tcp', -# transform=Transformation.AVERAGE(window=timedelta(seconds=60)), -# start_ts=now()-timedelta(days=3), -# end_ts=now(), -# ) # <--- this bracket is dedented and on a separate line - -#I18N_COMMENT= -# The regex for an i18n comment. The presence of this comment stops -# reformatting of that line, because the comments are required to be -# next to the string they translate. - -#I18N_FUNCTION_CALL= -# The i18n function call names. The presence of this function stops -# reformattting on that line, because the string it has cannot be moved -# away from the i18n comment. - -INDENT_DICTIONARY_VALUE=True -# Indent the dictionary value if it cannot fit on the same line as the -# dictionary key. -# -# For example: -# -# config = { -# 'key1': -# 'value1', -# 'key2': value1 + -# value2, -# } - -INDENT_WIDTH=2 -# The number of columns to use for indentation. - -JOIN_MULTIPLE_LINES=False -# Join short lines into one line. E.g., single line 'if' statements. - -SPACES_AROUND_POWER_OPERATOR=False -# Use spaces around the power operator. - -SPACES_BEFORE_COMMENT=1 -# The number of spaces required before a trailing comment. - -SPACE_BETWEEN_ENDING_COMMA_AND_CLOSING_BRACKET=False -# Insert a space between the ending comma and closing bracket of a list, -# etc. - -SPLIT_BEFORE_BITWISE_OPERATOR=False -# Set to True to prefer splitting before '&', '|' or '^' rather than after. - -SPLIT_BEFORE_LOGICAL_OPERATOR=False -# Set to True to prefer splitting before 'and' or 'or' rather than after. - -SPLIT_BEFORE_NAMED_ASSIGNS=False -# Split named assignments onto individual lines. - -SPLIT_PENALTY_AFTER_OPENING_BRACKET=30 -# The penalty for splitting right after the opening bracket. - -SPLIT_PENALTY_AFTER_UNARY_OPERATOR=10000 -# The penalty for splitting the line after a unary operator. - -SPLIT_PENALTY_BITWISE_OPERATOR=300 -# The penalty of splitting the line around the '&', '|', and '^' operators. - -SPLIT_PENALTY_EXCESS_CHARACTER=200 -# The penalty for characters over the column limit. - -SPLIT_PENALTY_FOR_ADDED_LINE_SPLIT=30 -# The penalty incurred by adding a line split to the unwrapped line. The -# more line splits added the higher the penalty. - -SPLIT_PENALTY_IMPORT_NAMES=0 -# The penalty of splitting a list of "import as" names. -# -# For example: -# -# from a_very_long_or_indented_module_name_yada_yad import (long_argument_1, -# long_argument_2, -# long_argument_3) -# -# would reformat to something like: -# -# from a_very_long_or_indented_module_name_yada_yad import ( -# long_argument_1, long_argument_2, long_argument_3) - -SPLIT_PENALTY_LOGICAL_OPERATOR=300 -# The penalty of splitting the line around the 'and' and 'or' operators. -