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 exclude regression #387

Merged
merged 3 commits into from
Jun 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions ament_flake8/ament_flake8/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import flake8
from flake8.api.legacy import StyleGuide
from flake8.main import application as flake8_app
from flake8.main import options as flake8_options


def main(argv=sys.argv[1:]):
Expand Down Expand Up @@ -173,7 +174,39 @@ def get_flake8_style_guide(argv):
return StyleGuide(application)


def parse_config_file(config_file):
from flake8.options import config, manager, aggregator

try:
# Support 4.0.0
opts_manager = manager.OptionManager(prog='flake8', version='4.0.0')
flake8_options.register_default_options(opts_manager)

return aggregator.aggregate_options(
opts_manager,
config.ConfigFileFinder('flake8', [], config_file),
[]
)
except TypeError:
opts_manager = manager.OptionManager(prog='flake8', version='3.0.0')
flake8_options.register_default_options(opts_manager)

return aggregator.aggregate_options(
opts_manager,
config.ConfigFileFinder('flake8', [], [config_file]),
[]
)


def generate_flake8_report(config_file, paths, excludes, max_line_length=None):
opts, _ = parse_config_file(config_file)

# Ignore flake8 defaults here
if opts.exclude != list(flake8_options.defaults.EXCLUDE):
# Explicitly append to exclude args to prevent config excludes
# from being overwritten
excludes.extend(opts.exclude)

flake8_argv = []
if config_file is not None:
flake8_argv.append('--config={0}'.format(config_file))
Expand Down