Use Click to parse command-line arguments in randomstart.py#12
Use Click to parse command-line arguments in randomstart.py#12nataliemes wants to merge 5 commits into
Conversation
|
Looks very nice. |
| "--higherdim", | ||
| default=3, | ||
| show_default=True, | ||
| help="Number of components in the probability vector being sampled", |
There was a problem hiding this comment.
change lines 90-91 to:
help="dimension [in 3..10] from which the middle 3 components will be sampled",
type=click.IntRange(3, 10),
metavar="INTEGER",
stengel
left a comment
There was a problem hiding this comment.
This is not the most recent file -
line 84 does not show MAX_ACCURACY and should have the following small amendments - see my email
help=f"Denominator N [in 1..{MAX_ACCURACY}]: each coordinate is rounded to the nearest multiple of 1/N",
type=click.IntRange(1, MAX_ACCURACY),
metavar="INTEGER",
There was a problem hiding this comment.
Pull request overview
This PR updates randomstart.py to use Click for command-line parsing and exposes it as an installable console script (randomstart) via pyproject.toml, improving CLI ergonomics and validation (notably for higherdim bounds).
Changes:
- Replace manual
sys.argvparsing inrandomstart.pywith a Click-based CLI (named flags + range validation). - Add
randomstart = "lemke.randomstart:main"console script entry point. - Add Click as a runtime dependency (and adjust dependency specifiers).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/lemke/randomstart.py | Introduces a Click CLI with typed/ranged options and adds accuracy validation used by both CLI and library callers. |
| pyproject.toml | Adds Click dependency and registers randomstart as a console script entry point; also modifies dependency version bounds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| dependencies = [ | ||
| "numpy>=2.2,<2.3", | ||
| "matplotlib>=3.10,<3.11" | ||
| "numpy>=2.2", | ||
| "matplotlib>=3.10", | ||
| "click>=8.1", | ||
| ] |
| def roundArray(x, accuracy=10000): | ||
| if not 1 <= accuracy <= MAX_ACCURACY: | ||
| raise ValueError(f"accuracy must be between 1 and {MAX_ACCURACY}") |
rahulsavani
left a comment
There was a problem hiding this comment.
This looks fine in terms of the changes done, but let's take this opportunity to add some tests.
See the test suggested in the copilot review for inspiration. Add as many obvious ones as you can think of for click's basic functionality.
This PR replaces manual command-line argument parsing with Click in
randomstart.py.Changes in detail
randomstartas a console script entry point, so it can be called directly from the terminal after installing the package (instead of callingpython randomstart.py).For example, both
randomstart --numpoints 500 --accuracy 10andrandomstart --accuracy 10 --numpoints 500are valid and mean the same thing.higherdimis outside the range [3, 10], instead of silently defaulting to 3.