All Projects → soniaai → rules_poetry

soniaai / rules_poetry

Licence: MIT License
Bazel rules that use Poetry for Python package management

Programming Languages

Starlark
911 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to rules poetry

Rules python
Experimental Bazel Python Rules
Stars: ✭ 233 (+482.5%)
Mutual labels:  bazel, bazel-rules, pip
rules gitops
This repository contains rules for continuous, GitOps driven Kubernetes deployments.
Stars: ✭ 112 (+180%)
Mutual labels:  bazel, bazel-rules
rules sass
Sass rules for Bazel
Stars: ✭ 47 (+17.5%)
Mutual labels:  bazel, bazel-rules
pipm
Python dependency management workflow using setup.cfg and requirements files without reinventing the wheels
Stars: ✭ 30 (-25%)
Mutual labels:  pip, python-package-management
rules ocaml
OCaml build rules for Bazel
Stars: ✭ 38 (-5%)
Mutual labels:  bazel, bazel-rules
rules dart
Dart rules for Bazel
Stars: ✭ 35 (-12.5%)
Mutual labels:  bazel, bazel-rules
rules java
Java rules for Bazel
Stars: ✭ 44 (+10%)
Mutual labels:  bazel, bazel-rules
rules proto grpc
Bazel rules for building Protobuf and gRPC code and libraries from proto_library targets
Stars: ✭ 201 (+402.5%)
Mutual labels:  bazel, bazel-rules
rules elm
Bazel rules for building web applications written in Elm
Stars: ✭ 22 (-45%)
Mutual labels:  bazel, bazel-rules
ios-bazel-users
Resources for using bazel for iOS development
Stars: ✭ 80 (+100%)
Mutual labels:  bazel, bazel-rules
poetry-setup
Generate setup.py (setuptools) from pyproject.toml (poetry)
Stars: ✭ 44 (+10%)
Mutual labels:  poetry, pip
rules gwt
Bazel rules for GWT
Stars: ✭ 20 (-50%)
Mutual labels:  bazel, bazel-rules
bazel-latex
Bazel build system rules for LaTeX
Stars: ✭ 67 (+67.5%)
Mutual labels:  bazel, bazel-rules
symmetric
A powerful tool to enable super fast module-to-API transformations. Learn in minutes, implement in seconds. Batteries included.
Stars: ✭ 65 (+62.5%)
Mutual labels:  poetry, pip
rules antlr
ANTLR rules for Bazel
Stars: ✭ 24 (-40%)
Mutual labels:  bazel, bazel-rules
rules appengine
AppEngine rules for Bazel
Stars: ✭ 28 (-30%)
Mutual labels:  bazel, bazel-rules
rules verilator
Bazel build rules for Verilator
Stars: ✭ 14 (-65%)
Mutual labels:  bazel, bazel-rules
rules openapi
🍃 bazel rules for generating code from openapi specifications
Stars: ✭ 49 (+22.5%)
Mutual labels:  bazel, bazel-rules
bazel-maven-proxy
A local (read-only) proxy for Bazel to access Maven resources behind a secure repository or from the local Maven repository
Stars: ✭ 22 (-45%)
Mutual labels:  bazel, bazel-rules
rules helm
rules_helm: Bazel rules for managing helm charts
Stars: ✭ 46 (+15%)
Mutual labels:  bazel, bazel-rules

Poetry Rules

Poetry is a package manager for Python. Bazel is a build system. Together they form a powerful, (mostly) hermetic build system for Python.

Installation

Prerequisites

  • Poetry 1.0 or higher
  • Bazel 1.0 or higher

The rules depend on Poetry's current lock file format. Versions 0.12.x or lower have a different format that is no longer supported.

Workspace Modifications

Add these lines to your project's WORKSPACE file:

# Poetry rules for managing Python dependencies

http_archive(
    name = "com_sonia_rules_poetry",
    sha256 = "8a7a6a5d2ef859ba4309929f3b4d61031f2a4bfed6f450f04ab09443246a4b5c",
    strip_prefix = "rules_poetry-ecd0d9c66b89403667304b11da3bd99764797a63",
    urls = ["https://github.com/soniaai/rules_poetry/archive/ecd0d9c66b89403667304b11da3bd99764797a63.tar.gz"],
)

load("@com_sonia_rules_poetry//rules_poetry:defs.bzl", "poetry_deps")

poetry_deps()

load("@com_sonia_rules_poetry//rules_poetry:poetry.bzl", "poetry")

poetry(
    name = "poetry",
    lockfile = "//:poetry.lock",
    pyproject = "//:pyproject.toml",
    # optional, if you would like to pull from pip instead of a Bazel cache
    tags = ["no-remote-cache"],
)

and use it to transitively pull in package dependencies using the generated dependency macro:

load("@poetry//:dependencies.bzl", "dependency")
load("@rules_python//python:defs.bzl", "py_library")

py_library(
    name = "some_package",
    srcs = ["example.py"],
    deps = [
        dependency("pytorch"),
        dependency("tensorflow"),
    ],
)

Usage

Usage is nearly identical to Poetry without Bazel. To add a dependency just run poetry add <package name>. To remove a package run poetry remove <package name>.

Caveats

  • May not work in network isolated sandboxes (untested)
  • Cache support is best-effort
  • Source wheels are built on demand and may not always produce deterministic results

Rules Comparison

As you're probably aware, there are a number of Python rules for Bazel due to rules_python being insufficient for many real world applications. While there is significant overlap between these rules, they're not identical in implementation nor in capability. A feature summary is listed below:

Feature rules_poetry rules_python
Backend poetry pip
Incremental yes no
Transitive yes no
Isolation yes no
Hash Validation yes depends
Deterministic mostly sometimes
Crosstool no no

  • Backend: which program is used for package management.
  • Incremental: adding, upgrading or removing packages only affects those that are modified. Unchanged packages are not reinstalled or downloaded.
  • Transitive: depending on one package will include all other packages it indirectly depends on.
  • Isolation: packages in the system or user site-packages should not be present in Python's path.
  • Hash Validation: wheel and source hashes are validated before installation
  • Deterministic: builds should be repeatable and cacheable
  • Crosstool: cross compilation (target != execution platform)

TODOs

  • Investiage using http_file instead of pip download to fetch dependencies
  • Expose the Poetry binary as a Bazel py_binary
  • Generate wrappers named python3 python3.7 etc
  • Add the wrappers to the PATH so the interpreter entrypoint is consistent
  • Unpack wheels directly into container layers to improve cacheability
  • Improve documentation
  • Write more tests

Contributions Welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].