Skip to content

Argparse "Overlay" Module #12873

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

Merged
merged 12 commits into from
Nov 28, 2017
Merged

Conversation

Rostepher
Copy link
Contributor

@Rostepher Rostepher commented Nov 11, 2017

Purpose

This PR is meant to supersede #11827. Rather than one large PR that introduces an entire DSL and refactors the very large argument parsing logic all at once, it seemed better to introduce the argument parsing DSL separately and then in follow-up PRs complete the refactoring. I've used @rintaro's work from #2190 to construct a wrapper module, or overlay if you will, around the standard python argparse which exposes the exact same API with some extras on top. Specifically there's now a bunch of new action classes which handle multiple destinations, a new builder class on the ArgumentParser and lastly a handful of new *Type classes.

The entire module is thoroughly tested and I'll be following this up with subsequent PRs to convert the argument parser piece-wise.

rdar://34336890

zisko
zisko previously requested changes Nov 13, 2017
Copy link
Contributor

@zisko zisko left a comment

Choose a reason for hiding this comment

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

Other than adding docstrings explaining how to use this new argument parser shim and what is happening in this module, everything here looks like a solid addition to our argument parsing logic. As long as the changes going forward don't break backwards compatibility with our build presets, then this looks good to me.

# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors


Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a docstring explaining what this module is intended to do so it is used appropriately in the future :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, I'll add those in a bit.

# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors


Copy link
Contributor

Choose a reason for hiding this comment

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

docstring here as well.

@Rostepher
Copy link
Contributor Author

@rintaro If you have the time would you mind taking a look at this PR?

@Rostepher
Copy link
Contributor Author

In case anyone is wondering the unit-tests can be run via the command python -m unittest discover -t utils/ -s utils/build_swift

@swiftlang swiftlang deleted a comment from swift-ci Nov 15, 2017
@swiftlang swiftlang deleted a comment from shahmishal Nov 15, 2017
@swiftlang swiftlang deleted a comment from swift-ci Nov 15, 2017
@swiftlang swiftlang deleted a comment from swift-ci Nov 15, 2017
@swiftlang swiftlang deleted a comment from swift-ci Nov 15, 2017
@swiftlang swiftlang deleted a comment from swift-ci Nov 15, 2017
@swiftlang swiftlang deleted a comment from swift-ci Nov 15, 2017
@swiftlang swiftlang deleted a comment from swift-ci Nov 15, 2017
@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher
Copy link
Contributor Author

@swift-ci please smoke test

@Rostepher
Copy link
Contributor Author

@swift-ci please Python lint

@Rostepher
Copy link
Contributor Author

@swift-ci please test OSX

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 77a525e6b96ea69045025ebf0fa079de27d71df4

@modocache
Copy link
Contributor

In case anyone is wondering the unit-tests can be run via the command python -m unittest discover -t utils/ -s utils/build_swift

Sorry if I'm missing something -- have you thought about running these tests automatically, by adding a file like this one?

@Rostepher
Copy link
Contributor Author

Rostepher commented Nov 16, 2017

I'm hesitant to add these unit-tests to the main suite because they take ~2 minutes to run thanks to build-script-impl. If that extra time is not an issue then I'll be happy to add them.

To elaborate, the argument parser tests attempt to verify every single preset is valid by running the arguments not only through the python parser, but also through build-script-impl. It's really the need to spawn a new subprocess for each of the presets that takes so long. Otherwise the entire suite would take only a few seconds.

…ean-like values and replaces the hard-coded boolean values in the _ToggleAction class.
…imports, so now the unit-tests will actually run as expected. The README has also been updated with a better command for executing the unit-test suite.
… to only take a single action or default to the store action.
@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher
Copy link
Contributor Author

@swift-ci please smoke test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - c2c006d24b7b9820aede901235745190626ca920

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - c2c006d24b7b9820aede901235745190626ca920

@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher
Copy link
Contributor Author

@swift-ci please smoke test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3b0dd5d

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3b0dd5d

@Rostepher
Copy link
Contributor Author

@swift-ci please test

@Rostepher
Copy link
Contributor Author

@swift-ci please smoke test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 16614b46aaa40ad1df8c93262b1da8c6cb014789

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 16614b46aaa40ad1df8c93262b1da8c6cb014789

@lplarson
Copy link
Contributor

Once @zisko's changes are added, LGTM.

@Rostepher Rostepher dismissed zisko’s stale review November 28, 2017 01:11

I've added the requested changes.

@zisko
Copy link
Contributor

zisko commented Nov 28, 2017

LGTM

@zisko zisko self-requested a review November 28, 2017 01:16
@Rostepher Rostepher merged commit 85abdcd into swiftlang:master Nov 28, 2017
@Rostepher Rostepher deleted the argparse-module branch November 28, 2017 05:49
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.

6 participants