Skip to content

Use Click to parse command-line arguments in randomstart.py#12

Open
nataliemes wants to merge 5 commits into
gambitproject:mainfrom
nataliemes:refactor/click-cli-randomstart
Open

Use Click to parse command-line arguments in randomstart.py#12
nataliemes wants to merge 5 commits into
gambitproject:mainfrom
nataliemes:refactor/click-cli-randomstart

Conversation

@nataliemes

Copy link
Copy Markdown
Collaborator

This PR replaces manual command-line argument parsing with Click in randomstart.py.

Changes in detail

  • Added randomstart as a console script entry point, so it can be called directly from the terminal after installing the package (instead of calling python randomstart.py).
  • Arguments are now named flags, so order no longer matters.
    For example, both randomstart --numpoints 500 --accuracy 10 and randomstart --accuracy 10 --numpoints 500 are valid and mean the same thing.
  • An automatic error is shown if higherdim is outside the range [3, 10], instead of silently defaulting to 3.

@nataliemes nataliemes requested review from rahulsavani and stengel June 4, 2026 13:25
@stengel

stengel commented Jun 4, 2026

Copy link
Copy Markdown
Member

Looks very nice.
One more request: Please check that accuracy is an integer between 1 and MAXACCURACY
where I would set MAXACCURACY to 10 million at the top of the file, 10000000.

@stengel stengel closed this Jun 4, 2026
@stengel stengel reopened this Jun 4, 2026
Comment thread src/lemke/randomstart.py Outdated
"--higherdim",
default=3,
show_default=True,
help="Number of components in the probability vector being sampled",

@stengel stengel Jun 5, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 stengel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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",

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.argv parsing in randomstart.py with 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.

Comment thread pyproject.toml
Comment on lines 8 to 12
dependencies = [
"numpy>=2.2,<2.3",
"matplotlib>=3.10,<3.11"
"numpy>=2.2",
"matplotlib>=3.10",
"click>=8.1",
]
Comment thread src/lemke/randomstart.py
Comment on lines 35 to +37
def roundArray(x, accuracy=10000):
if not 1 <= accuracy <= MAX_ACCURACY:
raise ValueError(f"accuracy must be between 1 and {MAX_ACCURACY}")

@rahulsavani rahulsavani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@nataliemes nataliemes requested a review from rahulsavani June 11, 2026 07:14
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.

4 participants