Giter Club home page Giter Club logo

rules_py's Introduction

Aspect's Bazel rules for python

aspect_rules_py is a layer on top of rules_python, the standard Python ruleset hosted at https://github.com/bazelbuild/rules_python. It is currently in pre-release, but we are committed to more development towards a 1.0 stable release.

Some parts of rules_python are reused:

  • Same toolchain for fetching a hermetic python interpreter.
  • pip_parse rule for translating a requirements-lock.txt file into Bazel repository fetching rules and installing those packages into external repositories.
  • The Gazelle extension for generating BUILD.bazel files works the same.

However, this ruleset introduces a new implementation of py_library, py_binary, and py_test. The starlark implementations allow us to innovate, while the existing ones are embedded in Bazel's Java sources in the bazelbuild/bazel repo and therefore very difficult to get changes made.

We understand that there is also an effort at Google to "starlarkify" the Python rules, but there is no committed roadmap or dates. Given the history of other projects coming from Google, we've chosen not to wait.

Our philosophy is to behave more like idiomatic python ecosystem tools. Having a starlark implementation allows us to do things like attach Bazel transitions, mypy typechecking actions, etc.

Things that are improved in rules_py:

  • We don't mess with the Python sys.path/$PYTHONPATH. Instead we use the standard site-packages folder layout produced by pip_install. This avoids problems like package naming collisions with built-ins (e.g. collections) or where argparse comes from a transitive dependency instead. (Maybe helps with diamond dependencies too).
  • We run python in isolated mode so we don't accidentally break out of Bazel's action sandbox, fixing:
  • We create a python-idiomatic virtualenv to run actions, which means better compatibility with userland implementations of importlib.
  • Thanks to the virtualenv, you can open the project in an editor like PyCharm and have working auto-complete, jump-to-definition, etc.
  • The launcher uses the Bash toolchain rather than Python, so we have no dependency on a system interpreter - fixes MacOS no longer shipping with python.

Improvements planned:

  • Build wheels in actions, so it's possible to have native packages built for the target platform, e.g. for a rules_docker py3_image.
  • Support --only_binary=:all: by always building wheels from source using a hermetic Bazel cc toolchain.
  • dep on wheels directly, rather than on a py_library that wraps it. Then we don't have to append to the .pth file to locate them.

Need help? This ruleset has support provided by https://aspect.dev.

Installation

From the release you wish to use: https://github.com/aspect-build/rules_py/releases copy the WORKSPACE snippet into your WORKSPACE file.

rules_py's People

Contributors

renovate[bot] avatar mattem avatar alexeagle avatar gregmagolan avatar f0rmiga avatar mvukov avatar dzbarsky avatar tellett avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.