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 with ament_flake8 #77

Merged
merged 1 commit into from
Jun 21, 2017
Merged

fix --exclude with ament_flake8 #77

merged 1 commit into from
Jun 21, 2017

Conversation

dirk-thomas
Copy link
Contributor

No description provided.

@dirk-thomas dirk-thomas added the in review Waiting for review (Kanban column) label Jun 21, 2017
@dirk-thomas dirk-thomas self-assigned this Jun 21, 2017
Copy link
Contributor

@dhood dhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for that

flake8_argv.append('--exclude={0}'.format(excludes))
if config_file is not None:
flake8_argv.append('--config={0}'.format(config_file))
if excludes is not None:
Copy link
Contributor

@dhood dhood Jun 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the check to if not excludes: will give consistent behaviour with the other linters (including flake8 v2) in the event the list is empty. Unless there's a reason this check is more appropriate, could you update it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand. The variable excludes is either None or a not empty list. How would it be an empty list?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding it could be an empty list if a user specifies the --exclude option, but with no filenames

Copy link
Contributor Author

@dirk-thomas dirk-thomas Jun 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not possible. argparse won't allow you to do that with the current settings.

Also in that case I think the line you commented on is doing exactly the right thing: excludes is not None and therefore calls the script with --excluded=. (which would be what the user asked for).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which setting makes it not possible? From what I've seen '--foo --bar 1 2 will make foo an empty list if it's an nargs='*' option.

My concern was consistency with the v2.x implementation, since it doesn't use the argument if it's []. but after re-looking at it, the end result will still turn out the same as 2.x with this implementation, so I'm fine to leave it as is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you try to run ament_flake8 --exclude the result will be:

Usage: flake8 [options] file file ...

flake8: error: --exclude option requires 1 argument

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, here's an example of how it can be an empty list:

In [1]: import argparse

In [2]: parser = argparse.ArgumentParser()

In [3]: parser.add_argument('--foo', nargs='*')
Out[3]: _StoreAction(option_strings=['--foo'], dest='foo', nargs='*', const=None, default=None, type=None, choices=None, help=None, metavar=None)

In [4]: parser.add_argument('--bar', nargs='*')
Out[4]: _StoreAction(option_strings=['--bar'], dest='bar', nargs='*', const=None, default=None, type=None, choices=None, help=None, metavar=None)

In [5]: parser.parse_args('--foo --bar 1 2'.split())
Out[5]: Namespace(bar=['1', '2'], foo=[])

it's strange that argparse has different behaviour base on its position in the list (strange to me, at least!)

@dirk-thomas dirk-thomas merged commit bf2d44e into master Jun 21, 2017
@dirk-thomas dirk-thomas deleted the fix_flake8_excludes branch June 21, 2017 22:06
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants