Skip to content

Commit

Permalink
ci: Adds clean, build, publish tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Dec 30, 2024
1 parent 74c10bb commit 9900aa1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tasks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ doc-serve = [
"python -m http.server --bind \"127.0.0.1\" --directory doc/_build/html 8000",
]
doc-publish = ["python tools/sync_website.py --no-commit"]
clean = [
"python -c \"import shutil;shutil.rmtree('dist', ignore_errors=True)\"",
]
build = ["clean", "uv build"]
publish = ["build", "uv publish"]
export-tasks = [
"python -c \"from tools.tasks import app;app.to_path('tasks.toml')\"",
]
Expand Down
58 changes: 57 additions & 1 deletion tools/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


REPO_ROOT: Path = Path(__file__).parent.parent
DIST: Literal["dist"] = "dist"
DOC: Literal["doc"] = "doc"
DOC_BUILD: LiteralString = f"{DOC}/_build"
DOC_IMAGES: LiteralString = f"{DOC}/_images"
Expand Down Expand Up @@ -153,7 +154,62 @@ def doc_publish_clean_build() -> Commands:


# -----------------------------------------------------------------------------
# TODO: Build
# NOTE: Build


@app.task()
def clean() -> Commands:
"""Clean old builds & distributions."""
yield cmd.rm_rf(REPO_ROOT / DIST)


@app.task()
def build() -> Commands:
"""
Create a source distribution and universal wheel.
HACK: Using `uv` explicitly here breaks the independent runner paradigm.
### Other options seem undesirable
1. Using string interpolation (e.g. ``"{runner} build"``)
- Means we need to check **every string** for this case
- Would be more realistic with `PEP 750`_
2. Using some callback to represent the replacement
- Can't see this translating well to ``.toml``,
without needing to introduce special syntax
### Additional Notes
- Only need to use ``uv`` by name for ``uv build``, ``uv publish``.
- Unlikely that ``hatch`` support is going to stay in by the time this merges.
.. _PEP 750:
https://peps.python.org/pep-0750/
"""
yield "clean"
yield "uv build"


@app.task()
def publish() -> Commands:
"""
`Publish`_ to PyPI, using `UV_PUBLISH_TOKEN`_.
Notes
-----
Currently unable to test:
uv publish
"warning: `uv publish` is experimental and may change without warning"
"Publishing 2 files https://upload.pypi.org/legacy/"
"Enter username ('__token__' if using a token):"
.. _Publish:
https://docs.astral.sh/uv/guides/publish/#publishing-your-package
.. _UV_PUBLISH_TOKEN:
https://docs.astral.sh/uv/configuration/environment/#uv_publish_token
"""
yield "build"
yield "uv publish"


# -----------------------------------------------------------------------------
Expand Down

0 comments on commit 9900aa1

Please sign in to comment.