|
| 1 | +from typing import Annotated |
| 2 | + |
| 3 | +import dagger |
| 4 | +from dagger import DefaultPath, Doc, Ignore, check, dag, field, function, object_type |
| 5 | + |
| 6 | +_SOURCE_IGNORE = [ |
| 7 | + "**/__pycache__", |
| 8 | + "**/*.pyc", |
| 9 | + "**/.git", |
| 10 | + "**/.pixi", |
| 11 | + "**/.venv", |
| 12 | + "**/.pytest_cache", |
| 13 | + "**/.ruff_cache", |
| 14 | + "**/.mypy_cache", |
| 15 | + "**/.direnv", |
| 16 | + "**/.devenv", |
| 17 | + "**/node_modules", |
| 18 | + "**/dist", |
| 19 | + "**/build", |
| 20 | + "**/*.egg-info", |
| 21 | + "**/sdk", |
| 22 | +] |
| 23 | + |
| 24 | + |
| 25 | +def _base() -> dagger.Container: |
| 26 | + return dag.container().from_("ghcr.io/prefix-dev/pixi:0.70.2").with_workdir("/workspace") |
| 27 | + |
| 28 | + |
| 29 | +@object_type |
| 30 | +class AsciiDaggerverse: |
| 31 | + """CI and docs helpers for the ASCII Daggerverse repository.""" |
| 32 | + |
| 33 | + source: Annotated[ |
| 34 | + dagger.Directory, |
| 35 | + Doc("Repository root."), |
| 36 | + DefaultPath("."), |
| 37 | + Ignore(_SOURCE_IGNORE), |
| 38 | + ] = field() |
| 39 | + |
| 40 | + @check |
| 41 | + @function |
| 42 | + async def python(self) -> None: |
| 43 | + """Run Python unit and lint checks through the root Pixi environment.""" |
| 44 | + ctr = ( |
| 45 | + _base() |
| 46 | + .with_directory("/workspace", self.source) |
| 47 | + .with_mounted_cache("/root/.cache/rattler/cache", dag.cache_volume("pixi-rattler-cache")) |
| 48 | + .with_mounted_cache("/root/.cache/pixi", dag.cache_volume("pixi-cache")) |
| 49 | + .with_env_variable("PIXI_NO_PROGRESS", "true") |
| 50 | + ) |
| 51 | + await ( |
| 52 | + ctr.with_exec(["pixi", "install", "--locked", "--environment", "default"]) |
| 53 | + .with_exec(["pixi", "run", "--frozen", "test"]) |
| 54 | + .with_exec(["pixi", "run", "--frozen", "lint"]) |
| 55 | + .with_exec(["pixi", "run", "--frozen", "format-check"]) |
| 56 | + .sync() |
| 57 | + ) |
| 58 | + |
| 59 | + @function |
| 60 | + async def docs_build(self) -> dagger.Directory: |
| 61 | + """Build the static docs site.""" |
| 62 | + ctr = ( |
| 63 | + _base() |
| 64 | + .with_directory("/workspace", self.source) |
| 65 | + .with_mounted_cache("/root/.cache/rattler/cache", dag.cache_volume("pixi-rattler-cache")) |
| 66 | + .with_mounted_cache("/root/.cache/pixi", dag.cache_volume("pixi-cache")) |
| 67 | + .with_env_variable("PIXI_NO_PROGRESS", "true") |
| 68 | + .with_exec(["pixi", "run", "--frozen", "python", "-m", "zensical", "build", "-f", "pixi/zensical.toml"]) |
| 69 | + ) |
| 70 | + return ctr.directory("/workspace/pixi/site") |
| 71 | + |
| 72 | + @check |
| 73 | + @function |
| 74 | + async def docs(self) -> None: |
| 75 | + """Build the module documentation site.""" |
| 76 | + await (await self.docs_build()).sync() |
0 commit comments