Skip to content

Commit

Permalink
chore(ci): build wheels (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
egorchakov authored Aug 23, 2024
1 parent 8261b39 commit d057d81
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 15 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: build

on:
push:
branches: [main]
tags: ["*"]

release:
types: [published]

workflow_dispatch:

jobs:
build-wheels:
runs-on: ubuntu-latest
steps:
- name: setup ssh
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.YAAK_IDL_REPO_SSH_KEY }}

- name: checkout
uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: false

- uses: hynek/build-and-inspect-python-package@v2.8.0
11 changes: 10 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
---
name: CI

on: [push]
on:
push:
branches: [main]

pull_request:

workflow_dispatch:

jobs:
pre-commit:
Expand Down Expand Up @@ -41,6 +47,9 @@ jobs:
- name: uv sync
run: uv sync --all-extras --dev

- name: run build hooks
run: uvx --from hatch hatch build --clean --hooks-only --target sdist

- name: install pre-commit
run: uv tool install --upgrade pre-commit

Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: validate-pyproject

- repo: https://github.com/crate-ci/typos
rev: v1.23.6
rev: v1.23.7
hooks:
- id: typos

Expand All @@ -24,14 +24,14 @@ repos:
exclude: examples/config

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
rev: v0.6.2
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/DetachHead/basedpyright-pre-commit-mirror
rev: 1.16.0
rev: 1.17.0
hooks:
- id: basedpyright

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://github.com/yaak-ai/rbyte/actions/workflows/ci.yaml/badge.svg)
[![CI](https://github.com/yaak-ai/rbyte/actions/workflows/ci.yaml/badge.svg)](https://github.com/yaak-ai/rbyte/actions/workflows/ci.yaml) [![build](https://github.com/yaak-ai/rbyte/actions/workflows/build.yaml/badge.svg)](https://github.com/yaak-ai/rbyte/actions/workflows/build.yaml)

# rbyte

Expand Down
26 changes: 25 additions & 1 deletion hatch_build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging
from collections.abc import Generator
from importlib import resources
from pathlib import Path
from tempfile import NamedTemporaryFile
Expand All @@ -7,6 +9,9 @@
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from protoletariat.fdsetgen import Raw

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)


class BuildYaakIdlProtosHook(BuildHookInterface): # pyright: ignore[reportMissingTypeArgument]
PLUGIN_NAME = "build-yaak-idl-protos"
Expand All @@ -33,10 +38,24 @@ class BuildYaakIdlProtosHook(BuildHookInterface): # pyright: ignore[reportMissi
)
YAAK_IDL_PROTOS = ("can.proto", "sensor.proto")

@override
def clean(self, versions: list[str]) -> None:
for path in self._get_yaak_idl_proto_paths():
if path.exists():
logger.warning("removing %s", path)
path.unlink()

@override
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
self._build_yaak_idl_protos()

@classmethod
def _get_yaak_idl_proto_paths(cls) -> Generator[Path, Any, None]:
for proto in cls.YAAK_IDL_PROTOS:
name, *_ = proto.split(".", maxsplit=1)
for ext in (".py", ".pyi"):
yield (cls.YAAK_IDL_PYTHON_OUT / f"{name}_pb2").with_suffix(ext)

@classmethod
def _build_yaak_idl_protos(cls) -> None:
with NamedTemporaryFile() as descriptor_set_out:
Expand All @@ -57,7 +76,12 @@ def _build_yaak_idl_protos(cls) -> None:
Raw(descriptor_set_out.read()).fix_imports(
python_out=cls.YAAK_IDL_PYTHON_OUT,
create_package=False,
overwrite_callback=lambda file, text: file.write_text(text), # pyright: ignore[reportArgumentType]
overwrite_callback=cls._overwrite_callback,
module_suffixes=["_pb2.py", "_pb2.pyi"],
exclude_imports_glob=["google/protobuf/*"],
)

@staticmethod
def _overwrite_callback(file: Path, text: str) -> None:
logger.warning("overwriting %s", file)
_ = file.write_text(text)
13 changes: 9 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
export HYDRA_FULL_ERROR := "1"
export PYTHONOPTIMIZE := "1"
export HATCH_BUILD_CLEAN := "1"

_default:
@just --list --unsorted

setup:
git submodule update --init --recursive --remote
uv sync --all-extras --dev
uv sync --all-extras
for tool in basedpyright ruff pre-commit; do uv tool install --force --upgrade $tool; done
uvx pre-commit install --install-hooks

clean:
uvx --from hatch hatch clean

build:
uvx --from build pyproject-build --installer uv --wheel
uvx --from build pyproject-build --installer uv

build-protos:
uvx --from hatch hatch build --clean --hooks-only --target sdist

pre-commit:
uvx pre-commit validate-config
uvx pre-commit install --install-hooks
uvx pre-commit run --all-files --color=always

generate-example-config:
Expand Down
15 changes: 10 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ rbyte-build-table = 'rbyte.scripts.build_table:main'
rbyte-visualize = 'rbyte.scripts.visualize:main'

[build-system]
requires = ["hatchling"]
requires = ["hatchling>=1.25.0"]
build-backend = "hatchling.build"

[tool.uv]
Expand All @@ -56,14 +56,19 @@ allow-direct-references = true
[tool.hatch.build]
reproducible = true

[tool.hatch.build.targets.wheel]
packages = ["src/rbyte"]
artifacts = ["src/rbyte/io/table/yaak/proto"]
[tool.hatch.build.targets.sdist]
include = ["src/rbyte"]
exclude = ["src/rbyte/io/table/yaak/idl-repo"]
artifacts = ["src/rbyte/io/table/yaak/proto/*_pb2.py*"]

[tool.hatch.build.hooks.custom]
[tool.hatch.build.targets.sdist.hooks.custom]
enable-by-default = true
require-runtime-features = ["build"]

[tool.hatch.build.targets.wheel]
packages = ["src/rbyte"]
artifacts = ["src/rbyte/io/table/yaak/proto/*_pb2.py*"]

[tool.basedpyright]
typeCheckingMode = "all"
enableTypeIgnoreComments = true
Expand Down

0 comments on commit d057d81

Please sign in to comment.