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

[PR #825/4f67a3a9 backport][release_2.0] Do not rely on length of sys.argv #842

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Sep 21, 2021

This is a backport of PR #825 as merged into devel (4f67a3a).

From the current behavior, it seems the goal is to print a common usage message and exit 0 if no sub command was given. Under other circumstances, such as an invalid or missing parameter, exit with 2 and print the normal usage message.

In order to preserve this behavior and make the tests run consistently whether or not they are run in multiple process, a custom error method was created that inspects the error message and exits 0 with the common usage message if no command was given. This is a bit fragile, but inside that method we do not have easy access to arguments passed to the main() function (they could be inferred by inspecting private attributes, but this is probably unwise).

This requires catching the SystemExit in the main() function and deciding there based on sys_args how to handle it.

This fix preservers the existing behavior whil making the tests pass consistently. However, it would be much simpler to rely on the default behavior of argparse and exit 2 in both cases. This would remove the need for a custom error method and exception handling. It would be a change in behavior, though.

Related to #815.

Do not rely on length of sys.argv

From the current behavior, it seems the goal is to print a common usage message and exit 0 if no sub command was given. Under other circumstances, such as an invalid or missing parameter, exit with 2 and print the normal usage message.
In order to preserve this behavior and make the tests run consistently whether or not they are run in multiple process, a custom error method was created that inspects the error message and exits 0 with the common usage message if no command was given. This is a bit fragile, but inside that method we do not have easy access to arguments passed to the main() function (they could be inferred by inspecting private attributes, but this is probably unwise).
This requires catching the SystemExit in the main() function and deciding there based on sys_args how to handle it.
This fix preservers the existing behavior whil making the tests pass consistently. However, it would be much simpler to rely on the default behavior of argparse and exit 2 in both cases. This would remove the need for a custom error method and exception handling. It would be a change in behavior, though.
Related to #815.

Reviewed-by: Alan Rominger <arominge@redhat.com>
Reviewed-by: Sam Doran <sdoran@redhat.com>
Reviewed-by: David Shrewsbury <None>
Reviewed-by: None <None>
(cherry picked from commit 4f67a3a)
@Shrews Shrews added the gate label Sep 22, 2021
Copy link
Contributor

@ansible-zuul ansible-zuul bot left a comment

Choose a reason for hiding this comment

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

LGTM!

@ansible-zuul ansible-zuul bot merged commit 17c62ca into release_2.0 Sep 22, 2021
@shanemcd shanemcd deleted the patchback/backports/release_2.0/4f67a3a9e2f20e5d4da313958881eeef67397011/pr-825 branch October 6, 2021 16:35
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.

1 participant