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

Provide strtobool to avoid use of deprecated (removed in 3.12) distutils #457

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ body:
- 3.9
- "3.10"
- "3.11"
- "3.12"
- type: dropdown
id: streaming
attributes:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/streaming-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest"] # TODO: update mac and streaming methods
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: s-weigand/setup-conda@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-13", "windows-latest"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: conda-incubator/setup-miniconda@v3
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Improvements

* Exposed progress bar control to `inspect_all` and `run_checks` to allow compatibility with more generic visualizations of inspection progress related to the NWB GUIDED. [#443](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/443)
* Added Python 3.12 support. [#457](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/457)

### Testing

Expand Down
2 changes: 1 addition & 1 deletion docs/developer_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Disable Tests That Require Network Connection

Some of the tests in the suite require internet connectivity both to and from the DANDI archive S3 bucket.
If this is failing for some reason, you can explicitly control all related tests by setting the environment variable
``NWBI_SKIP_NETWORK_TESTS`` to some value able to be parsed by ``distutils.util.str2tool``. For example, to disable them on
``NWBI_SKIP_NETWORK_TESTS`` to some value able to be parsed by ``nwbinspector.utils.strtobool``. For example, to disable them on
a linux system, run

.. code-block::
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ If you haven't checked it out already, please read the :nwb-overview:`NWB Overvi

The NWBInspector tool offers convenient command-line usage via any standard Conda or Python terminal.

To install the package in any generic Python v3.8-v3.11 environment, simply type
To install the package in any generic Python v3.8-v3.12 environment, simply type

::

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
)
2 changes: 1 addition & 1 deletion src/nwbinspector/nwbinspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from concurrent.futures import ProcessPoolExecutor, as_completed
from types import FunctionType
from warnings import filterwarnings, warn
from distutils.util import strtobool
from collections import defaultdict
from packaging.version import Version

Expand All @@ -38,6 +37,7 @@
robust_s3_read,
calculate_number_of_cpu,
get_package_version,
strtobool,
)
from nwbinspector import __version__

Expand Down
3 changes: 1 addition & 2 deletions src/nwbinspector/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import json
from uuid import uuid4
from distutils.util import strtobool
from pathlib import Path
from datetime import datetime
from typing import Tuple, Optional
Expand All @@ -16,7 +15,7 @@
from pynwb import NWBHDF5IO, NWBFile
from pynwb.image import ImageSeries

from .utils import is_module_installed, get_package_version
from .utils import is_module_installed, get_package_version, strtobool

# The tests must be invoked at the outer level of the repository
TESTING_CONFIG_FILE_PATH = Path.cwd() / "tests" / "testing_config.json"
Expand Down
19 changes: 19 additions & 0 deletions src/nwbinspector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,22 @@ def __get_shape_helper(local_data):
if hasattr(data, "__len__") and not isinstance(data, (str, bytes)):
if not strict_no_data_load or isinstance(data, (list, tuple, set)):
return __get_shape_helper(data)


def strtobool(val: str) -> bool:
"""
Convert a string representation of truth to True or False.

True values are 'y', 'yes', 't', 'true', 'on', and '1';
False values are 'n', 'no', 'f', 'false', 'off', and '0'.
Raises ValueError if 'val' is anything else.
"""
if not isinstance(val, str):
raise TypeError(f"Invalid type of {val!r} - must be str for `strtobool`")
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return True
elif val in ("n", "no", "f", "false", "off", "0"):
return False
else:
raise ValueError(f"Invalid truth value {val!r}")
22 changes: 22 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
get_package_version,
calculate_number_of_cpu,
is_ascending_series,
strtobool,
)


import pytest


def test_format_byte_size():
assert format_byte_size(byte_size=12345) == "12.35KB"

Expand Down Expand Up @@ -142,3 +146,21 @@ def test_is_ascending_series():
assert is_ascending_series(series=[1, 1, 1])
assert is_ascending_series(series=[1, 2, 3])
assert not is_ascending_series(series=[1, 2, 1])


@pytest.mark.parametrize(
"values,target",
[
(("y", "yes", "t", "true", "on", "1"), True),
(("n", "no", "f", "false", "off", "0"), False),
],
)
def test_strtobool(values, target):
for v in values:
assert strtobool(v) is target
assert strtobool(v.upper()) is target
with pytest.raises(ValueError):
strtobool(v + "1")
# it is strtobool, so no bool is allowed
with pytest.raises(TypeError):
strtobool(target)
Loading