Skip to content

Commit 87f5216

Browse files
committed
ENH: Adopt PEP518 and PEP631
Adopt PEP518 to specify minimum build system requirements for the package. Partially comply with PEP631: - Dependencies are now stored in the `pyproject.toml` file, including packages that are not in PyPI (e.g. source code URLs -GitHub, etc.), so the related requirements file is removed. Require `setuptools >= 66` so that the package can be effectively installed in editable mode when using the minimum required version of it. Avoids: ``` ERROR: Project file:///home/runner/work/whitematteranalysis/whitematteranalysis has a 'pyproject.toml' and its build backend is missing the 'build_editable' hook. Since it does not have a 'setup.py' nor a 'setup.cfg', it cannot be installed in editable mode. Consider using a build backend that supports PEP 660. ``` Require `nibabel > 3.0.0` to avoid: ``` File "bin/wm_cluster_volumetric_measurements.py", line 7, in <module> import nibabel as nib File "python3.10/site-packages/nibabel/__init__.py", line 66, in <module> (...) AttributeError: module 'numpy' has no attribute 'float'. `np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'cfloat'? ``` Require `"scipy >= 1.7.0` for `python_version == '3.9'` to avoid: ``` whitematteranalysis/cluster.py:14: in <module> import scipy.cluster.hierarchy (...) python3.9/site-packages/scipy/special/orthogonal.py:79: in <module> from numpy import (exp, inf, pi, sqrt, floor, sin, cos, around, int, E ImportError: cannot import name 'int' from 'numpy' (python3.9/site-packages/numpy/__init__.py) ``` Require `statsmodels >= 0.14.0` to avoid: ``` ModuleNotFoundError: No module named 'statsmodels' ``` when using the minimum required version builds. Require `vtk>=9.2.2` for `python_version == '3.9'` to avoid: ``` import vtk ModuleNotFoundError: No module named 'vtk' ``` Require `vtk>=9.2.2` for `python_version >= '3.10'` to avoid: ``` ERROR: Could not find a version that satisfies the requirement vtk==9.2.0 (from versions: 9.2.2, 9.2.4, 9.2.5, 9.2.6, 9.3.0rc1, 9.3.0rc2, 9.3.0, 9.3.20230807rc0) ERROR: No matching distribution found for vtk==9.2.0 ``` and `vtk>=9.2.4` for Python 3.11 to avoid: ``` File "whitematteranalysis/cluster.py", line 16, in <module> import vtk ModuleNotFoundError: No module named 'vtk' ``` List `importlib-resources` as a dependency explicitly to avoid Python 3.9 not finding the package. Use `float` instad of `np.float` in `tract_measurement.py`. Fixes: ``` AttributeError: module 'numpy' has no attribute 'float'. `np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here. ``` Adapt the Sphinx documentation config file to read the necessary metadata from the `pyproject.toml` file. Add the `tomli` package to the documentation dependencies so that `readthedocs` can successfully find it. Prepend the module location to the script testing `script_runner.run` calls. Adopt `tox.ini` for testing automation and standardization. Adapt the GitHub Actions workflow accordingly Do not use the `--doctest-modules` for now to avoid: ``` _____________________ ERROR collecting docs/source/conf.py _____________________ E FileNotFoundError: [Errno 2] No such file or directory: '../../pyproject.toml' ``` Documentation: https://www.python.org/dev/peps/pep-0518/ https://www.python.org/dev/peps/pep-0631/
1 parent e125aaa commit 87f5216

File tree

50 files changed

+231
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+231
-152
lines changed

.github/workflows/test_package.yaml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ jobs:
2828
- name: Set min. dependencies
2929
if: matrix.requires == 'minimal'
3030
run: |
31-
python -c "req = open('requirements.txt').read().replace(' >= ', ' == ') ; open('requirements.txt', 'w').write(req)"
32-
python -c "req = open('requirements_dev.txt').read().replace(' >= ', ' == ') ; open('requirements_dev.txt', 'w').write(req)"
33-
python -c "req = open('setup.py').read().replace(' >= ', ' == ') ; open('setup.py', 'w').write(req)"
31+
python -c "req = open('pyproject.toml').read().replace(' >= ', ' == ') ; open('pyproject.toml', 'w').write(req)"
3432
3533
# - name: Cache pip
3634
# uses: actions/cache@v2
@@ -45,18 +43,24 @@ jobs:
4543
- name: Install dependencies
4644
# if: steps.cache.outputs.cache-hit != 'true'
4745
run: |
48-
python -m pip install --upgrade --user pip setuptools pytest-cov
49-
pip install -r requirements_dev.txt
46+
# SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL required due to
47+
# some dependency listing "scikit-learn" as "sklearn" in its dependencies
48+
export SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True
49+
python -m pip install --upgrade --user pip
50+
pip install setuptools tox
51+
pip install -e .[test]
5052
python --version
5153
pip --version
5254
pip list
5355
5456
- name: Run tests
5557
run: |
56-
# tox --sitepackages
57-
pip install -e .
58+
# Test with tox
59+
tox --sitepackages
60+
# Test with pytest
5861
python -c 'import whitematteranalysis'
59-
coverage run --source whitematteranalysis -m pytest -o junit_family=xunit2 -v --doctest-modules --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}.xml
62+
coverage run --source whitematteranalysis -m pytest -o junit_family=xunit2 -v --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}.xml
63+
# coverage run --source whitematteranalysis -m pytest -o junit_family=xunit2 -v --doctest-modules --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}.xml
6064
6165
- name: Upload pytest test results
6266
uses: actions/upload-artifact@master
@@ -74,9 +78,9 @@ jobs:
7478
- name: Package Setup
7579
# - name: Run tests with tox
7680
run: |
77-
# pip install build
81+
pip install build
7882
# check-manifest
79-
python setup.py install
83+
python -m build
8084
# twine check dist/
8185
# tox --sitepackages
8286
# python -m tox

bin/tests/test_harden_transform_with_slicer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# -*- coding: utf-8 -*-
33

44
def test_help_option(script_runner):
5-
ret = script_runner.run(["harden_transform_with_slicer.py", "--help"])
5+
ret = script_runner.run(["bin/harden_transform_with_slicer.py", "--help"])
66
assert ret.success

bin/tests/test_wm_append_clusters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# -*- coding: utf-8 -*-
33

44
def test_help_option(script_runner):
5-
ret = script_runner.run(["wm_append_clusters.py", "--help"])
5+
ret = script_runner.run(["bin/wm_append_clusters.py", "--help"])
66
assert ret.success

bin/tests/test_wm_append_clusters_to_anatomical_tracts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
def test_help_option(script_runner):
55
ret = script_runner.run(
6-
["wm_append_clusters_to_anatomical_tracts.py", "--help"])
6+
["bin/wm_append_clusters_to_anatomical_tracts.py", "--help"])
77
assert ret.success

bin/tests/test_wm_append_diffusion_measures_across_subjects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
def test_help_option(script_runner):
55
ret = script_runner.run(
6-
["wm_append_diffusion_measures_across_subjects.py", "--help"])
6+
["bin/wm_append_diffusion_measures_across_subjects.py", "--help"])
77
assert ret.success

bin/tests/test_wm_assess_cluster_location_by_hemisphere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
def test_help_option(script_runner):
55
ret = script_runner.run(
6-
["wm_assess_cluster_location_by_hemisphere.py", "--help"])
6+
["bin/wm_assess_cluster_location_by_hemisphere.py", "--help"])
77
assert ret.success

bin/tests/test_wm_average_tract_measures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# -*- coding: utf-8 -*-
33

44
def test_help_option(script_runner):
5-
ret = script_runner.run(["wm_average_tract_measures.py", "--help"])
5+
ret = script_runner.run(["bin/wm_average_tract_measures.py", "--help"])
66
assert ret.success

bin/tests/test_wm_change_nrrd_dir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# -*- coding: utf-8 -*-
33

44
def test_help_option(script_runner):
5-
ret = script_runner.run(["wm_change_nrrd_dir.py", "--help"])
5+
ret = script_runner.run(["bin/wm_change_nrrd_dir.py", "--help"])
66
assert ret.success

bin/tests/test_wm_cluster_from_atlas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
def test_help_option(script_runner):
5-
ret = script_runner.run(["wm_cluster_from_atlas.py", "--help"])
5+
ret = script_runner.run(["bin/wm_cluster_from_atlas.py", "--help"])
66
assert ret.success
77

88

bin/tests/test_wm_cluster_remove_outliers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
def test_help_option(script_runner):
5-
ret = script_runner.run(["wm_cluster_remove_outliers.py", "--help"])
5+
ret = script_runner.run(["bin/wm_cluster_remove_outliers.py", "--help"])
66
assert ret.success
77

88

0 commit comments

Comments
 (0)