From 4bdb746a70c7bd15a044adc5c5d44a8f1ef917f8 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sat, 3 Aug 2024 23:50:03 -0700 Subject: [PATCH 01/14] transition to poetry --- .pre-commit-config.yaml | 12 +++++------ Makefile | 12 +++-------- pyproject.toml | 41 +++++++++++++++++++++++++++++++++++++ requirements.txt | 10 --------- setup.py | 45 ----------------------------------------- 5 files changed, 50 insertions(+), 70 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 setup.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 058266a..6dacbb2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,27 +1,27 @@ default_language_version: - python: python3.8 + python: python3.11 repos: - repo: https://github.com/ambv/black - rev: 23.1.0 + rev: 24.8.0 hooks: - id: black - args: ["elapid", "--line-length=120", "--target-version=py37"] + args: ["elapid", "--line-length=120"] - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 7.1.0 hooks: - id: flake8 args: ["--select=C,E,F,W,B,B950", "--max-line-length=120", "--ignore=E203,E501,W503,F401,F403"] - repo: https://github.com/timothycrosley/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort args: ["-l 120", "--profile", "black", "."] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - id: check-yaml exclude: recipe/meta.yaml diff --git a/Makefile b/Makefile index bf377a9..7a67d7c 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,6 @@ help: @echo "--- [ $(NAME) developer tools ] --- " @echo "" @echo "make init - initialize conda dev environment" - @echo "make utils - install convenient packages" @echo "make test - run package tests" @echo "make test-data - generates new data for tests/data/" @echo "make conda-clean - removes conda tempfiles" @@ -20,14 +19,9 @@ help: # utils init: - conda env list | grep -q ${NAME} || conda create --name=${NAME} python=3.8 mamba -y -c conda-forge - ${CONDA} mamba install gdal -c conda-forge -c nodefaults - ${CONDA} pip install pre-commit pytest pytest-xdist pytest-cov - ${CONDA} pre-commit install - ${CONDA} pip install -e . - -utils: - ${CONDA} pip install ipython jupyter matplotlib mkdocs-material mkdocstrings[python] mkdocs-jupyter + conda env list | grep -q ${NAME} || conda create --name=${NAME} python=3.11 mamba -y -c conda-forge -c nodefaults + ${CONDA} mamba install gdal poetry -c conda-forge -c nodefaults -y + ${CONDA} poetry install test: ${CONDA} pytest -n auto --cov --no-cov-on-fail --cov-report=term-missing:skip-covered diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c8e6709 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,41 @@ +[tool.poetry] +name = "elapid" +version = "1.0.2" +description = "Species distribution modeling tools" +authors = ["Christopher Anderson "] +license = "MIT" +readme = "README.md" +keywords = ["biogeography", "ecology", "maxent", "SDM", "species distribution modeling"] +include = [ + { path = "elapid/data/*", format = "sdist" } +] + +[tool.poetry.dependencies] +python = ">=3.8" +numpy = ">=1.18,<2.0" +pandas = ">=1.0.3" +pyproj = ">3.0" +geopandas = ">=0.7" +rasterio = ">=1.2.1" +tqdm = ">=4.60" +rtree = ">=0.9" +scikit-learn = ">=0.22.2" + +[tool.poetry.group.dev.dependencies] +descartes = ">=1.1" +pytest = ">=8.3" +pytest-xdist = ">=3.6" +pytest-cov = ">=5.0" +pre-commit = ">=3.0" +ipython = ">=8.0" +jupyter = ">=1.0" +mkdocs-material = ">=9.5" +mkdocstrings = {extras = ["python"], version = ">=0.25"} +mkdocs-jupyter = ">=0.24" + +[tool.poetry.extras] +glmnet = ["glmnet"] + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e798bdd..0000000 --- a/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -descartes>=1.1.0 -geopandas>=0.7.0 -numpy>=1.18 -pandas>=1.0.3 -pyproj>=3.0 -rasterio>=1.2.1 -rtree>=0.9 -scikit-learn>=0.22.2 -shapely>=1.7.0 -tqdm>=4.60.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index a157c02..0000000 --- a/setup.py +++ /dev/null @@ -1,45 +0,0 @@ -import os -import platform - -from setuptools import setup - -this_dir, this_path = os.path.split(os.path.abspath(__file__)) -version = open(os.path.join(this_dir, "elapid", "__version__.py")).read().strip('"\n') -long_description = open(os.path.join(this_dir, "README.md"), "r", encoding="utf-8").read() -requirements = open(os.path.join(this_dir, "requirements.txt"), "r", encoding="utf-8").read().strip().split() - -setup_args = { - "name": "elapid", - "version": version, - "url": "https://elapid.org", - "license": "MIT", - "author": "Christopher Anderson", - "author_email": "cbanders@stanford.edu", - "description": "Species distribution modeling support tools", - "long_description": long_description, - "long_description_content_type": "text/markdown", - "keywords": [ - "biogeography", - "ecology", - "conservation", - "SDM", - "species distribution modeling", - "maxent", - ], - "packages": ["elapid"], - "include_package_data": True, - "data_files": [("elapid", ["elapid/data/bradypus.csv.gz"])], - "install_requires": requirements, - "extras_require": { - "glmnet": "glmnet", - }, - "python_requires": ">=3.7.0", - "platforms": "any", - "classifiers": [ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ], -} - -setup(**setup_args) From 9bd019d5e477497e70c696417cf2b74a2184a571 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sat, 3 Aug 2024 23:51:36 -0700 Subject: [PATCH 02/14] reformat --- elapid/__version__.py | 2 +- elapid/config.py | 1 + elapid/models.py | 3 ++- elapid/types.py | 1 + elapid/utils.py | 2 +- 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/elapid/__version__.py b/elapid/__version__.py index 6c39a52..dc88d3d 100644 --- a/elapid/__version__.py +++ b/elapid/__version__.py @@ -1 +1 @@ -"1.0.1" +"1.0.2" diff --git a/elapid/config.py b/elapid/config.py index 1d4c348..87bc549 100644 --- a/elapid/config.py +++ b/elapid/config.py @@ -1,4 +1,5 @@ """SDM model configuration parameters.""" + from typing import Tuple, Union diff --git a/elapid/models.py b/elapid/models.py index 5f8009a..13fb5af 100644 --- a/elapid/models.py +++ b/elapid/models.py @@ -1,4 +1,5 @@ """Classes for training species distribution models.""" + from typing import List, Tuple, Union import matplotlib.pyplot as plt @@ -20,7 +21,7 @@ compute_weights, ) from elapid.types import ArrayLike, validate_feature_types -from elapid.utils import NCPUS, make_band_labels, square_factor +from elapid.utils import NCPUS, make_band_labels # handle windows systems without functioning gfortran compilers FORCE_SKLEARN = False diff --git a/elapid/types.py b/elapid/types.py index 8f05f78..0ebb26c 100644 --- a/elapid/types.py +++ b/elapid/types.py @@ -1,4 +1,5 @@ """Custom maxent and typing data types.""" + from typing import Any, Union import geopandas as gpd diff --git a/elapid/utils.py b/elapid/utils.py index c4c9b4b..9dfef4b 100644 --- a/elapid/utils.py +++ b/elapid/utils.py @@ -5,7 +5,7 @@ import os import pickle import sys -from typing import Any, Callable, Dict, Iterable, List, Tuple, Union +from typing import Any, Callable, Dict, Iterable, List, Tuple from urllib import request import geopandas as gpd From b9bd8c764361c2aab8fa4c713ea26e30098fe554 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sat, 3 Aug 2024 23:51:58 -0700 Subject: [PATCH 03/14] drop 3.7, add 3.11 --- .github/workflows/run-pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-pytest.yml b/.github/workflows/run-pytest.yml index fe65402..8132872 100644 --- a/.github/workflows/run-pytest.yml +++ b/.github/workflows/run-pytest.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From 1dc4538adc55ce67a684dcc5c55b0ce850116cf8 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sat, 3 Aug 2024 23:58:47 -0700 Subject: [PATCH 04/14] using new github actions --- .github/workflows/deploy-docs.yml | 6 +++--- .github/workflows/os-tests.yml | 6 +++--- .github/workflows/run-pytest.yml | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index d6d1116..1fd9234 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -12,10 +12,10 @@ jobs: runs-on: ubuntu-latest if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: - python-version: 3.7 + python-version: 3.11 - run: pip install mkdocs mkdocs-material mkdocstrings[python] mkdocs-jupyter livereload - run: pip install . - run: mkdocs gh-deploy --force diff --git a/.github/workflows/os-tests.yml b/.github/workflows/os-tests.yml index 61ed54d..950875f 100644 --- a/.github/workflows/os-tests.yml +++ b/.github/workflows/os-tests.yml @@ -15,13 +15,13 @@ jobs: os: [macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ env.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ env.python-version }} - cache: 'pip' + cache: 'poetry' - name: Install dependencies run: | diff --git a/.github/workflows/run-pytest.yml b/.github/workflows/run-pytest.yml index 8132872..adf4a27 100644 --- a/.github/workflows/run-pytest.yml +++ b/.github/workflows/run-pytest.yml @@ -13,12 +13,12 @@ jobs: matrix: python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - cache: 'pip' + cache: 'poetry' - name: Install dependencies run: | python -m pip install --upgrade pip From f93c6f5229e80b7be00600b7349e8dff13b51907 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sun, 4 Aug 2024 00:01:00 -0700 Subject: [PATCH 05/14] caching pyproject --- .github/workflows/os-tests.yml | 1 + .github/workflows/run-pytest.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/os-tests.yml b/.github/workflows/os-tests.yml index 950875f..d3210da 100644 --- a/.github/workflows/os-tests.yml +++ b/.github/workflows/os-tests.yml @@ -22,6 +22,7 @@ jobs: with: python-version: ${{ env.python-version }} cache: 'poetry' + cache-dependency-path: "pyproject.toml" - name: Install dependencies run: | diff --git a/.github/workflows/run-pytest.yml b/.github/workflows/run-pytest.yml index adf4a27..13b3e46 100644 --- a/.github/workflows/run-pytest.yml +++ b/.github/workflows/run-pytest.yml @@ -19,6 +19,7 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: 'poetry' + cache-dependency-path: "pyproject.toml" - name: Install dependencies run: | python -m pip install --upgrade pip From 532ac3d9f1a3bc82ad0582240b8ed04299c4c5c0 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sun, 4 Aug 2024 00:06:03 -0700 Subject: [PATCH 06/14] install poetry --- .github/workflows/os-tests.yml | 3 +++ .github/workflows/run-pytest.yml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/os-tests.yml b/.github/workflows/os-tests.yml index d3210da..4821e18 100644 --- a/.github/workflows/os-tests.yml +++ b/.github/workflows/os-tests.yml @@ -17,6 +17,9 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install poetry + run: pipx install poetry + - name: Set up Python ${{ env.python-version }} uses: actions/setup-python@v5 with: diff --git a/.github/workflows/run-pytest.yml b/.github/workflows/run-pytest.yml index 13b3e46..aaa686a 100644 --- a/.github/workflows/run-pytest.yml +++ b/.github/workflows/run-pytest.yml @@ -14,6 +14,8 @@ jobs: python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v4 + - name: Install poetry + run: pipx install poetry - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: From 45b644945849af23fb4cdc64847bb3225c44d8d2 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sun, 4 Aug 2024 00:08:54 -0700 Subject: [PATCH 07/14] adding matplotlib dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index c8e6709..34bd8cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ rasterio = ">=1.2.1" tqdm = ">=4.60" rtree = ">=0.9" scikit-learn = ">=0.22.2" +matplotlib = ">=3.7" [tool.poetry.group.dev.dependencies] descartes = ">=1.1" From 5fb2ba35c340e395d1b2340dfc2715af095e4579 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sun, 4 Aug 2024 00:15:28 -0700 Subject: [PATCH 08/14] sklearn version update --- elapid/features.py | 4 ++-- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/elapid/features.py b/elapid/features.py index ccfd13d..16299d3 100644 --- a/elapid/features.py +++ b/elapid/features.py @@ -349,13 +349,13 @@ def fit(self, x: ArrayLike) -> "CategoricalTransformer": self.estimators_ = [] x = np.array(x) if x.ndim == 1: - estimator = OneHotEncoder(dtype=np.uint8, sparse=False) + estimator = OneHotEncoder(dtype=np.uint8, sparse_output=False) self.estimators_.append(estimator.fit(x.reshape(-1, 1))) else: nrows, ncols = x.shape for col in range(ncols): xsub = x[:, col].reshape(-1, 1) - estimator = OneHotEncoder(dtype=np.uint8, sparse=False) + estimator = OneHotEncoder(dtype=np.uint8, sparse_output=False) self.estimators_.append(estimator.fit(xsub)) return self diff --git a/pyproject.toml b/pyproject.toml index 34bd8cf..1d0c01c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ geopandas = ">=0.7" rasterio = ">=1.2.1" tqdm = ">=4.60" rtree = ">=0.9" -scikit-learn = ">=0.22.2" +scikit-learn = ">=1.2" matplotlib = ">=3.7" [tool.poetry.group.dev.dependencies] From 513c16038430401b289be9c360cd9ec75c291416 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sun, 4 Aug 2024 00:23:10 -0700 Subject: [PATCH 09/14] using poetry install --- .github/workflows/os-tests.yml | 7 +------ .github/workflows/run-pytest.yml | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/os-tests.yml b/.github/workflows/os-tests.yml index 4821e18..30be8ea 100644 --- a/.github/workflows/os-tests.yml +++ b/.github/workflows/os-tests.yml @@ -27,11 +27,6 @@ jobs: cache: 'poetry' cache-dependency-path: "pyproject.toml" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pytest pytest-cov pytest-xdist - - name: Install windows geo dependencies if: matrix.os == 'windows-latest' run: | @@ -48,7 +43,7 @@ jobs: - name: Install package run: | - pip install . + poetry install - name: Run pytest run: | diff --git a/.github/workflows/run-pytest.yml b/.github/workflows/run-pytest.yml index aaa686a..678f314 100644 --- a/.github/workflows/run-pytest.yml +++ b/.github/workflows/run-pytest.yml @@ -24,9 +24,7 @@ jobs: cache-dependency-path: "pyproject.toml" - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install pytest pytest-cov pytest-xdist - pip install . + poetry install - name: Run pytest run: | pytest -n auto --cov --no-cov-on-fail --cov-report=term-missing:skip-covered --cov-report xml:coverage.xml From 677cacbea8b4ac12e41e7d232fe65f510865d1e3 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sun, 4 Aug 2024 00:26:47 -0700 Subject: [PATCH 10/14] poetry pytest --- .github/workflows/os-tests.yml | 2 +- .github/workflows/run-pytest.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/os-tests.yml b/.github/workflows/os-tests.yml index 30be8ea..3b23111 100644 --- a/.github/workflows/os-tests.yml +++ b/.github/workflows/os-tests.yml @@ -47,4 +47,4 @@ jobs: - name: Run pytest run: | - pytest -n auto --cov --no-cov-on-fail --cov-report=term-missing:skip-covered --cov-report xml:coverage.xml + poetry run pytest -n auto --cov --no-cov-on-fail --cov-report=term-missing:skip-covered --cov-report xml:coverage.xml diff --git a/.github/workflows/run-pytest.yml b/.github/workflows/run-pytest.yml index 678f314..5d07ded 100644 --- a/.github/workflows/run-pytest.yml +++ b/.github/workflows/run-pytest.yml @@ -27,4 +27,4 @@ jobs: poetry install - name: Run pytest run: | - pytest -n auto --cov --no-cov-on-fail --cov-report=term-missing:skip-covered --cov-report xml:coverage.xml + poetry run pytest -n auto --cov --no-cov-on-fail --cov-report=term-missing:skip-covered --cov-report xml:coverage.xml From 2b799023a17cc8a28e30953f61a3ad23632e0d02 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sun, 4 Aug 2024 00:27:06 -0700 Subject: [PATCH 11/14] key value update --- elapid/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elapid/models.py b/elapid/models.py index 13fb5af..eda8488 100644 --- a/elapid/models.py +++ b/elapid/models.py @@ -182,7 +182,7 @@ def partial_dependence_scores( ) mean[idx] = pd["individual"][0].mean(axis=0) stdv[idx] = pd["individual"][0].std(axis=0) - bins[idx] = pd["values"][0] + bins[idx] = pd["grid_values"][0] return bins, mean, stdv From 981999c323a0eef0d4633a356f5f739eed444b52 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Sun, 4 Aug 2024 00:34:04 -0700 Subject: [PATCH 12/14] install gdal osx --- .github/workflows/os-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/os-tests.yml b/.github/workflows/os-tests.yml index 3b23111..3acbda5 100644 --- a/.github/workflows/os-tests.yml +++ b/.github/workflows/os-tests.yml @@ -41,6 +41,11 @@ jobs: pipwin install rtree pip install geopandas + - name: 'Install osx geo dependencies' + if: matrix.os == 'macos-latest' + run: | + brew install gdal + - name: Install package run: | poetry install From 41d65ac80e345ae48727a48923f58515afea9828 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Thu, 8 Aug 2024 23:35:27 -0700 Subject: [PATCH 13/14] using pyproject as version source --- elapid/__init__.py | 2 +- elapid/__version__.py | 1 - elapid/version.py | 3 +++ 3 files changed, 4 insertions(+), 2 deletions(-) delete mode 100644 elapid/__version__.py create mode 100644 elapid/version.py diff --git a/elapid/__init__.py b/elapid/__init__.py index c7232a2..cf4968f 100644 --- a/elapid/__init__.py +++ b/elapid/__init__.py @@ -1,6 +1,5 @@ """User entrypoint to elapid""" -from elapid.__version__ import __doc__ as __version__ from elapid.features import ( CategoricalTransformer, HingeTransformer, @@ -27,3 +26,4 @@ from elapid.stats import normalize_sample_probabilities from elapid.train_test_split import BufferedLeaveOneOut, GeographicKFold, checkerboard_split from elapid.utils import download_sample_data, load_object, load_sample_data, save_object +from elapid.version import __version__ diff --git a/elapid/__version__.py b/elapid/__version__.py deleted file mode 100644 index dc88d3d..0000000 --- a/elapid/__version__.py +++ /dev/null @@ -1 +0,0 @@ -"1.0.2" diff --git a/elapid/version.py b/elapid/version.py new file mode 100644 index 0000000..c1d20e7 --- /dev/null +++ b/elapid/version.py @@ -0,0 +1,3 @@ +import importlib.metadata + +__version__ = importlib.metadata.version(__package__) From 888b8fe90efe7f2b3f36965ea80287647d9d31d7 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Thu, 8 Aug 2024 23:39:32 -0700 Subject: [PATCH 14/14] dependency spec update --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 0439384..724bd87 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,6 @@ include LICENSE include README.md -include requirements.txt +include pyproject.toml recursive-exclude * __pycache__ recursive-exclude * *.py[co]