From 9078798e96ae607085015db8b15d1110ff127acf Mon Sep 17 00:00:00 2001 From: Tom White Date: Tue, 24 Sep 2024 11:56:41 +0100 Subject: [PATCH] Test on Python 3.12 - but only on NumPy 2 due to cbgen version constraints Update flake8 Fix flake8 errors Don't run pre-commit for NumPy 2 tests Try installing latest bio2zarr at end Replace pkg_resources with importlib.metadata --- .github/workflows/build-numpy-2.yml | 8 ++++---- .pre-commit-config.yaml | 2 +- requirements-numpy2-dev.txt | 23 ++++++++++++++++++++++ requirements-numpy2.txt | 12 +++++++++++ sgkit/__init__.py | 6 +++--- sgkit/tests/test_stats_utils.py | 2 +- validation/gwas/method/regenie/hail_sim.py | 4 ++-- 7 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 requirements-numpy2-dev.txt create mode 100644 requirements-numpy2.txt diff --git a/.github/workflows/build-numpy-2.yml b/.github/workflows/build-numpy-2.yml index 0374905b8..4e1c14890 100644 --- a/.github/workflows/build-numpy-2.yml +++ b/.github/workflows/build-numpy-2.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10", "3.11"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v2 @@ -22,11 +22,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt -r requirements-dev.txt + pip install -r requirements-numpy2.txt -r requirements-numpy2-dev.txt # update bio2zarr for NumPy 2, see https://github.com/sgkit-dev/bio2zarr/issues/256 pip install -U 'numpy<2.1' -U git+https://github.com/sgkit-dev/bio2zarr.git - - name: Run pre-commit - uses: pre-commit/action@v2.0.0 + # - name: Run pre-commit + # uses: pre-commit/action@v2.0.0 - name: Test with pytest (numba jit disabled) env: NUMBA_DISABLE_JIT: 1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index db0311976..9db4e02e3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: - id: black language_version: python3 - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 language_version: python3 diff --git a/requirements-numpy2-dev.txt b/requirements-numpy2-dev.txt new file mode 100644 index 000000000..275c7d538 --- /dev/null +++ b/requirements-numpy2-dev.txt @@ -0,0 +1,23 @@ +callee +pre-commit +pytest +pytest-cov +pytest-datadir +pytest-mock +hypothesis +scikit-allel +statsmodels +msprime>=1.0 +scikit-learn +partd +bed-reader +rechunker +cbgen > 1.0.5; platform_system != "Windows" +cbgen == 1.0.1; platform_system == "Windows" +yarl +matplotlib +asv +networkx +aiohttp +requests +graphviz diff --git a/requirements-numpy2.txt b/requirements-numpy2.txt new file mode 100644 index 000000000..491e63fb8 --- /dev/null +++ b/requirements-numpy2.txt @@ -0,0 +1,12 @@ +numpy < 2.1 +xarray +dask[array] >= 2023.01.0, <= 2024.8.0 +distributed >= 2023.01.0, <= 2024.8.0 +dask-ml +scipy +typing-extensions +numba +zarr >= 2.10.0, != 2.11.0, != 2.11.1, != 2.11.2, < 3 +fsspec != 2021.6.* +scikit-learn +pandas diff --git a/sgkit/__init__.py b/sgkit/__init__.py index dbe5832a9..3a82272ac 100644 --- a/sgkit/__init__.py +++ b/sgkit/__init__.py @@ -1,4 +1,4 @@ -from pkg_resources import DistributionNotFound, get_distribution # type: ignore[import] +from importlib.metadata import PackageNotFoundError, version # type: ignore[import] from .display import display_genotypes, display_pedigree from .distance.api import pairwise_distance @@ -68,8 +68,8 @@ ) try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: # pragma: no cover + __version__ = version(__name__) +except PackageNotFoundError: # pragma: no cover __version__ = "unknown" __all__ = [ diff --git a/sgkit/tests/test_stats_utils.py b/sgkit/tests/test_stats_utils.py index 965a350a0..d26b10ccb 100644 --- a/sgkit/tests/test_stats_utils.py +++ b/sgkit/tests/test_stats_utils.py @@ -107,7 +107,7 @@ def sample_dataset(draw): # Split first dimension assignment into two groups and assign second # dimension with unique names since n cols will differ dims = [ - (f"dim-0-{i%2}",) if i < n_1d else (f"dim-0-{i%2}", f"dim-1-{i}") + (f"dim-0-{i % 2}",) if i < n_1d else (f"dim-0-{i % 2}", f"dim-1-{i}") for i in range(n_arrs) ] diff --git a/validation/gwas/method/regenie/hail_sim.py b/validation/gwas/method/regenie/hail_sim.py index 181825a87..0c8c5bd4e 100755 --- a/validation/gwas/method/regenie/hail_sim.py +++ b/validation/gwas/method/regenie/hail_sim.py @@ -49,8 +49,8 @@ def get_plink_sim_dataset(n_variants=16, n_samples=4, n_contigs=2, seed=0): for s in range(n_samples): data.append( { - "v": f"{c+1}:{v+1}:A:C", - "s": f"S{s+1:07d}", + "v": f"{c + 1}:{v + 1}:A:C", + "s": f"S{s + 1:07d}", "cm": 0.1, "GT": hl.Call([rs.randint(0, 2), rs.randint(0, 2)]), }