Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements")
load("@rules_python//python:defs.bzl", "py_runtime", "py_runtime_pair")
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@pypi//:requirements.bzl", "all_whl_requirements")
load("@rules_python//gazelle:def.bzl", "GAZELLE_PYTHON_RUNTIME_DEPS")
load("@rules_python//gazelle/manifest:defs.bzl", "gazelle_python_manifest")
load("@rules_python//gazelle/modules_mapping:def.bzl", "modules_mapping")
load("@rules_python//python:defs.bzl", "py_runtime", "py_runtime_pair")
load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements")

# gazelle:exclude internal_python_deps.bzl
# gazelle:exclude internal_deps.bzl
# gazelle:exclude py/tests/
# gazelle:exclude examples/django

gazelle_python_manifest(
name = "gazelle_python_manifest",
modules_mapping = ":modules_map",
pip_repository_incremental = True,
pip_repository_name = "pypi",
requirements = "requirements.txt",
)

gazelle_binary(
name = "gazelle_bin",
languages = ["@bazel_skylib//gazelle/bzl"],
languages = [
"@bazel_skylib//gazelle/bzl",
"@rules_python//gazelle",
],
)

gazelle(
name = "gazelle",
gazelle = "gazelle_bin",
data = GAZELLE_PYTHON_RUNTIME_DEPS,
gazelle = ":gazelle_bin",
)

compile_pip_requirements(
Expand All @@ -23,6 +40,11 @@ compile_pip_requirements(
requirements_txt = "requirements.txt",
)

modules_mapping(
name = "modules_map",
wheels = all_whl_requirements,
)

py_runtime(
name = "container_py3_runtime",
interpreter_path = "/usr/bin/python",
Expand Down
6 changes: 5 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.17.2")
go_register_toolchains(version = "1.19.3")

gazelle_dependencies()

load("@rules_python//gazelle:deps.bzl", _py_gazelle_deps = "gazelle_deps")

_py_gazelle_deps()

############################################
# rules_docker dependencies for containers
load(
Expand Down
20 changes: 20 additions & 0 deletions docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions examples/pytest/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@rules_python//python:defs.bzl", "py_test")
load("@//py:defs.bzl", "py_pytest_main")

py_pytest_main(name = "__test__")

py_test(
name = "pytest_test",
srcs = [
"foo_test.py",
":__test__",
],
imports = ["../.."],
main = ":__test__.py",
deps = [
":__test__",
"@pypi_pytest//:pkg",
],
)
19 changes: 19 additions & 0 deletions examples/pytest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# A pytest entrypoint for Bazel's py_test

With Bazel `py_test`, it requires a single file as the entry point. This repository contains a
template that gets rendered for a particular package and will discover tests automatically in the
same way the `pytest` command-line does.

## How to use

After importing this repository into your `WORKSPACE`, add to your Bazel packages containing
`_test.py` files the following:

```python
load("@aspect_rules_py//py:defs.bzl", "py_pytest_main")

py_pytest_main(name = "__test__")
```

When using this repository together with the Gazelle extension for Python from rules_python, Gazelle
will detect the `__test__` target and produce a `py_test` compatible with it.
5 changes: 5 additions & 0 deletions examples/pytest/foo_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pytest


def test_add():
assert 1 + 1 == 2, "Expected 1 + 1 to equal 2"
Loading