Skip to content

Numpy 2.0 + scipy + matplotlib pre-release workflow #89

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

Merged
merged 37 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
498bb7d
pin pytest to 8.0 and above
Mar 12, 2024
8869fa3
move conftest.py to root and turn warnings into errors
Mar 12, 2024
e6bdb87
add workflow testing against numpy 2.0
Mar 12, 2024
c6421cf
skip coverage
Mar 12, 2024
b9f812b
fix config file used
Mar 12, 2024
133eb37
also install pip-pre scipy and matplotlib
Mar 12, 2024
d359e64
scikit-learn also for nilearn compatibility with numpy 2.0
Mar 12, 2024
3e4848c
don't run nilearn tests on pip-pre
Mar 12, 2024
7174d55
run 3.9 and 3.12 on circle and 3.7 compat on gh
Mar 12, 2024
57bf4d2
fix workflow name
Mar 12, 2024
c051918
fix: importorskip is not a mark decorator
Mar 12, 2024
e9f8638
catch user warning
Mar 12, 2024
5823b76
fix deprecated readfp
Mar 12, 2024
f28ebc3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 12, 2024
861e6ac
ignore conftest in module discovery
Mar 12, 2024
fdfd6a3
fix uninstall step of nilearn
Mar 12, 2024
969a2bd
try again to rm nilearn
Mar 12, 2024
8cf1d75
fix module discovery logic
Mar 12, 2024
06cb94a
fix numpy deprecation of np.NINF and np.trapz
Mar 12, 2024
b0bba37
fix missed importorskip("nilearn")
Mar 12, 2024
1298196
fix deprecation of find_module in module discovery logic
Mar 12, 2024
b5008f1
fix compatibility trapz <-> trapezoid
Mar 12, 2024
45cc318
fix compatibility function
Mar 12, 2024
530ee74
add missed pytest.importorskip("nilearn")
Mar 12, 2024
7d33193
fix imports, drop pkg_utils entirely
Mar 12, 2024
4c59098
fix missed imports
Mar 12, 2024
ac48dac
rm unused variable
Mar 12, 2024
af4d907
use relative imports and fix circular import and namespace
Mar 12, 2024
d632133
revert version import
Mar 12, 2024
34ed758
close log file handler
Mar 12, 2024
fda9324
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 12, 2024
ec85fb8
fix missed importorskip("nilearn")
Mar 12, 2024
8ef7bbc
fix codecov yml
Apr 22, 2024
b55bc0c
suppress sphinx gallery warning
Apr 22, 2024
114ae4f
mv trapezoid_compat
Apr 24, 2024
a40f270
Merge remote-tracking branch 'upstream/master' into np2.0
Apr 24, 2024
493756d
trigger ci
Apr 25, 2024
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
20 changes: 10 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ orbs:
# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
test37: # This is the name of the job, feel free to change it to better match what you're trying to do!
test39: # This is the name of the job, feel free to change it to better match what you're trying to do!
# These next lines defines a Docker executors: https://circleci.com/docs/2.0/executor-types/
# You can specify an image from Dockerhub or use one of the convenience images from CircleCI's Developer Hub
# A list of available CircleCI Docker convenience images are available here: https://circleci.com/developer/images/image/cimg/python
# The executor is the environment in which the steps below will be executed - below will use a python 3.6.14 container
# Change the version below to your required version of python
docker:
- image: cimg/python:3.7
- image: cimg/python:3.9
working_directory: /tmp/src/nigsp
resource_class: medium
# Checkout the code as the first step. This is a dedicated CircleCI step.
Expand Down Expand Up @@ -58,9 +58,9 @@ jobs:
paths:
- src/coverage/.coverage.py37

test310:
test312:
docker:
- image: cimg/python:3.10
- image: cimg/python:3.12
working_directory: /tmp/src/nigsp
resource_class: medium
steps:
Expand All @@ -85,7 +85,7 @@ jobs:

style_check:
docker:
- image: cimg/python:3.7
- image: cimg/python:3.11
working_directory: /tmp/src/nigsp
resource_class: small
steps:
Expand All @@ -105,7 +105,7 @@ jobs:
merge_coverage:
working_directory: /tmp/src/nigsp
docker:
- image: cimg/python:3.10
- image: cimg/python:3.11
resource_class: small
steps:
- attach_workspace:
Expand Down Expand Up @@ -133,13 +133,13 @@ workflows:
# Inside the workflow, you define the jobs you want to run.
jobs:
- style_check
- test37:
- test39:
requires:
- style_check
- test310:
- test312:
requires:
- style_check
- merge_coverage:
requires:
- test37
- test310
- test39
- test312
84 changes: 84 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: pytest
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }}
cancel-in-progress: true
on: # yamllint disable-line rule:truthy
pull_request:
push:
branches: [main]
workflow_dispatch:
schedule:
- cron: '0 8 * * 1'

jobs:
pytest-compat:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
python-version: ["3.7"]
name: pip compat - py${{ matrix.python-version }}
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --progress-bar off --upgrade pip setuptools
python -m pip install --progress-bar off .[all,style]
python -m pip install --progress-bar off pytest pytest-cov coverage
- name: Run pytest
run: pytest nigsp --cov=nigsp --cov-report=xml --cov-config=setup.cfg
- name: Upload to codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
flags: unittests # optional
name: codecov-umbrella # optional
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true # optional (default = false)
pytest-pip-pre:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
name: pip pre-release - py${{ matrix.python-version }}
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --progress-bar off --upgrade pip setuptools
python -m pip install --progress-bar off .[test]
python -m pip install matplotlib
python -m pip install --progress-bar off --upgrade --no-deps --pre --only-binary :all: -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --timeout=180 matplotlib
python -m pip install --progress-bar off --upgrade --pre --only-binary :all: -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --timeout=180 numpy scipy
python -m pip uninstall -y nilearn
- name: Run pytest
run: pytest nigsp --cov=nigsp --cov-report=xml --cov-config=setup.cfg
- name: Upload to codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
flags: unittests # optional
name: codecov-umbrella # optional
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true # optional (default = false)
6 changes: 3 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
codecov:
branch: master
strict_yaml_branch: master
require_ci_to_pass: yes
require_ci_to_pass: true
bot: "codecov-io"
max_report_age: 48
disable_default_path_fixes: no
disable_default_path_fixes: false

coverage:
precision: 2
Expand Down Expand Up @@ -40,4 +40,4 @@ ignore:
comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: no
require_changes: false
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
nitpicky = True
nitpick_ignore = []

# list of warning types to suppress
suppress_warnings = ["config.cache"]

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
Expand Down
26 changes: 12 additions & 14 deletions nigsp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
"""Hopefully importing everything."""

import pkgutil

from . import (
blocks,
cli,
due,
io,
objects,
operations,
references,
utils,
viz,
workflow,
)
from ._version import get_versions
from .operations import graph, laplacian, metrics, nifti, surrogates, timeseries

SKIP_MODULES = ["tests"]

__version__ = get_versions()["version"]
del get_versions

__all__ = []
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
if "tests" not in module_name:
__all__.append(module_name)
_module = loader.find_module(module_name).load_module(module_name)
globals()[module_name] = _module
4 changes: 2 additions & 2 deletions nigsp/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import logging

from nigsp import io, viz
from nigsp.operations import nifti
from . import io, viz
from .operations import nifti

LGR = logging.getLogger(__name__)

Expand Down
9 changes: 3 additions & 6 deletions nigsp/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

import argparse

from nigsp import __version__
from .. import __version__


def _get_parser():
"""
Parse command line inputs for this function.
"""Parse command line inputs for this function.

Returns
-------
parser.parse_args() : argparse dict

"""
parser = argparse.ArgumentParser(
description=(
Expand Down Expand Up @@ -251,8 +249,7 @@ def _get_parser():
if __name__ == "__main__":
raise RuntimeError(
"nigsp/cli/run.py should not be run directly;\n"
"Please `pip install` nigsp and use the "
"`nigsp` command"
"Please `pip install` nigsp and use the `nigsp` command."
)


Expand Down
42 changes: 30 additions & 12 deletions nigsp/tests/conftest.py → nigsp/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
"""
This configuration test module was taken from phys2bids.
Credit to the original author(s) and to the phys2bids community.
"""
from __future__ import annotations # c.f. PEP 563, PEP 649

import os
import ssl
from typing import TYPE_CHECKING
from urllib.request import urlretrieve

import pytest
from pytest import fixture

if TYPE_CHECKING:
from pytest import Config

Check warning on line 11 in nigsp/conftest.py

View check run for this annotation

Codecov / codecov/patch

nigsp/conftest.py#L11

Added line #L11 was not covered by tests


def pytest_configure(config: Config) -> None:
"""Configure pytest options."""
warnings_lines = r"""
error::
"""
for warning_line in warnings_lines.split("\n"):
warning_line = warning_line.strip()
if warning_line and not warning_line.startswith("#"):
config.addinivalue_line("filterwarnings", warning_line)


"""
The following fetch_file and configuration test module was taken from phys2bids.
Credit to the original author(s) and to the phys2bids community.
"""


def fetch_file(osf_id, path, filename):
Expand Down Expand Up @@ -48,37 +66,37 @@
return full_path


@pytest.fixture(scope="session")
@fixture(scope="session")
def testdir(tmp_path_factory):
"""Test path that will be used to download all files."""
return tmp_path_factory.getbasetemp()


@pytest.fixture
@fixture(scope="function")
def atlas(testdir):
return fetch_file("h6nj7", testdir, "atlas.nii.gz")


@pytest.fixture
@fixture(scope="function")
def atlastime(testdir):
return fetch_file("ts6a8", testdir, "ats.nii.gz")


@pytest.fixture
@fixture(scope="function")
def mean_fc(testdir):
return fetch_file("jrg8d", testdir, "mean_fc_matlab.tsv")


@pytest.fixture
@fixture(scope="function")
def sdi(testdir):
return fetch_file("rs4dn", testdir, "SDI_matlab.tsv")


@pytest.fixture
@fixture(scope="function")
def sc_mtx(testdir):
return fetch_file("vwh75", testdir, "sc.mat")


@pytest.fixture
@fixture(scope="function")
def timeseries(testdir):
return fetch_file("ay8df", testdir, "func.mat")
2 changes: 1 addition & 1 deletion nigsp/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import numpy as np

from nigsp.utils import change_var_type
from .utils import change_var_type

EXT_1D = [".txt", ".csv", ".tsv", ".1d", ".par", ".tsv.gz", ".csv.gz"]
EXT_MAT = [".mat"]
Expand Down
2 changes: 1 addition & 1 deletion nigsp/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import logging
from copy import deepcopy

from nigsp import operations
from . import operations

LGR = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion nigsp/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
`nigsp.operations.sdi` or `nigsp.metrisc.sdi`.
"""

# Import all operations.
from . import graph, laplacian, metrics, nifti, surrogates, timeseries
from .graph import nodestrength, zerocross
from .laplacian import (
compute_laplacian,
Expand Down
2 changes: 1 addition & 1 deletion nigsp/operations/surrogates.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def _pmf(x, n, p):
if return_masked:
LGR.info("Returning masked empirical data")
stat_mask = np.ma.array(
data=surr[..., -1], mask=np.invert(stat_mask), fill_value=np.NINF
data=surr[..., -1], mask=np.invert(stat_mask), fill_value=-np.inf
).squeeze()
else:
LGR.info("Returning mask")
Expand Down
Loading