Skip to content

Commit

Permalink
feat: use pyproject.toml
Browse files Browse the repository at this point in the history
Includes a pre-commit autoupdate. No functional code changes.
  • Loading branch information
gadomski committed May 12, 2023
1 parent 2b131f6 commit 0055bcb
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .github/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ runs:
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('setup.cfg', 'requirements-dev.txt') }}
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: ${{ runner.os }}-pip-
- name: Set up pre-commit cache
uses: actions/cache@v2
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install with extra_requires
run: pip install '.[all]'
- name: Install development dependencies
run: pip install -r requirements-dev.txt
run: pip install .[s3,dev]
- name: Test
run: ./scripts/test
minimum-versions:
Expand All @@ -63,12 +61,10 @@ jobs:
- uses: ./.github/setup
with:
python-version: ${{ matrix.python-version }}
- name: Install development dependencies
run: pip install -r requirements-dev.txt
- name: Install the package
run: pip install .[dev]
- name: Install the minimum requirements
run: scripts/install-min-requirements
- name: Install the package
run: pip install .
- name: Test
run: scripts/test
pre-release-versions:
Expand Down
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.258
rev: v0.0.265
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
Expand All @@ -21,7 +22,7 @@ repos:
hooks:
- id: doc8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
rev: v1.3.0
hooks:
- id: mypy
# TODO lint test and scripts too
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Use `pyproject.toml` for project metadata ([#424](https://github.com/stac-utils/stactools/pull/424))

## [0.4.7] - 2023-05-08

### Changed
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ docker pull ghcr.io/stac-utils/stactools:latest
stac --help
```

### Docker
### Running from docker

```sh
docker run --rm ghcr.io/stac-utils/stactools:latest --help
```

## Documentation

See the [documentation page](https://stactools.readthedocs.io/en/latest/) for the latest docs.
See the [documentation page](https://stactools.readthedocs.io/) for the latest docs.

## Packages

Expand Down Expand Up @@ -118,15 +118,12 @@ Third-party packages can be installed in the same way, or, if they are not on Py

## Developing

Basic development can be done with your system's default Python, though it it recommended to use a virtual environment.
E.g.:
Clone the repository and install it in editable mode with the `dev` optional dependencies:

```sh
git clone https://github.com/stac-utils/stactools.git
cd stactools
python -m venv venv
pip install -e . # install stactools into the virtual environment in editable mode
pip install -r requirements-dev.txt # install development requirements
pip install -e '.[dev]'
```

Linting and formatting are handled with [pre-commit](https://pre-commit.com/).
Expand Down Expand Up @@ -205,13 +202,12 @@ conda activate stactools
Finally, install `stactools` in editable mode and all development requirements:

```sh
pip install -e .
pip install -r requirements-dev.txt
pip install -e '.[dev]'
```

### Documentation
### Developing the docs

To build and serve the docs, the development requirements must be installed with `pip install -r requirements-dev.txt`.
To build and serve the docs, the development requirements must be installed with `pip install -e '.[dev]'`.
To build the docs, you can use `make html` from inside of the docs directory, and to build the docs and start a server that watches for changes, use `make livehtml`:

```sh
Expand Down
12 changes: 5 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ FROM base as dep_builder
RUN apt-get update \
&& apt-get install -y gcc build-essential \
&& rm -rf /var/lib/apt/lists/*
COPY pyproject.toml setup.cfg ./
COPY pyproject.toml ./
COPY src/stactools/core/__init__.py src/stactools/core/
# Install dependencies but remove the actual package
RUN pip install --prefix=/install .[all] \
RUN pip install --prefix=/install .[s3] \
&& rm -r /install/lib/*/site-packages/stactools*


Expand All @@ -28,16 +28,14 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*
COPY --from=dep_builder /install /opt/conda
RUN conda install -c conda-forge pandoc && conda clean -af
COPY requirements-dev.txt ./
RUN pip install -r requirements-dev.txt
COPY . ./
# pre-commit run --all-files fails w/o this line
RUN git init
RUN pip install -e .[all]
RUN pip install -e .[dev,s3]


FROM base AS main
COPY --from=dep_builder /install /opt/conda
COPY src ./src
COPY pyproject.toml setup.cfg ./
RUN pip install .[all]
COPY pyproject.toml ./
RUN pip install .[s3]
22 changes: 0 additions & 22 deletions mypy.ini

This file was deleted.

102 changes: 102 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,108 @@
[project]
name = "stactools"
description = "Command line tool and Python library for working with STAC"
readme = "README.md"
authors = [
{ name = "Rob Emanuele", email = "[email protected]" },
{ name = "Pete Gadomski", email = "[email protected]" },
]
maintainers = [{ name = "Pete Gadomski", email = "[email protected]" }]
license = { text = "Apache-2.0" }
keywords = [
"pystac",
"imagery",
"raster",
"catalog",
"STAC",
]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
requires-python = ">=3.8"
dependencies = [
"Shapely>=1.8.5.post1",
"aiohttp>=3.8.3",
"click>=8.1.3",
"fsspec>=2021.7",
"lxml>=4.9.2",
"numpy>=1.22.0",
"pyproj>=3.3",
"pystac[validation]>=1.6.1",
"rasterio>=1.3.2",
"requests>=2.27.1",
"stac-check>=1.3.2",
"stac-validator>=3.1.0",
]
dynamic = ["version"]

[project.urls]
homepage = "https://github.com/stac-utils/stactools"
documentation = "https://stactools.readthedocs.io/"
repository = "https://github.com/stac-utils/stactools.git"
changelog = "https://github.com/stac-utils/stactools/blob/main/CHANGELOG.md"
discussions = "https://github.com/radiantearth/stac-spec/discussions/categories/stac-software"

[project.scripts]
stac = "stactools.cli.cli:run_cli"

[project.optional-dependencies]
dev = [
"black~=23.3",
"codespell~=2.2",
"importlib-metadata~=6.6",
"ipython~=8.12",
"jupyter~=1.0",
"lxml-stubs~=0.4",
"mypy~=1.3",
"nbsphinx~=0.9",
"packaging~=23.1",
"pre-commit~=3.3",
"pydata-sphinx-theme~=0.13",
"pylint~=2.17",
"pytest~=7.3",
"pytest-cov~=3.0",
"ruff==0.0.265",
"sphinx~=7.0",
"sphinx-autobuild==2021.3.14",
"sphinx-click~=4.4",
"sphinxcontrib-napoleon~=0.7",
"types-certifi~=2021.10.8",
"types-orjson~=3.6",
"types-python-dateutil~=2.8",
"types-requests~=2.30",
]
s3 = ["s3fs>=2021.7"]

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic]
version = { attr = "stactools.core.__version__" }

[tool.ruff]
line-length = 88
select = ["E", "F", "I"]

[tool.mypy]
mypy_path = "src"
explicit_package_bases = true
namespace_packages = true
show_error_codes = true
strict = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = [
"fsspec",
"osgeo",
"rasterio",
"s3fs",
"shapely"
]
ignore_missing_imports = true
23 changes: 0 additions & 23 deletions requirements-dev.txt

This file was deleted.

19 changes: 13 additions & 6 deletions scripts/install-min-requirements
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""Installs the minimum version of all stactools dependencies, with pip.
Assumptions:
- You've installed the development dependencies: `pip install -r requirements-dev.txt`
- All of the dependencies in setup.cfg are specified with `>=`
- You've installed the development dependencies: `pip install '.[dev]'`
- All of the dependencies in pyproject.toml are specified with `>=`
For more context on the approach and rationale behind testing against minimum
requirements, see
Expand All @@ -13,18 +13,25 @@ https://www.gadom.ski/2022/02/18/dependency-protection-with-python-and-github-ac
"""

import subprocess
from configparser import ConfigParser
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]
setup_cfg = ConfigParser()
setup_cfg.read(root / "setup.cfg")
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 setup_cfg["options"]["install_requires"].splitlines()),
(i.strip() for i in pyproject_toml["project"]["dependencies"]),
):
requirement = Requirement(install_requires)
assert len(requirement.specifier) == 1
Expand Down
3 changes: 1 addition & 2 deletions scripts/update
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
usage
else
python -m pip install --upgrade pip
pip install .
pip install -r requirements-dev.txt
pip install '.[dev]'
fi
fi
Loading

0 comments on commit 0055bcb

Please sign in to comment.