Skip to content

Commit

Permalink
- support for bazelmod
Browse files Browse the repository at this point in the history
- building wheels with bazel
- support for macOS via not standard array_record library
- support for ci tagging and versioning
  • Loading branch information
vyeevani committed Oct 2, 2024
1 parent 0f55c56 commit 5c37fb4
Show file tree
Hide file tree
Showing 32 changed files with 1,408 additions and 400 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --enable_bzlmod
75 changes: 75 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build and Save Python Wheel

on:
push:
branches:
- '**' # Build on all branches
tags:
- 'v*' # Trigger the release workflow only when a tag is pushed (e.g., v1.0.0)

jobs:
build:
strategy:
matrix:
os: [macos-latest, ubuntu-latest] # Specify both macOS and Linux environments
runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Ensures that the full history is cloned to handle any branch-specific build needs

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install setuptools wheel
# Run the build script and capture the output directory
- name: Run build script
id: build
run: |
bazel run //:requirements.update
bazel build ...
- name: Run Bazel Tests
run: |
bazel test ...
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: built-wheels-${{ matrix.os }}
path: bazel-bin/*.whl

release:
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v') # Only run this job if a tag starting with "v" is pushed
steps:
- name: Download Artifacts from macOS
uses: actions/download-artifact@v3
with:
name: built-wheels-macos-latest
path: ./artifacts/macos

- name: Download Artifacts from Linux
uses: actions/download-artifact@v3
with:
name: built-wheels-ubuntu-latest
path: ./artifacts/linux

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }} # Use the current tag name as the release version
files: |
artifacts/macos/*.whl
artifacts/linux/*.whl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 changes: 0 additions & 47 deletions .github/workflows/tests.yml

This file was deleted.

128 changes: 128 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Byte-compiled files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
venv/
ENV/
env.bak/
venv.bak/
*.egg-info/
dist/
build/
eggs/
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Virtual environments
*.env
*.venv

# PyInstaller
*.manifest
*.spec

# Unit test / coverage reports
*.cover
*.py,cover
.cache
coverage.*
.tox/
nosetests.xml
*.log

# Pytest
.pytest_cache/

# mypy
.mypy_cache/
dmypy.json
dmypy.json.*

# Pyre
.pyre/

# Jupyter Notebook checkpoints
.ipynb_checkpoints

# VSCode settings
.vscode/

# IDE directories
.idea/
*.iml

# Sublime Text project files
*.sublime-project
*.sublime-workspace

# macOS files
.DS_Store

# Windows files
Thumbs.db
# Bazel directories
bazel-*

# Bazel outputs
bazel-bin/
bazel-out/
bazel-testlogs/
bazel-genfiles/

# Bazel caches
bazel-cache/
bazel-workspace/
.bazelrc.user
.bazelignore
*.bazelproject

# Bazel module files
modules/
bazel.lock
bazel_external/
bazel_dep_graph.dot

# Build outputs
build/
dist/
out/

# Temporary files
*.log
*.tmp
*.temp
*.swp
*.bak

# IDE settings
.idea/
.project
*.iml
.vscode/

# Operating system files
.DS_Store
Thumbs.db

# C++ build artifacts (if you have native rules)
*.o
*.obj
*.exe
*.dll
*.dylib
*.so

# Python build artifacts (if you use py_rules)
__pycache__/
*.py[cod]
*.pyo
31 changes: 31 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,34 @@ py_library(
srcs = ["setup.py"],
srcs_version = "PY3",
)

load("@rules_python//python:defs.bzl", "py_binary", "py_test")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
load("@rules_python//python:packaging.bzl", "py_wheel", 'py_package')

compile_pip_requirements(
name = "requirements",
src = "requirements.in",
requirements_txt = "requirements_lock.txt",
requirements_darwin = "requirements_darwin.txt",
requirements_linux = "requirements_linux.txt",
)

py_package(
name="grain_pkg",
packages=["grain"],
deps=["//grain:core", "//grain:python", "//grain:python_experimental", "//grain:python_lazy_dataset"]
)

py_wheel(
name = "grain_whl",
distribution = "grain",
version = "0.2.2",
platform = select({
"@platforms//os:macos": "macosx_14_0_arm64",
"@platforms//os:linux": "manylinux2014_x86_64",
}),
deps = [
"grain_pkg"
],
)
31 changes: 31 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module(
name = "grain",
version = "0.1.0",
)

bazel_dep(name = "rules_python", version = "0.36.0")
bazel_dep(name = "pybind11_bazel", version = "2.12.0")
bazel_dep(name = "platforms", version = "0.0.10")

SUPPORTED_PYTHON_VERSIONS = [
"3.10",
]
DEFAULT_PYTHON_VERSION = SUPPORTED_PYTHON_VERSIONS[-1]
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
[
python.toolchain(
python_version = version,
is_default = version == DEFAULT_PYTHON_VERSION,
)
for version in SUPPORTED_PYTHON_VERSIONS
]

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pypi_grain",
python_version = "3.10",
requirements_lock = "//:requirements_lock.txt",
requirements_darwin = "//:requirements_darwin.txt",
requirements_linux = "//:requirements_linux.txt"
)
use_repo(pip, "pypi_grain")
Loading

0 comments on commit 5c37fb4

Please sign in to comment.