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

Add config file support to ament_pep257 #476

Open
wants to merge 5 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 18 additions & 3 deletions ament_pep257/ament_pep257/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def main(argv=sys.argv[1:]):
default=[],
help='Choose the basic list of error codes for pydocstyle to check for.'
)
err_code_group.add_argument(
'--config',
metavar='path',
dest='config_file',
help='The config file'
)
err_code_group.add_argument(
'--convention',
choices=_conventions,
Expand Down Expand Up @@ -114,16 +120,21 @@ def main(argv=sys.argv[1:]):
if args.xunit_file:
start_time = time.time()

if args.config_file and not os.path.exists(args.config_file):
print("Could not find config file '{}'".format(args.config_file), file=sys.stderr)
return 1

args.ignore = ','.join(args.ignore)
args.select = ','.join(args.select)
args.add_select = ','.join(args.add_select)
args.add_ignore = ','.join(args.add_ignore)
if not (args.ignore or args.select) and args.convention == 'ament':
if not (args.ignore or args.select or args.config_file) and args.convention == 'ament':
args.ignore = ','.join(_ament_ignore)

excludes = [os.path.abspath(e) for e in args.excludes]
report = generate_pep257_report(args.paths, excludes, args.ignore, args.select,
args.convention, args.add_ignore, args.add_select)
args.convention, args.add_ignore, args.add_select,
args.config_file)
error_count = sum(len(r[1]) for r in report)

# print summary
Expand Down Expand Up @@ -161,7 +172,8 @@ def _filename_in_excludes(filename, excludes):
return any(os.path.commonpath([absname, e]) == e for e in excludes)


def generate_pep257_report(paths, excludes, ignore, select, convention, add_ignore, add_select):
def generate_pep257_report(paths, excludes, ignore, select, convention, add_ignore, add_select,
config_file):
conf = ConfigurationParser()
sys_argv = sys.argv
sys.argv = [
Expand All @@ -173,12 +185,15 @@ def generate_pep257_report(paths, excludes, ignore, select, convention, add_igno
sys.argv += ['--ignore', ignore]
elif select:
sys.argv += ['--select', select]
elif config_file:
sys.argv += ['--config', config_file]
else:
sys.argv += ['--convention', convention]
if add_ignore:
sys.argv += ['--add-ignore', add_ignore]
if add_select:
sys.argv += ['--add-select', add_select]

sys.argv += paths
conf.parse()
sys.argv = sys_argv
Expand Down
4 changes: 2 additions & 2 deletions ament_pep257/test/test_generate_pep257_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
def test_invalid_file():
ignore = ','.join(_ament_ignore)

report = generate_pep257_report(['non_existent_file.py'], [], ignore, [], 'ament', [], [])
report = generate_pep257_report(['non_existent_file.py'], [], ignore, [], 'ament', [], [], [])
assert len(report) == 1
filename, errors = report[0]
assert filename == 'non_existent_file.py'
Expand All @@ -40,7 +40,7 @@ def test_valid_file():
py_file = temp_dir / 'foobar.py'
py_file.write_text('a = 1+2\n')

report = generate_pep257_report([str(temp_dir)], [], ignore, [], 'ament', [], [])
report = generate_pep257_report([str(temp_dir)], [], ignore, [], 'ament', [], [], [])

assert len(report) == 1
filename, errors = report[0]
Expand Down