Skip to content

Commit

Permalink
Merge pull request #43 from zarr-developers/chore/dump-poetry
Browse files Browse the repository at this point in the history
refactor the entire build system to use hatch instead of poetry.
  • Loading branch information
d-v-b authored Jan 30, 2025
2 parents c6d1915 + 92f7e76 commit cb5ac81
Show file tree
Hide file tree
Showing 22 changed files with 442 additions and 1,753 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
actions:
patterns:
- '*'
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
if:
if:
startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/checkout@v3
Expand All @@ -23,4 +23,4 @@ jobs:
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
password: ${{ secrets.PYPI_API_TOKEN }}
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci
name: ci
on:
push:
branches:
Expand All @@ -13,14 +13,13 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: |
pip install poetry
poetry install --with docs
poetry run mkdocs gh-deploy --force
pip install hatch
hatch run docs:deploy --force
80 changes: 70 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,84 @@
name: Linux Testing
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
test:
name: os=${{ matrix.os }}, py=${{ matrix.python-version }}, np=${{ matrix.numpy-version }}, deps=${{ matrix.dependency-set }}

strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
python-version: ['3.11', '3.12', '3.13']
numpy-version: ['1.25', '2.1']
dependency-set: ["minimal", "optional"]
os: ["ubuntu-latest"]
include:
- python-version: '3.11'
numpy-version: '1.25'
dependency-set: 'optional'
os: 'macos-latest'
- python-version: '3.13'
numpy-version: '2.1'
dependency-set: 'optional'
os: 'macos-latest'
- python-version: '3.11'
numpy-version: '1.25'
dependency-set: 'optional'
os: 'windows-latest'
- python-version: '3.13'
numpy-version: '2.1'
dependency-set: 'optional'
os: 'windows-latest'
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install Hatch
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Run Tests
run: |
hatch run test.py${{ matrix.python-version }}:test-cov
- name: Upload coverage
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true # optional (default = false)

doctests:
name: doctests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
shell: "bash -l {0}"
with:
fetch-depth: 0 # required for hatch version discovery, which is needed for numcodecs.zarr3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install Hatch
run: |
pip install poetry
poetry install
- name: Test
python -m pip install --upgrade pip
pip install hatch
- name: Run Tests
run: |
poetry run pytest
hatch run docs:test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# VCS versioning
src/pydantic_zarr/_version.py
49 changes: 37 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autoupdate_schedule: "monthly"
autofix_commit_msg: "style: pre-commit fixes"
default_stages: [commit, push]
default_language_version:
python: python3
autofix_prs: false
default_stages: [pre-commit, pre-push]
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: ["-L", "fo,ihs,kake,te", "-S", "fixture"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: check-yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.4
- id: check-yaml
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.14.1
hooks:
- id: mypy
files: src|tests
additional_dependencies:
- pytest
- pydantic
- repo: https://github.com/scientific-python/cookie
rev: 2024.08.19
hooks:
- id: sp-repo-review
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/numpy/numpydoc
rev: v1.8.0
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
- id: numpydoc-validation
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This project is under flux -- I want to add [zarr version 3](https://zarr-specs.
## Getting help

- Docs: see the [documentation](https://zarr.dev/pydantic-zarr/) for detailed information about this project.
- Chat: We use [Zulip](https://ossci.zulipchat.com/#narrow/channel/423692-Zarr) for project-related chat.
- Chat: We use [Zulip](https://ossci.zulipchat.com/#narrow/channel/423692-Zarr) for project-related chat.

## Example

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![PyPI](https://img.shields.io/pypi/v/pydantic-zarr)](https://pypi.python.org/pypi/pydantic-zarr)

Static typing and runtime validation for Zarr hierachies.
Static typing and runtime validation for Zarr hierarchies.

## Overview

Expand Down
28 changes: 14 additions & 14 deletions docs/usage_zarr_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ instances, then providing those objects as `members` to the constructor of anoth
other words, with this approach we create "child nodes" and give those nodes to the "parent node",
recursively.

Constructing deeply nested hierarchies this way can be tedious.
Constructing deeply nested hierarchies this way can be tedious.
For this reason, `pydantic-zarr` supports an alternative representation of the Zarr
hierarchy in the form of a dictionary with `str` keys and `ArraySpec` / `GroupSpec` values, and
methods to convert to / from these dictionaries.
Expand All @@ -118,11 +118,11 @@ This example demonstrates how to create a `GroupSpec` from a `dict` representati

```python
from pydantic_zarr.v2 import GroupSpec, ArraySpec
# other than the key representing the root path "",
# other than the key representing the root path "",
# the keys must be valid paths in the Zarr storage hierarchy
# note that the `members` attribute is `None` for the `GroupSpec` instances in this `dict`.
tree = {
"": GroupSpec(members=None, attributes={"root": True}),
"": GroupSpec(members=None, attributes={"root": True}),
"/a": GroupSpec(members=None, attributes={"root": False}),
"/a/b": ArraySpec(shape=(10,10), dtype="uint8", chunks=(1,1))
}
Expand Down Expand Up @@ -158,12 +158,12 @@ print(GroupSpec.from_flat(tree).model_dump())

#### flattening `GroupSpec` objects

This is similar to the example above, except that we are working in reverse -- we are making the
This is similar to the example above, except that we are working in reverse -- we are making the
flat `dict` from the `GroupSpec` object.

```python
from pydantic_zarr.v2 import GroupSpec, ArraySpec
# other than the key representing the root path "",
# other than the key representing the root path "",
# the keys must be valid paths in the Zarr storage hierarchy
# note that the `members` attribute is `None` for the `GroupSpec` instances in this `dict`.

Expand Down Expand Up @@ -193,9 +193,9 @@ print(root.to_flat())
```

#### Implicit groups
`zarr-python` supports creating Zarr arrays or groups deep in the
hierarchy without explicitly creating the intermediate groups first.
`from_flat` models this behavior. For example, `{'/a/b/c': ArraySpec(...)}` implicitly defines the existence of a groups named `a` and `b` (which is contained in `a`). `from_flat` will create the expected `GroupSpec` object from such `dict` instances.
`zarr-python` supports creating Zarr arrays or groups deep in the
hierarchy without explicitly creating the intermediate groups first.
`from_flat` models this behavior. For example, `{'/a/b/c': ArraySpec(...)}` implicitly defines the existence of a groups named `a` and `b` (which is contained in `a`). `from_flat` will create the expected `GroupSpec` object from such `dict` instances.

```python
from pydantic_zarr.v2 import GroupSpec, ArraySpec
Expand Down Expand Up @@ -237,7 +237,7 @@ print(GroupSpec.from_flat(tree).model_dump())

## Comparing `GroupSpec` and `ArraySpec` models

`GroupSpec` and `ArraySpec` both have `like` methods that take another `GroupSpec` or `ArraySpec` as an argument and return `True` (the models are like each other) or `False` (the models are not like each other).
`GroupSpec` and `ArraySpec` both have `like` methods that take another `GroupSpec` or `ArraySpec` as an argument and return `True` (the models are like each other) or `False` (the models are not like each other).

The `like` method works by converting both input models to `dict` via `pydantic.BaseModel.model_dump`, and comparing the `dict` representation of the models. This means that instances of two different subclasses of `GroupSpec`, which would not be considered equal according to the `==` operator, will be considered `like` if and only if they serialize to identical `dict` instances.

Expand All @@ -251,7 +251,7 @@ arr_a = ArraySpec(shape=(1,), dtype='uint8', chunks=(1,))
arr_b = ArraySpec(shape=(2,), dtype='uint8', chunks=(1,))

# Returns False, because of mismatched shape
print(arr_a.like(arr_b))
print(arr_a.like(arr_b))
#> False

# Returns True, because we exclude shape.
Expand All @@ -264,11 +264,11 @@ store = zarr.MemoryStore()
arr_a_stored = arr_a.to_zarr(store, path='arr_a')

# arr_a is like the zarr.Array version of itself
print(arr_a.like(arr_a_stored))
print(arr_a.like(arr_a_stored))
#> True

# Returns False, because of mismatched shape
print(arr_b.like(arr_a_stored))
print(arr_b.like(arr_a_stored))
#> False

# Returns True, because we exclude shape.
Expand All @@ -284,7 +284,7 @@ print(g_a.like(g_a))
#> True

# Returns False, because of mismatched attributes
print(g_a.like(g_b))
print(g_a.like(g_b))
#> False

# Returns True, because we ignore attributes
Expand Down Expand Up @@ -335,7 +335,7 @@ print(SpecificAttrsGroup(attributes={'a': 100, 'b': 100}))
#> zarr_version=2 attributes={'a': 100, 'b': 100} members={}

# a Zarr group that only contains arrays -- no subgroups!
# we re-use the TAttr type variable defined in pydantic_zarr.core
# we reuse the TAttr type variable defined in pydantic_zarr.core
ArraysOnlyGroup = GroupSpec[TAttr, ArraySpec]

try:
Expand Down
4 changes: 2 additions & 2 deletions docs/usage_zarr_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Disclaimer

At the moment, [Zarr version 3](https://zarr-specs.readthedocs.io/en/latest/v3/core/v3.0.html) is only *barely* support by this project. That will likely
change when the Zarr storage backend used here ([`zarr-python`](https://zarr.readthedocs.io/en/stable/))
At the moment, [Zarr version 3](https://zarr-specs.readthedocs.io/en/latest/v3/core/v3.0.html) is only *barely* support by this project. That will likely
change when the Zarr storage backend used here ([`zarr-python`](https://zarr.readthedocs.io/en/stable/))
fully implements version 3. Until then, the only Zarr v3 stuff you can do with this repo
is create abstract hierarchies. You cannot use the `to_zarr` or `from_zarr` methods, because
the backend for that doesn't exist.
Expand Down
4 changes: 2 additions & 2 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ copyright: Copyright © 2016 - 2024 HHMI / Janelia

theme:
name: material
palette:
palette:
# Palette toggle for light mode
- scheme: default
toggle:
icon: material/brightness-7
icon: material/brightness-7
name: Switch to dark mode

# Palette toggle for dark mode
Expand Down
Loading

0 comments on commit cb5ac81

Please sign in to comment.