Skip to content

Commit

Permalink
feat: Add nada-mir-proto package and initial uv support (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
navasvarela authored Nov 6, 2024
1 parent 9892065 commit 1564c77
Show file tree
Hide file tree
Showing 18 changed files with 1,792 additions and 22 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.24"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install . .'[test]' .'[lint]'
run: uv sync --all-extras --dev

- name: Lint with pylint
run: |
pylint nada_dsl/
uv run pylint nada_dsl/
- name: Test with pytest
run: |
pytest
uv run pytest
# Test that the compiled programs are compatible the Nillion backend.
test:
runs-on: ubuntu-latest
Expand Down
57 changes: 56 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,28 @@ jobs:
local_version_is_higher: ${{ steps.versioncheck.outputs.local_version_is_higher }}
local_version: ${{ steps.versioncheck.outputs.local_version }}
remote_version: ${{ steps.versioncheck.outputs.public_version }}
local_nada_mir_version_is_higher: ${{ steps.versioncheck_nada_mir.outputs.local_version_is_higher }}
steps:
- uses: actions/checkout@v4

- name: Check pypi versions
uses: maybe-hello-world/pyproject-check-version@v4
id: versioncheck
with:
pyproject-path: "./pyproject.toml" # default value
pyproject-path: "./pyproject.toml"

- name: Check pypi versions
uses: maybe-hello-world/pyproject-check-version@v4
id: versioncheck_nada_mir
with:
pyproject-path: "nada_mir/pyproject.toml"

- name: check output
run: |
echo "Output: ${{ steps.versioncheck.outputs.local_version_is_higher }}" # 'true' or 'false
echo "Local version: ${{ steps.versioncheck.outputs.local_version }}" # e.g., 0.1.1
echo "Public version: ${{ steps.versioncheck.outputs.public_version }}" # e.g., 0.1.0
echo "nada_mir Output: ${{ steps.versioncheck.outputs.local_version_is_higher }}" # 'true' or 'false"
# Build distribution files
build-distribution:
Expand Down Expand Up @@ -61,6 +69,30 @@ jobs:
with:
name: python-package-distributions
path: dist/
build-nada-mir-distribution:
needs: checkversion
if: needs.checkversion.outputs.local_nada_mir_version_is_higher == 'true'
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "^3.10"
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.24"
- name: Install pypa/build
run: >-
uv build --package nada-mir-proto -o nada_mir/dist
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: nada-mir-python-package-distributions
path: nada_mir/dist/

# Generates a Github release with the version taken from the one in pyproject.toml
github-release:
Expand Down Expand Up @@ -124,3 +156,26 @@ jobs:
- name: Publish distribution 📦 to PyPI
# Publishes using trusted publishers
uses: pypa/gh-action-pypi-publish@release/v1
publish-to-pypi-nada-mir:
needs: [checkversion, build-distribution]
if: needs.checkversion.outputs.local_nada_mir_version_is_higher == 'true'
name: >-
Publish nada-mir-proto Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/nada-mir-proto/
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: nada-mir-python-package-distributions
path: nada_mir/dist/
- name: Publish distribution 📦 to PyPI
# Publishes using trusted publishers
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: nada_mir/dist/
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@

doc:
python -m pip install '.[docs]' && sphinx-build docs docs/_build
uv run sphinx-build docs docs/_build

release:
pip install --upgrade build wheel
python -m build --no-isolation

lint:
pylint nada_dsl/
uv run pylint nada_dsl/

test-dependencies:
pip install .'[test]'

test: test-dependencies
pytest
pytest

# Build protocol buffers definitions.
build_proto:
nada_mir/scripts/gen_proto.sh
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ python -m pip install '.[docs]'
cd docs
sphinx-build . _build
```

# Developing

This tool uses [uv](https://docs.astral.sh/uv/) to manage itself. Make sure to have it installed for your platform.

You can install dependencies running (at the root folder of the project):

```
uv sync
```

Then activate the virtual environment:

```
source .venv/bin/activate
```
2 changes: 2 additions & 0 deletions nada_mir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# NADA MIR
This package contains the protocol buffers representation of the MIR model, defined in: https://github.com/NillionNetwork/nada-mir-model.
21 changes: 21 additions & 0 deletions nada_mir/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "nada-mir-proto"
version = "0.1.0"
description = "The protocol buffers representation of the Nada MIR."
requires-python = ">=3.10"
license = { text = "MIT" }
readme = "README.md"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

dependencies = ["grpcio-tools==1.62.3", "betterproto==2.0.0b7"]

[project.optional-dependencies]
dev = ["betterproto[compiler]==2.0.0b7"]
28 changes: 28 additions & 0 deletions nada_mir/scripts/gen_proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# Script to generate protocol buffer bindings for the Nada MIR.
# This script needs to be run to update the protocol buffer definitions every time there's a change
# in `nada-mir-model`.
set -e

SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}" 2>/dev/null)" && pwd -P)"

# This is the path where nada-mir-model has been checked out in your workstation
NADA_MIR_MODEL_ROOT=${SCRIPT_PATH}/../../../nada-mir-model
GRPC_ROOT=${NADA_MIR_MODEL_ROOT}/proto

mir_files=(
"nillion/nada/v1/mir.proto"
"nillion/nada/v1/operations.proto"
"nillion/nada/v1/types.proto"
)


OUTPUT_DIR=${SCRIPT_PATH}/../src/nada_mir_proto

mkdir -p ${OUTPUT_DIR}

cd ${SCRIPT_PATH}/../src

for file in "${mir_files[@]}"; do
python -m grpc_tools.protoc -I${GRPC_ROOT} --python_betterproto_out=nada_mir_proto $file
done
Empty file.
Empty file.
Empty file.
Empty file.
169 changes: 169 additions & 0 deletions nada_mir/src/nada_mir_proto/nillion/nada/mir/v1/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Loading

0 comments on commit 1564c77

Please sign in to comment.