Skip to content

Commit

Permalink
ENH: Adopt PEP518 and PEP631
Browse files Browse the repository at this point in the history
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 `statsmodels >= 0.14.0` to avoid

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'
```

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.

Documentation:
https://www.python.org/dev/peps/pep-0518/
https://www.python.org/dev/peps/pep-0631/
  • Loading branch information
jhlegarreta committed Dec 8, 2023
1 parent e125aaa commit dc3d13d
Show file tree
Hide file tree
Showing 50 changed files with 231 additions and 152 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/test_package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ jobs:
- name: Set min. dependencies
if: matrix.requires == 'minimal'
run: |
python -c "req = open('requirements.txt').read().replace(' >= ', ' == ') ; open('requirements.txt', 'w').write(req)"
python -c "req = open('requirements_dev.txt').read().replace(' >= ', ' == ') ; open('requirements_dev.txt', 'w').write(req)"
python -c "req = open('setup.py').read().replace(' >= ', ' == ') ; open('setup.py', 'w').write(req)"
python -c "req = open('pyproject.toml').read().replace(' >= ', ' == ') ; open('pyproject.toml', 'w').write(req)"
# - name: Cache pip
# uses: actions/cache@v2
Expand All @@ -45,18 +43,24 @@ jobs:
- name: Install dependencies
# if: steps.cache.outputs.cache-hit != 'true'
run: |
python -m pip install --upgrade --user pip setuptools pytest-cov
pip install -r requirements_dev.txt
# SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL required due to
# some dependency listing "scikit-learn" as "sklearn" in its dependencies
export SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True
python -m pip install --upgrade --user pip
pip install setuptools tox
pip install -e .[test]
python --version
pip --version
pip list
- name: Run tests
run: |
# tox --sitepackages
pip install -e .
# Test with tox
tox --sitepackages
# Test with pytest
python -c 'import whitematteranalysis'
coverage run --source whitematteranalysis -m pytest -o junit_family=xunit2 -v --doctest-modules --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}.xml
coverage run --source whitematteranalysis -m pytest -o junit_family=xunit2 -v --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}.xml
# coverage run --source whitematteranalysis -m pytest -o junit_family=xunit2 -v --doctest-modules --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}.xml
- name: Upload pytest test results
uses: actions/upload-artifact@master
Expand All @@ -74,9 +78,9 @@ jobs:
- name: Package Setup
# - name: Run tests with tox
run: |
# pip install build
pip install build
# check-manifest
python setup.py install
python -m build
# twine check dist/
# tox --sitepackages
# python -m tox
2 changes: 1 addition & 1 deletion bin/tests/test_harden_transform_with_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["harden_transform_with_slicer.py", "--help"])
ret = script_runner.run(["bin/harden_transform_with_slicer.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_append_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_append_clusters.py", "--help"])
ret = script_runner.run(["bin/wm_append_clusters.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_append_clusters_to_anatomical_tracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

def test_help_option(script_runner):
ret = script_runner.run(
["wm_append_clusters_to_anatomical_tracts.py", "--help"])
["bin/wm_append_clusters_to_anatomical_tracts.py", "--help"])
assert ret.success
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

def test_help_option(script_runner):
ret = script_runner.run(
["wm_append_diffusion_measures_across_subjects.py", "--help"])
["bin/wm_append_diffusion_measures_across_subjects.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_assess_cluster_location_by_hemisphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

def test_help_option(script_runner):
ret = script_runner.run(
["wm_assess_cluster_location_by_hemisphere.py", "--help"])
["bin/wm_assess_cluster_location_by_hemisphere.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_average_tract_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_average_tract_measures.py", "--help"])
ret = script_runner.run(["bin/wm_average_tract_measures.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_change_nrrd_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_change_nrrd_dir.py", "--help"])
ret = script_runner.run(["bin/wm_change_nrrd_dir.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_cluster_from_atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

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


Expand Down
2 changes: 1 addition & 1 deletion bin/tests/test_wm_cluster_remove_outliers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

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


Expand Down
3 changes: 2 additions & 1 deletion bin/tests/test_wm_cluster_volumetric_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_cluster_volumetric_measurements.py", "--help"])
ret = script_runner.run(
["bin/wm_cluster_volumetric_measurements.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_compare_vtks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_compare_vtks.py", "--help"])
ret = script_runner.run(["bin/wm_compare_vtks.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_create_mrml_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_create_mrml_file.py", "--help"])
ret = script_runner.run(["bin/wm_create_mrml_file.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_diffusion_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_diffusion_measurements.py", "--help"])
ret = script_runner.run(["bin/wm_diffusion_measurements.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_download_anatomically_curated_atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

def test_help_option(script_runner):
ret = script_runner.run(
["wm_download_anatomically_curated_atlas.py", "--help"])
["bin/wm_download_anatomically_curated_atlas.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_harden_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_harden_transform.py", "--help"])
ret = script_runner.run(["bin/wm_harden_transform.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_preprocess_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_preprocess_all.py", "--help"])
ret = script_runner.run(["bin/wm_preprocess_all.py", "--help"])
assert ret.success
3 changes: 2 additions & 1 deletion bin/tests/test_wm_quality_control_after_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_quality_control_after_clustering.py", "--help"])
ret = script_runner.run(
["bin/wm_quality_control_after_clustering.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_quality_control_cluster_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

def test_help_option(script_runner):
ret = script_runner.run(
["wm_quality_control_cluster_measurements.py", "--help"])
["bin/wm_quality_control_cluster_measurements.py", "--help"])
assert ret.success
3 changes: 2 additions & 1 deletion bin/tests/test_wm_quality_control_tract_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_quality_control_tract_overlap.py", "--help"])
ret = script_runner.run(
["bin/wm_quality_control_tract_overlap.py", "--help"])
assert ret.success
3 changes: 2 additions & 1 deletion bin/tests/test_wm_quality_control_tractography.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@


def test_help_option(script_runner):
ret = script_runner.run(["wm_quality_control_tractography.py", "--help"])
ret = script_runner.run(
["bin/wm_quality_control_tractography.py", "--help"])
assert ret.success


Expand Down
3 changes: 2 additions & 1 deletion bin/tests/test_wm_register_multisubject_faster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_register_multisubject_faster.py", "--help"])
ret = script_runner.run(
["bin/wm_register_multisubject_faster.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_register_to_atlas_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_register_to_atlas_new.py", "--help"])
ret = script_runner.run(["bin/wm_register_to_atlas_new.py", "--help"])
assert ret.success


Expand Down
2 changes: 1 addition & 1 deletion bin/tests/test_wm_remove_data_along_tracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_remove_data_along_tracts.py", "--help"])
ret = script_runner.run(["bin/wm_remove_data_along_tracts.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_separate_clusters_by_hemisphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_separate_clusters_by_hemisphere.py", "--help"])
ret = script_runner.run(["bin/wm_separate_clusters_by_hemisphere.py", "--help"])
assert ret.success


Expand Down
2 changes: 1 addition & 1 deletion bin/tests/test_wm_tract_to_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_tract_to_volume.py", "--help"])
ret = script_runner.run(["bin/wm_tract_to_volume.py", "--help"])
assert ret.success
2 changes: 1 addition & 1 deletion bin/tests/test_wm_vtp2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
ret = script_runner.run(["wm_vtp2vtk.py", "--help"])
ret = script_runner.run(["bin/wm_vtp2vtk.py", "--help"])
assert ret.success
41 changes: 9 additions & 32 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,30 @@
import os
import re
from datetime import datetime
from importlib.metadata import version as vers

import tomli

# import sys

# sys.path.insert(0, os.path.abspath('.'))

author_setup_str = " author="
author_email_setup_str = " author_email="
name_setup_str = " name="
version_setup_str = " version="


# Load the release info into a dict by explicit execution
info = {}
with open(os.path.abspath(os.path.join(
os.path.dirname(__file__), "../..", "setup.py")), "r") as f:
for line in f:
if line.startswith(name_setup_str):
project = (
re.search(name_setup_str + "(.*),", line).group(1).strip("\'"))
elif line.startswith(author_setup_str):
_author = (
re.search(
author_setup_str + "(.*),",
line).group(1).strip("\'").replace("\\", "")
)
elif line.startswith(author_email_setup_str):
_email = (
re.search(
author_email_setup_str + "(.*),",
line).group(1).strip("\'")
)
elif line.startswith(version_setup_str):
_version = (
re.search(
version_setup_str + "(.*),",
line).group(1).strip("\'")
)
with open(os.path.join("../..", "pyproject.toml"), "rb") as f:
info = tomli.load(f)

# -- Project information -----------------------------------------------------

project = info["project"]["name"]
_author = info["project"]["authors"][0]["name"]
_email = info["project"]["authors"][1]["email"]
copyright = f"2013-{datetime.now().year}, {_author} <{_email}>"
author = f"{_author}s"

_version = vers(project)
# The full version, including alpha/beta/rc tags
release = _version


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
Expand Down
Loading

0 comments on commit dc3d13d

Please sign in to comment.