From bf2297a4358ae9dd3821eae9d09decc611c98189 Mon Sep 17 00:00:00 2001 From: pjhartzell Date: Sun, 6 Aug 2023 19:09:33 -0400 Subject: [PATCH] add CI min-dependencies job --- .github/workflows/ci.yaml | 20 +++++++++++++++++ pyproject.toml | 3 ++- scripts/install-min-dependencies | 38 ++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 scripts/install-min-dependencies diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 64fd136..f13d21c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,6 +30,26 @@ jobs: run: pre-commit run --all-files - name: Run tests run: pytest + min-dependencies: + runs-on: ubuntu-latest + steps: + - name: Chekcout + uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.8" + cache: "pip" + - name: Install geos + run: sudo apt-get install libgeos-dev + - name: Install with dev dependencies + run: pip install .[dev] + - name: Install minimum versions of dependencies + run: scripts/install_min_dependencies + - name: Check with pre-commit + run: pre-commit run --all-files + - name: Run tests + run: pytest docs: runs-on: ubuntu-latest defaults: diff --git a/pyproject.toml b/pyproject.toml index 41cabf7..cc56e63 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ classifiers = [ "Programming Language :: Python :: 3", "Development Status :: 2 - Pre-Alpha", ] -dependencies = ["rasterio", "shapely"] +dependencies = ["rasterio>=1.3", "shapely>=2.0"] [project.optional-dependencies] dev = [ @@ -21,6 +21,7 @@ dev = [ "pre-commit~=3.3", "pytest~=7.4", "ruff==0.0.282", + "tomli~=2.0; python_version<'3.11'", ] docs = ["sphinx~=7.1", "pydata-sphinx-theme~=0.13"] diff --git a/scripts/install-min-dependencies b/scripts/install-min-dependencies new file mode 100644 index 0000000..68b15a9 --- /dev/null +++ b/scripts/install-min-dependencies @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +"""Installs the minimum version of all dependencies, with pip. + +Assumptions: +- You've installed the development dependencies: `pip install '.[dev]'` +- All of the dependencies in pyproject.toml are specified with `>=` +""" + +import subprocess +import sys +from pathlib import Path + +from packaging.requirements import Requirement + +assert sys.version_info[0] == 3 +if sys.version_info[1] < 11: + import tomli as toml +else: + import tomllib as toml + + +root = Path(__file__).parents[1] +with open(root / "pyproject.toml", "rb") as f: + pyproject_toml = toml.load(f) +requirements = [] +for install_requires in filter( + bool, + (i.strip() for i in pyproject_toml["project"]["dependencies"]), +): + requirement = Requirement(install_requires) + assert len(requirement.specifier) == 1 + specifier = list(requirement.specifier)[0] + assert specifier.operator == ">=" + install_requires = install_requires.replace(">=", "==") + requirements.append(install_requires) + +subprocess.run(["pip", "install", *requirements], check=True)