Skip to content

Commit

Permalink
👌 accept enable/disable and on/off as valid Boolean values (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmd-dk authored Dec 22, 2023
1 parent 763e5ed commit d5c12df
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
29 changes: 14 additions & 15 deletions concept
Original file line number Diff line number Diff line change
Expand Up @@ -994,29 +994,28 @@ def time(value):
s = '0' + s
value = f'{h}:{m}:{s}'
return value
# Function which checks whether input is a boolean or is empty
def bool_or_empty(value):
value = str(value)
# Function which checks whether input is a Boolean
def bool_from_str(value):
value_raw = value
value = str(value).lower()
if value == '':
return value
if value in {'true', 't', 'y', 'yes', '1'}:
if value.startswith('y') or value in {'true', 't', 'on', 'enable', '1', '1.0'}:
return 'True'
if value in {'false', 'f', 'n', 'no', '0'}:
if value.startswith('n') or value in {'false', 'f', 'off', 'disable', '0', '0.0'}:
return 'False'
raise argparse.ArgumentTypeError(f\"invalid bool value: '{value_raw}'\")
# Function which checks whether input is a boolean,
# Function which checks whether input is a Boolean or is empty
def bool_or_empty(value):
value = str(value).strip()
if not value:
return value
return bool_from_str(value)
# Function which checks whether input is a Boolean,
# with empty input defaulting to True.
def bool_truebydefault(value):
value = str(value)
value_raw = value
value = str(value).lower()
if value in {'', 'true', 't', 'y', 'yes', '1'}:
value = str(value).strip()
if not value:
return 'True'
if value in { 'false', 'f', 'n', 'no', '0'}:
return 'False'
raise argparse.ArgumentTypeError(f\"invalid bool value: '{value_raw}'\")
return bool_from_str(value)
# Function for setting up a parser for command-line arguments
def get_parser(*, add_help=True):
def add_parser_argument(name, group, help, default, useenv=True, shortname=False, **kwargs):
Expand Down
17 changes: 9 additions & 8 deletions doc/command_line_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,15 @@ in which case the watch utility will not be run at all.

.. note::
This is an example of a Boolean command-line option. As a value, you may
use any of ``False``/``f``/``no``/``n``/``0`` for signifying ``False`` and
any of ``True``/``t``/``yes``/``y``/``1`` for signifying ``True`` (all case
insensitive). In addition, specifying the command-line option alone with no
value is the same as setting it to ``True``, i.e. ``--watch`` is equivalent
to ``--watch True``. As ``True`` also happens to be the default value,
supplying ``--watch`` by itself then does nothing. This is not so for
Boolean command-line options which default to ``False``, e.g. the
``--local`` :ref:`option <local>`.
use any of ``False``/``f``/``no``/``n``/``off``/``disable``/``0``/``0.0``
for signifying ``False`` and any of
``True``/``t``/``yes``/``y``/``on``/``enable``/``1``/``1.0`` for signifying
``True`` (all case insensitive). In addition, specifying the command-line
option alone with no value is the same as setting it to ``True``, i.e.
``--watch`` is equivalent to ``--watch True``. As ``True`` also happens to
be the default value, supplying ``--watch`` by itself then does nothing.
This is not so for Boolean command-line options which default to ``False``,
e.g. the ``--local`` :ref:`option <local>`.



Expand Down
2 changes: 1 addition & 1 deletion src/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def get_powerspec_declarations(components):
kk='Py_ssize_t',
logk_bin_centers='double[::1]',
logk_magnitude='double',
mask=object, # boolean np.ndarray
mask=object, # bool np.ndarray
n_modes='Py_ssize_t[::1]',
n_modes_fine='Py_ssize_t[::1]',
nyquist='Py_ssize_t',
Expand Down
6 changes: 3 additions & 3 deletions src/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3123,7 +3123,7 @@ def canonicalize_input_str(method):
else:
abort(
f'potential_options["deconvolve"]["{key}"]["{key2}"] = {val2} '
f'but should to be a tuple of two booleans, corresponding to the upstream '
f'but should to be a tuple of two Booleans, corresponding to the upstream '
f'and downstream deconvolution'
)
force_deconvolutions[key][key2] = val2
Expand Down Expand Up @@ -3173,7 +3173,7 @@ def interlace2latticekind(interlace):
else:
abort(
f'potential_options["interlace"]["{key}"]["{key2}"] = {val2} '
f'but should to be a tuple of two booleans or strs, corresponding to the upstream '
f'but should to be a tuple of two Booleans or strs, corresponding to the upstream '
f'and downstream interlacing'
)
force_interlacings[key][key2] = val2
Expand Down Expand Up @@ -5385,7 +5385,7 @@ def correct_float(val_raw):
rel_tol='double',
abs_tol='double',
# Locals
mask='unsigned char[::1]', # really boolean np.ndarray
mask='unsigned char[::1]', # really Boolean np.ndarray
a='double',
b='double',
i='Py_ssize_t',
Expand Down
2 changes: 1 addition & 1 deletion src/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def domain_domain(
# "only_supply_communication".
only_supply_communication = (only_supply if 𝔹[receiver is supplier] else True)
ranks_send, ranks_recv = domain_domain_communication(pairing_level, only_supply_communication)
# Backup of the passed only_supply boolean
# Backup of the passed only_supply Boolean
only_supply_passed = only_supply
# Pair this process/domain with whichever other
# processes/domains are needed. This process is paired
Expand Down
2 changes: 1 addition & 1 deletion src/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -3320,7 +3320,7 @@ def register_species(
negative for species which acts as a sink for a decaying species.
- logs: Dictionary of the form
{'rho': (logx, logy), 'p': (logx, logy)}
with each logx and logy a boolean specifying whether splines of
with each logx and logy a Boolean specifying whether splines of
the background density and pressure (as function of the scale
factor) should be carried out logarithmically or not.
- source_continuity: Function taking in the arguments
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ def activate_terminate(components, a, Δt, act='activate terminate'):
"""This function mutates the passed list of components
as well as the global passive_components, keeping their
collective contents constant.
The return value is a boolean signalling
The return value is a Boolean signalling
whether any component was activated.
"""
# Terminations
Expand Down
2 changes: 1 addition & 1 deletion src/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,7 @@ def fourier_operate(slab, deconv_order=0, lattice=None, diff_dim=-1):
returns='void',
)
def nullify_modes(slab, nullifications):
"""The nullifications argument can be a boolean, a str of
"""The nullifications argument can be a bool, a str of
comma-separated words, or alternatively a list of str's, each being
a single word. The words specify which types of modes to nullify:
- False, None: Do not perform any nullification.
Expand Down

0 comments on commit d5c12df

Please sign in to comment.