Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate from poetry to uv #43

Merged
merged 24 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7635f03
convert poetry toml to uv toml using pdm build backend
rbavery Oct 31, 2024
e19f4b5
correct all commands to use currently active env based on which pytho…
rbavery Oct 31, 2024
26b5705
add lockfile, test precommit with relaxed python version to accomodat…
rbavery Oct 31, 2024
6d32293
remove poetry lock
rbavery Oct 31, 2024
1ae1242
check npm versions in CI, reset before npm run format-markdown
rbavery Nov 1, 2024
634bf2b
gitignore reqs generated from make
rbavery Nov 1, 2024
305e40c
poetry>uv in actions
rbavery Nov 1, 2024
6094b22
code linting with ruff, fix makefile command, ignore line length and …
rbavery Nov 1, 2024
fe16953
update example to 1.0.0
rbavery Nov 1, 2024
5a84905
remove docker, point to uv docs, uv badge
rbavery Nov 1, 2024
15b7aae
line length fix
rbavery Nov 1, 2024
a94aaa5
fix style of uv badge and remove github pages badge
rbavery Nov 1, 2024
8471a49
ignore line length for certain lists, remove remove command
rbavery Nov 5, 2024
d7278bf
make format
rbavery Nov 5, 2024
2d3af0d
Merge branch 'main' into migrate-to-uv
rbavery Nov 5, 2024
277b1d7
fix if condition on linux, linitng
rbavery Nov 5, 2024
a8cf7ca
don't run setup on every command in makefile
rbavery Nov 5, 2024
2a5963d
disable dependabot
rbavery Nov 5, 2024
e15f0ad
temporarily remove dependabot
rbavery Nov 5, 2024
9c18aba
update setup command, add back dependabot
rbavery Nov 11, 2024
34fbf3d
merge main with make lint-all
rbavery Nov 11, 2024
021d0a2
add backticks, remove extra | None
rbavery Nov 11, 2024
eb2e5c6
remove noqa, make format
rbavery Nov 12, 2024
9752f5e
backticks, use Optional instead of | None
rbavery Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/dependabot.yml
rbavery marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
- uses: actions/checkout@v4
- run: |
npm install
npm test
npm list
rbavery marked this conversation as resolved.
Show resolved Hide resolved
npm test
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Project setup

1. If you don't have `uv` installed run:
1. If you don't have uv installed run:

```bash
make setup
Expand All @@ -18,8 +18,8 @@ make install-dev
make pre-commit-install
```

This will install project dependencies into the currently active environment. If you would like to
use uv's default behavior of managing a project-scoped environment, use uv commands directly to
This will install project dependencies into the currently active environment. If you would like to
use uv's default behavior of managing a project-scoped environment, use uv commands directly to
rbavery marked this conversation as resolved.
Show resolved Hide resolved
install dependencies. `uv sync` will install dependencies and dev dependencies in `.venv` and update the `uv.lock`.

## PR submission
Expand Down
38 changes: 11 additions & 27 deletions Makefile
rbavery marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,38 @@ ACTIVEPYTHON = $(shell which python)
#* UV
.PHONY: setup
setup:
@if ! command -v uv &> /dev/null; then \
curl -LsSf https://astral.sh/uv/install.sh | sh; \
else \
echo "uv is already installed"; \
fi

.PHONY: remove
remove:
@read -p "Are you sure you want to remove uv and all its data? [y/N] " confirm && \
if [ "$$confirm" = "y" ]; then \
uv cache clean; \
rm -r "$$(uv python dir)"; \
rm -r "$$(uv tool dir)"; \
rm ~/.cargo/bin/uv ~/.cargo/bin/uvx; \
else \
echo "Operation cancelled."; \
fi
curl -LsSf https://astral.sh/uv/install.sh | sh

.PHONY: publish
publish:
uv publish --build

#* Installation
.PHONY: install
install: setup
install:
uv export --format requirements-txt -o requirements.txt --no-dev
uv pip install --python $(ACTIVEPYTHON) -r requirements.txt

.PHONY: install-dev
install-dev: setup
install-dev:
uv export --format requirements-txt -o requirements-dev.txt
uv pip install --python $(ACTIVEPYTHON) -r requirements-dev.txt

.PHONY: pre-commit-install
pre-commit-install: setup
pre-commit-install:
uv run --python $(ACTIVEPYTHON) pre-commit install

#* Formatters
.PHONY: codestyle
codestyle: setup
codestyle:
uv run --python $(ACTIVEPYTHON) ruff format --config=pyproject.toml stac_model tests

.PHONY: format
format: codestyle

#* Linting
.PHONY: test
test: setup
test:
uv run --python $(ACTIVEPYTHON) pytest -c pyproject.toml --cov-report=html --cov=stac_model tests/

.PHONY: check
Expand All @@ -62,27 +46,27 @@ check: check-examples check-markdown check-lint check-mypy check-safety check-ci
check-all: check

.PHONY: mypy
mypy: setup
mypy:
uv run --python $(ACTIVEPYTHON) mypy --config-file pyproject.toml ./

.PHONY: check-mypy
check-mypy: mypy

.PHONY: check-safety
check-safety: setup
check-safety:
uv run --python $(ACTIVEPYTHON) safety check --full-report
uv run --python $(ACTIVEPYTHON) bandit -ll --recursive stac_model tests

.PHONY: lint
lint: setup
lint:
uv run --python $(ACTIVEPYTHON) ruff check --fix --config=pyproject.toml ./

.PHONY: check-lint
check-lint: lint
uv run --python $(ACTIVEPYTHON) ruff check --config=pyproject.toml ./

.PHONY: format-lint
format-lint: setup lint
format-lint: lint
ruff format --config=pyproject.toml ./

.PHONY: install-npm
Expand Down Expand Up @@ -112,7 +96,7 @@ $(addprefix fix-, $(FORMATTERS)): fix-%: format-%
lint-all: lint mypy check-safety check-markdown

.PHONY: update-dev-deps
update-dev-deps: setup
update-dev-deps:
uv export --only-dev --format requirements-txt -o requirements-only-dev.txt
uv pip install --python $(ACTIVEPYTHON) -r requirements-only-dev.txt

Expand Down
2 changes: 1 addition & 1 deletion README_STAC_MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ _A PydanticV2 and PySTAC validation and serialization library for the STAC ML Mo
pip install -U stac-model
```

or install with `uv`:
or install with uv:

```shell
uv add stac-model
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ stac-model = "stac_model.__main__:app"
# NOTE:
# Although these definitions are provided in this 'stac-model' project file,
# they are actually intented for versioning the MLM specification itself.
# To version 'stac-model', use the 'bumpversion bump' operation.
# To version 'stac-model', use the 'bump-my-version bump' operation.
# See also https://github.com/stac-extensions/mlm/blob/main/CONTRIBUTING.md#building-and-releasing
current_version = "1.3.0"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
Expand Down
32 changes: 30 additions & 2 deletions stac_model/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,37 @@ class MLMStatistic(MLMBaseModel): # FIXME: add 'Statistics' dep from raster ext
valid_percent: Annotated[Number | None, OmitIfNone] = None


NormalizeType: TypeAlias = Literal["min-max", "z-score", "l1", "l2", "l2sqr", "hamming", "hamming2", "type-mask", "relative", "inf"] | None
NormalizeType: TypeAlias = (
Literal[
"min-max",
"z-score",
"l1",
"l2",
"l2sqr",
"hamming",
"hamming2",
"type-mask",
"relative",
"inf",
]
| None
) # noqa: E501

ResizeType: TypeAlias = Literal["crop", "pad", "interpolation-nearest", "interpolation-linear", "interpolation-cubic", "interpolation-area", "interpolation-lanczos4", "interpolation-max", "wrap-fill-outliers", "wrap-inverse-map"] | None
ResizeType: TypeAlias = (
Literal[
"crop",
"pad",
"interpolation-nearest",
"interpolation-linear",
"interpolation-cubic",
"interpolation-area",
"interpolation-lanczos4",
"interpolation-max",
"wrap-fill-outliers",
"wrap-inverse-map",
]
| None
) # noqa: E501
rbavery marked this conversation as resolved.
Show resolved Hide resolved


class ModelBand(MLMBaseModel):
Expand Down
9 changes: 3 additions & 6 deletions stac_model/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,15 @@ def get_schema_uri(cls) -> str:

@overload
@classmethod
def ext(cls, obj: pystac.Asset, add_if_missing: bool = False) -> "AssetMLModelExtension":
...
def ext(cls, obj: pystac.Asset, add_if_missing: bool = False) -> "AssetMLModelExtension": ...

@overload
@classmethod
def ext(cls, obj: pystac.Item, add_if_missing: bool = False) -> "ItemMLModelExtension":
...
def ext(cls, obj: pystac.Item, add_if_missing: bool = False) -> "ItemMLModelExtension": ...

@overload
@classmethod
def ext(cls, obj: pystac.Collection, add_if_missing: bool = False) -> "CollectionMLModelExtension":
...
def ext(cls, obj: pystac.Collection, add_if_missing: bool = False) -> "CollectionMLModelExtension": ...

# @overload
# @classmethod
Expand Down
7 changes: 2 additions & 5 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_mlm_schema(
)
def test_mlm_no_undefined_prefixed_field(
mlm_validator: STACValidator,
mlm_example: Dict[str, JSON],
mlm_example: dict[str, JSON],
) -> None:
mlm_data = copy.deepcopy(mlm_example)
mlm_item = pystac.Item.from_dict(mlm_data)
Expand All @@ -44,10 +44,7 @@ def test_mlm_no_undefined_prefixed_field(
with pytest.raises(pystac.errors.STACValidationError) as exc:
mlm_item = pystac.Item.from_dict(mlm_data)
pystac.validation.validate(mlm_item, validator=mlm_validator)
assert all(
field in str(exc.value.source)
for field in ["mlm:unknown", "^(?!mlm:)"]
)
assert all(field in str(exc.value.source) for field in ["mlm:unknown", "^(?!mlm:)"])


@pytest.mark.parametrize(
Expand Down