Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flake8 6.x compatibility #21

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 8 additions & 24 deletions flake8_copyright.py
Expand Up @@ -22,22 +22,6 @@
__version__ = '0.2.3'


# Temporary shim for flake8 2.x --> 3.x transition
# http://flake8.pycqa.org/en/latest/plugin-development/cross-compatibility.html#option-handling-on-flake8-2-and-3
def register_opt(parser, *args, **kwargs):
try:
# Flake8 3.x registration
parser.add_option(*args, **kwargs)
except (optparse.OptionError, TypeError):
# Flake8 2.x registration
parse_from_config = kwargs.pop('parse_from_config', False)
kwargs.pop('comma_separated_list', False)
kwargs.pop('normalize_paths', False)
parser.add_option(*args, **kwargs)
if parse_from_config:
parser.config_options.append(args[-1].lstrip('-'))


class CopyrightChecker(object):
name = 'flake8_copyright'
version = __version__
Expand All @@ -49,22 +33,22 @@ def __init__(self, tree, filename):

@classmethod
def add_options(cls, parser):
register_opt(
parser, '--copyright-check', action='store_true', parse_from_config=True,
parser.add_option(
'--copyright-check', action='store_true', parse_from_config=True,
help="Checks for copyright notices in every file."
)
register_opt(
parser, '--copyright-min-file-size', default=0, action='store', type='int',
parser.add_option(
'--copyright-min-file-size', default=0, action='store', type=int,
parse_from_config=True,
help="Minimum number of characters in a file before requiring a copyright notice."
)
register_opt(
parser, '--copyright-author', default='', action='store',
parser.add_option(
'--copyright-author', default='', action='store',
parse_from_config=True,
help="Checks for a specific author in the copyright notice."
)
register_opt(
parser, '--copyright-regexp',
parser.add_option(
'--copyright-regexp',
default=r"Copyright\s+(\(C\)\s+)?\d{4}([-,]\d{4})*\s+%(author)s",
action='store',
parse_from_config=True,
Expand Down