Skip to content

Conversation

@KetanReddy
Copy link
Member

@KetanReddy KetanReddy commented Sep 26, 2025

Python Pipeline

TLDR: An initial offering of a Python pipeline similar to our offerings for other languages to allow for easy integration into a Player Plugin.

Basics

This pipeline serves as a convenience wrapper around a lot of the rules_python rules that allows for packages to be created that are more similar to the layout of our other language packages while still being compliant with the Python ecosystem.

Setup/Requirements

MODULE.bazel

You'll need to add aspect_bazel_lib, rules_python and platforms to your bazel deps and configure the Python toolchain for rules_python (steps here) and dependencies (steps here). For most simple use cases the basic requirements.txt approach will work fine.

Layout

Source code should be placed in a src folder that is peer to the BUILD file. Underneath it, is where a __init__.py and your source code should live. Additionally, a __tests__ folder should be created to contain the tests for the module. E.g

  • library
    • BUILD
    • src
      • __tests__
        • __init__.py
        • test_source.py
      • __init__.py
      • source.py

Build

Python files don't have a traditional build step but there is orchestration to create the standard python package layout and a local library target that can be referenced. Runtime dependencies should be supplied in the deps attribute. The name supplied to the pipeline will be what should be used to reference the library locally as well as what the library will be published as.

Tests

Out of the box this pipelines offers unit and lint tests. Tests are orchestrated through pytest via a wrapper included in the rules.

Unit

Dependencies that are only required for unit tests can be provided via the test_deps argument. Tests are orchestrated wholly, as in there is a single test target for all tests in the __tests__ folder. Non test files and or non Python helper files (e.g static JSON file) can be placed in a subfolder called __helpers__ that will be included in the test environment.

Lint

Lint currently runs only across source code. pytest lint plugins can be supplied via the lint_deps argument to customize the linting rules. Customization of those lint rules can be achieved by customizing the .pylintrc file.

Packaging

A virtual requirement.txt file will be created via the specified runtime dependencies. The version/ranges in the base requirements.txt file will be used for external packages and the exact version specified in the VERSION file will be used for intra-repository dependencies.

The pipeline will produce a .whl file with name, version (provided via the VERSION file), and any additional kwargs supplied to the pipeline that match the args in the underlying py_wheel rule (docs here).

The target to run the publish will be the wheel target on the pipeline.

Release Notes

Add py_pipeline macro to offer a simple, slightly opinionated, pipeline for building/testing Python libraries.

@KetanReddy KetanReddy added the minor Increment the minor version when merged label Sep 26, 2025
@KetanReddy KetanReddy marked this pull request as draft September 26, 2025 20:53
@KetanReddy KetanReddy force-pushed the feature/python-rules branch from 505d8ac to cbd5c35 Compare October 9, 2025 19:46
@KetanReddy KetanReddy marked this pull request as ready for review October 9, 2025 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor Increment the minor version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants