diff --git a/README.md b/README.md index 0e4c72b..662933c 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,18 @@ From the release you wish to use: copy the WORKSPACE snippet into your `WORKSPACE` file or the `bazel_dep` if you use bzlmod. +################################################# + +# loadup the requirements for pytest +load("@rules_python_pytest//python_pytest:repositories.bzl", "setup_pytest_requirements") +# this requires you to pass in your python interpreter +setup_pytest_requirements(interpreter = interpreter) +load("@pytest_requirements//:requirements.bzl", "install_deps") +install_deps() + +################################################# + + ## Usage ```py diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 53b52af..85c64c5 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -1 +1,2 @@ # Marker that this is the root of a Bazel workspace. +workspace("rules_python_pytest") diff --git a/e2e/smoke/requirements.txt b/e2e/smoke/requirements.txt index 1594aa8..64b29b3 100644 --- a/e2e/smoke/requirements.txt +++ b/e2e/smoke/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.9 +# This file is autogenerated by pip-compile with Python 3.10 # by the following command: # # pip-compile --allow-unsafe --generate-hashes --no-emit-index-url requirements.in diff --git a/python_pytest/defs.bzl b/python_pytest/defs.bzl index cc6cd5a..defa29f 100644 --- a/python_pytest/defs.bzl +++ b/python_pytest/defs.bzl @@ -1,7 +1,7 @@ """Public API""" load("@rules_python//python:defs.bzl", "py_test") -# load("@py_deps//:requirements.bzl", "requirement") +load("@pytest_requirements//:requirements.bzl", "requirement") def py_pytest_test(name, srcs, deps = [], args = [], **kwargs): """Use pytest to run tests, using a wrapper script to interface with Bazel. @@ -12,8 +12,6 @@ def py_pytest_test(name, srcs, deps = [], args = [], **kwargs): size = "small", srcs = ["test.py"], deps = [ - # TODO Add this for the user - requirement("pytest"), ], ) ``` @@ -31,10 +29,9 @@ def py_pytest_test(name, srcs, deps = [], args = [], **kwargs): ] + args + ["$(location :%s)" % x for x in srcs], # python_version = "PY3", # srcs_version = "PY3", - # TODO It'd be nice to implicitly include pytest, but I don't know how to know the requirements repo nme - # deps = deps + [ - # requirement("pytest"), - # ], - deps = deps, + deps = deps + [ + requirement("pytest"), + requirement("pluggy"), + ], **kwargs ) diff --git a/python_pytest/repositories.bzl b/python_pytest/repositories.bzl index d88d8da..8225855 100644 --- a/python_pytest/repositories.bzl +++ b/python_pytest/repositories.bzl @@ -6,6 +6,7 @@ See https://docs.bazel.build/versions/main/skylark/deploying.html#dependencies load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("@rules_python//python:pip.bzl", "pip_parse") def http_archive(name, **kwargs): maybe(_http_archive, name = name, **kwargs) @@ -34,3 +35,11 @@ def rules_python_pytest_dependencies(): strip_prefix = "rules_python-0.6.0", url = "https://github.com/bazelbuild/rules_python/archive/0.6.0.tar.gz", ) + +def setup_pytest_requirements(interpreter): + pip_parse( + name = "pytest_requirements", + python_interpreter_target = interpreter, + quiet = False, + requirements_lock = "@rules_python_pytest//:e2e/smoke/requirements.txt", + )