Skip to content

Commit

Permalink
Add pyproject.toml (#99)
Browse files Browse the repository at this point in the history
* transition to poetry

* reformat

* drop 3.7, add 3.11

* using new github actions

* caching pyproject

* install poetry

* adding matplotlib dependency

* sklearn version update

* using poetry install

* poetry pytest

* key value update

* install gdal osx

* using pyproject as version source

* dependency spec update
  • Loading branch information
earth-chris authored Aug 9, 2024
1 parent 7b90539 commit 15220dc
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 99 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 14 additions & 10 deletions .github/workflows/os-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ jobs:
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov pytest-xdist
cache: 'poetry'
cache-dependency-path: "pyproject.toml"

- name: Install windows geo dependencies
if: matrix.os == 'windows-latest'
Expand All @@ -42,10 +41,15 @@ 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: |
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
poetry run pytest -n auto --cov --no-cov-on-fail --cov-report=term-missing:skip-covered --cov-report xml:coverage.xml
17 changes: 9 additions & 8 deletions .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ 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
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- 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'
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
poetry run pytest -n auto --cov --no-cov-on-fail --cov-report=term-missing:skip-covered --cov-report xml:coverage.xml
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include LICENSE
include README.md
include requirements.txt
include pyproject.toml

recursive-exclude * __pycache__
recursive-exclude * *.py[co]
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion elapid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""User entrypoint to elapid"""

from elapid.__version__ import __doc__ as __version__
from elapid.features import (
CategoricalTransformer,
HingeTransformer,
Expand All @@ -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__
1 change: 0 additions & 1 deletion elapid/__version__.py

This file was deleted.

1 change: 1 addition & 0 deletions elapid/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""SDM model configuration parameters."""

from typing import Tuple, Union


Expand Down
4 changes: 2 additions & 2 deletions elapid/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions elapid/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Classes for training species distribution models."""

from typing import List, Tuple, Union

import matplotlib.pyplot as plt
Expand All @@ -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
Expand Down Expand Up @@ -181,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

Expand Down
1 change: 1 addition & 0 deletions elapid/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Custom maxent and typing data types."""

from typing import Any, Union

import geopandas as gpd
Expand Down
2 changes: 1 addition & 1 deletion elapid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions elapid/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import importlib.metadata

__version__ = importlib.metadata.version(__package__)
42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[tool.poetry]
name = "elapid"
version = "1.0.2"
description = "Species distribution modeling tools"
authors = ["Christopher Anderson <cbanderson08@gmail.com>"]
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 = ">=1.2"
matplotlib = ">=3.7"

[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"
10 changes: 0 additions & 10 deletions requirements.txt

This file was deleted.

45 changes: 0 additions & 45 deletions setup.py

This file was deleted.

0 comments on commit 15220dc

Please sign in to comment.