Code Monkey home page Code Monkey logo

bazel-python-src-tests-example's Introduction

Bazel for Python that uses src and tests dirs

An example of how to configure bazel (via the new bzlmod MODULE.bazel) for Python projects that use a src dir and have tests outside of the package in a separate tests dir.

Key points that make this example interesting:

  • All python code is in a src dir, as recommended by the Python Packaging User Guide.
  • Tests are outside of the package and thus not shipped with distributions.
  • The package must be installed before tests will work.
    • Typically this is done via editable installs pip install -e ..

Usage

  1. Clone the repo.
  2. Make a venv and activate it.
  3. Install the package pip install -e .[dev]
  4. Make sure non-bazel basic unit tests work python -m unittest.
  5. And make sure bazel unit tests work bazel test //....
  6. And that bazel run works: bazel run //src/mypackage:mypackage_bin.

If I've set up this example correctlly, everything should pass.

Buildifier

Buildifier is a linter and autoformatter for Starlark, the language used by Bazel.

Run with one or both of:

bazel run //:buildifier.fix
bazel run //:buildifier.check

Gazelle

Gazelle is a tool for autogenerating BUILD(.bazel) files from source code.

Run by calling all these, in order:

# If any python dependencies change:
bazel run //:requirements.update
bazel run //:gazelle_python_manifest.update
# Run gazelle and generate BUILD files and targets:
bazel run //:gazelle

bazel-python-src-tests-example's People

Contributors

dougthor42 avatar

Stargazers

 avatar

Watchers

 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.