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

Use click.IntRange type to catch integer values < 1 instead of manually checking max_cpu_slices #459

Open
yousefmoazzam opened this issue Oct 2, 2024 · 0 comments
Labels
minor Nice to do but not vital

Comments

@yousefmoazzam
Copy link
Collaborator

The --max-cpu-slices flag has type click.INT which allows for integers < 1:

httomo/httomo/cli.py

Lines 86 to 91 in 6af2e2e

@click.option(
"--max-cpu-slices",
type=click.INT,
default=64,
help="Maximum number of slices to use for a block for CPU-only sections (default: 64)",
)

However, for the maximum number of CPU slices, a value < 1 doesn't make sense, and thus there is a bit of code manually checking if the given value is < 1:

httomo/httomo/cli.py

Lines 200 to 201 in 6af2e2e

if max_cpu_slices < 1:
raise ValueError("max-cpu-slices must be greater or equal to 1")

Click provides the type click.IntRange which allows for specifying a certain range. In particular, it can be used to provide a boundary on one side of the range, and have the other side of the range be unbounded. This would allow clipping the range of the max CPU slices to not be below 1, but still be anything above 1.

A similar case this has been used for already is in the --frames-per-chunk flag value, which can't be less than 0, but can be any integer from 0 and above:

httomo/httomo/cli.py

Lines 137 to 142 in 6af2e2e

@click.option(
"--frames-per-chunk",
type=click.IntRange(0),
default=1,
help="Number of frames per-chunk in intermediate data (0 = write as contiguous)",
)

@yousefmoazzam yousefmoazzam added the minor Nice to do but not vital label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Nice to do but not vital
Projects
None yet
Development

No branches or pull requests

1 participant