Skip to content

Commit

Permalink
🔨 finalize tasks.py
Browse files Browse the repository at this point in the history
Signed-off-by: rjdbcm <[email protected]>
  • Loading branch information
rjdbcm committed Aug 22, 2024
1 parent f6b0982 commit 788d0a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
56 changes: 30 additions & 26 deletions ozi/tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# ozi/tasks.py
# Part of the OZI Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# /// script
# requires-python = ">=3.10"
# dependencies = [ # noqa: E800, RUF100
# 'OZI.build',
# 'build',
# 'cibuildwheel',
# 'invoke',
Expand All @@ -23,24 +28,22 @@

if TYPE_CHECKING:
from invoke.context import Context
from invoke.runners import Result


@task
def setup(c: Context, suite: str = 'dist') -> None:
def setup(c: Context, suite: str = 'dist', draft: bool = False) -> None | Result:
"""Setup a meson build directory for an OZI suite."""
target = Path(f'.tox/{suite}/tmp').absolute() # noqa: S108
env_dir = Path(f'.tox/{suite}').absolute()
c.run(f'meson setup {target} -D{suite}=enabled -Dtox-env-dir={env_dir} --reconfigure')
if draft and suite == 'dist':
return c.run('psr --strict version')


@task
def checkpoint(c: Context, suite: str, maxfail: int = 1) -> None:
"""Run OZI checkpoint suites with meson test."""
target = Path(f'.tox/{suite}/tmp').absolute() # noqa: S108
c.run(f'meson test --no-rebuild --maxfail={maxfail} -C {target} --setup={suite}')


@task
def sign_log(c: Context, suite: str | None = None) -> None:
def sign_checkpoint(c: Context, suite: str | None = None) -> None:
"""Sign checkpoint suites with sigstore."""
banned = './'
host = f'py{sys.version_info.major}{sys.version_info.minor}'
if not suite:
Expand All @@ -59,30 +62,31 @@ def sign_log(c: Context, suite: str | None = None) -> None:
print(f'Meson log not found for suite: {suite}.', file=sys.stderr)


@task
def checkpoint(c: Context, suite: str, maxfail: int = 1) -> None:
"""Run OZI checkpoint suites with meson test."""
target = Path(f'.tox/{suite}/tmp').absolute() # noqa: S108
c.run(f'meson test --no-rebuild --maxfail={maxfail} -C {target} --setup={suite}')
sign_checkpoint(c, suite=suite)


@task(
pre=[
call(sign_log, suite='dist'), # type: ignore
call(sign_log, suite='test'), # type: ignore
call(sign_log, suite='lint'), # type: ignore
call(checkpoint, suite='dist'), # type: ignore
call(checkpoint, suite='test'), # type: ignore
call(checkpoint, suite='lint'), # type: ignore
],
)
def release(c: Context, sdist: bool = False) -> None:
"""Create release wheels for the current interpreter.
:param c: invoke context
:type c: Context
:param sdist: create source distribution tarball, defaults to False
:type sdist: bool, optional
"""
setup(c, suite='dist')
draft = c.run('psr --strict version')
if draft and draft.exited != 0:
def release(c: Context, sdist: bool = False, draft: bool = False, cibuildwheel: bool = True) -> None:
"""Create releases for the current interpreter."""
draft_ = setup(c, suite='dist', draft=draft)
if draft_ and draft_.exited != 0:
return print('No release drafted.', file=sys.stderr)
if sdist:
c.run('python -m build --sdist')
c.run('sigstore sign dist/*.tar.gz')
ext_wheel = c.run('cibuildwheel --prerelease-pythons --output-dir dist .')
if ext_wheel and ext_wheel.exited != 0:
ext_wheel = c.run('cibuildwheel --prerelease-pythons --output-dir dist .') if cibuildwheel else None
if (ext_wheel and ext_wheel.exited != 0) or cibuildwheel:
c.run('python -m build --wheel')
c.run('sigstore sign --output-dir=sig dist/*.whl')

Expand All @@ -94,7 +98,7 @@ def provenance(c: Context) -> None:


@task(provenance)
def publish(c: Context) -> None:
def publish(c: Context, upload: bool = True) -> None:
"""Publishes a release tag"""
c.run('psr publish')
c.run('twine check dist/*')
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -423,5 +423,5 @@ commands =
meson compile -C {env_tmp_dir}
rm -rf {env_tmp_dir}/.gitignore
commands_post =
{env_python} -m invoke --search-root={env_tmp_dir}/ozi {posargs}
{env_python} -m invoke --search-root={env_tmp_dir}/ozi {posargs:--list}
"""

0 comments on commit 788d0a4

Please sign in to comment.