Skip to content

Commit

Permalink
use uv for dependency management during development (#118)
Browse files Browse the repository at this point in the history
* use uv for dependency management during development

Co-authored-by: Pete Gadomski <[email protected]>
  • Loading branch information
hrodmn and gadomski authored Dec 19, 2024
1 parent 6837658 commit f87faca
Show file tree
Hide file tree
Showing 15 changed files with 2,344 additions and 89 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ jobs:
path: ~/conda_pkgs_dir
key: ${{ runner.os }}-conda-${{ hashFiles('**/environment.yml') }}
restore-keys: ${{ runner.os }}-conda-
- name: Set up pip cache
uses: actions/cache@v4
- name: Set up uv
uses: astral-sh/setup-uv@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: ${{ runner.os }}-pip-
version: "0.5.*"
- name: Set up Conda with Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
- name: Update Conda's environemnt
run: conda env update -f environment.yml -n test
- name: Install package
run: uv sync
- name: Execute linters and test suites
run: ./scripts/cibuild
run: uv run ./scripts/test
8 changes: 3 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ repos:
- id: codespell
args: [--ignore-words=.codespellignore]
types_or: [jupyter, markdown, python, shell]
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
hooks:
Expand All @@ -20,6 +16,8 @@ repos:
- click != 8.1.0
- stactools
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.2
rev: v0.8.3
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
10 changes: 5 additions & 5 deletions README-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ We use [pre-commit](https://pre-commit.com/) to check any changes.
To set up your development environment:

```shell
pip install -e '.[dev]'
pre-commit install
uv sync
uv run pre-commit install
```

To check all files:

```shell
pre-commit run --all-files
uv run pre-commit run --all-files
```

To run the tests:

```shell
pytest -vv
uv run pytest -vv
```

If you've updated the STAC metadata output, update the examples:

```shell
scripts/update-examples
uv run scripts/update-examples
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This is a template repo used for creating new packages for `stactools`.
2. Change into the top-level directory of your package and run `scripts/rename`.
This will update _most_ of the files in the repository with your new package name.
3. Update `pyproject.toml` with your package description and such.
4. Install with the development requirements (`pip install -e '.[dev]'`).
4. Install with the development requirements (`uv sync`).
5. Update the LICENSE with your company's information (or whomever holds the copyright).
6. Edit or replace the existing functions to create stac Items and Collections
for your dataset.
Expand Down
43 changes: 28 additions & 15 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,62 @@ FROM continuumio/miniconda3 as base

COPY environment.yml ./
RUN conda update conda && \
conda env update -f environment.yml -n base && \
conda clean -af
conda env update -f environment.yml -n base && \
conda clean -af


FROM base as dependencies

ENV PATH="/opt/venv/bin:$PATH"
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_PYTHON_DOWNLOADS=never \
UV_PYTHON=python3.12 \
UV_PROJECT_ENVIRONMENT=/opt/venv \
PATH="/opt/venv/bin:$PATH"
WORKDIR /opt/stactools-ephemeral
COPY --from=base /opt/conda /opt/conda
COPY pyproject.toml ./
COPY src/stactools/ephemeral/__init__.py src/stactools/ephemeral/
RUN apt-get -y -q update \
&& apt-get -y -q install build-essential \
&& rm -rf /var/lib/apt/lists/
RUN python -m venv /opt/venv
RUN pip install . \
&& ls /opt/venv \
&& rm -r /opt/venv/lib/python3.12/site-packages/stactools/ephemeral
&& apt-get -y -q install build-essential \
&& rm -rf /var/lib/apt/lists/
RUN uv sync --no-install-project --no-editable


FROM dependencies as builder

ENV PATH="/opt/venv/bin:$PATH"
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_PYTHON_DOWNLOADS=never \
UV_PYTHON=python3.12 \
UV_PROJECT_ENVIRONMENT=/opt/venv \
PATH="/opt/venv/bin:$PATH"
WORKDIR /opt/stactools-ephemeral
COPY --from=base /opt/conda /opt/conda
COPY --from=dependencies /opt/venv /opt/venv
COPY pyproject.toml ./
COPY src ./src
RUN pip install -U pip \
&& pip install .
RUN uv sync --no-dev --no-editable
WORKDIR /
RUN rm -rf /opt/stactools-ephemeral
CMD [ "stac", "ephemeralcmd" ]


FROM dependencies as dev-dependencies

ENV PATH="/opt/venv/bin:$PATH"
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_PYTHON_DOWNLOADS=never \
UV_PYTHON=python3.12 \
UV_PROJECT_ENVIRONMENT=/opt/venv \
PATH="/opt/venv/bin:$PATH"
WORKDIR /opt/stactools-ephemeral
COPY --from=dependencies /opt/venv /opt/venv
COPY pyproject.toml .
RUN pip install -e '.[dev]' \
&& git init
RUN uv sync \
&& git init


FROM dev-dependencies as dev-builder
Expand Down
5 changes: 3 additions & 2 deletions docker/cibuild
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
--target dev-builder \
.
docker run --rm \
--entrypoint scripts/cibuild \
stactools-packages/ephemeral:dev
--entrypoint uv \
stactools-packages/ephemeral:dev \
sync
fi
4 changes: 3 additions & 1 deletion docs/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1257,8 +1257,10 @@
],
"source": [
"from pathlib import Path\n",
"from pystac import Collection, Item\n",
"\n",
"from IPython.display import display\n",
"from pystac import Collection\n",
"\n",
"import stactools.ephemeral.stac\n",
"\n",
"root = Path().cwd().parent\n",
Expand Down
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ classifiers = [
requires-python = ">=3.9"
dependencies = ["stactools>=0.4.0"]

[project.optional-dependencies]
[dependency-groups]
dev = [
"black~=24.4",
"codespell~=2.3",
"mypy~=1.10",
"pre-commit~=4.0",
Expand All @@ -42,9 +41,6 @@ Issues = "https://github.com/stactools-packages/ephemeral/issues"
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.isort]
profile = "black"

[tool.mypy]
explicit_package_bases = true
namespace_packages = true
Expand All @@ -53,4 +49,4 @@ strict = true
mypy_path = "src"

[tool.ruff]
select = ["E", "F", "I"]
lint.select = ["E", "F", "I"]
23 changes: 0 additions & 23 deletions scripts/cibuild

This file was deleted.

23 changes: 0 additions & 23 deletions scripts/update

This file was deleted.

3 changes: 2 additions & 1 deletion scripts/update-examples
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import shutil
from pathlib import Path

import stactools.ephemeral.stac
from pystac import CatalogType

import stactools.ephemeral.stac

root = Path(__file__).parents[1]
examples = root / "examples"

Expand Down
1 change: 1 addition & 0 deletions src/stactools/ephemeral/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import click
from click import Command, Group

from stactools.ephemeral import stac

logger = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion src/stactools/ephemeral/stac.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from datetime import datetime, timezone

import stactools.core.create
from pystac import (
Collection,
Extent,
Expand All @@ -9,6 +8,8 @@
TemporalExtent,
)

import stactools.core.create


def create_collection() -> Collection:
"""Creates a STAC Collection.
Expand Down
1 change: 1 addition & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from click import Group
from click.testing import CliRunner
from pystac import Collection, Item

from stactools.ephemeral.commands import create_ephemeralcmd_command

from . import test_data
Expand Down
Loading

0 comments on commit f87faca

Please sign in to comment.