TODO: Build badges and such
The pyenv rules integrate pyenv with Bazel.
These rules can be used to hermetically download and compile versions of CPython supported by pyenv and pyenv-win for the supporting platform.
Add the following to your WORKSPACE
file:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "dpu_rules_pyenv",
sha256 = "8ca32471f14f4a831f58333c54bb4b0f6cc8cc00e73a93d9a878f5f1fb5019c0",
strip_prefix = "rules_pyenv-0.2.0",
urls = ["https://github.com/digital-plumbers-union/rules_pyenv/archive/v0.2.0.tar.gz"],
)
load("@dpu_rules_pyenv//pyenv:defs.bzl", "pyenv_install")
pyenv_install(
py2 = "<The version of python2 you want to use for your project>",
py3 = "<The version of python3 you want to use for your project>",
)
rules_pyenv
allows projects to select between hermetic versions of Python controlled by Bazel or non-hermetic versions
of Python managed by a pre-existing installation of pyenv or pyenv-win on the host machine.
Hermetic use of pyenv
is the default, simply declare your project's py_runtime_pair in your WORKSPACE
file.
pyenv_install(
py2 = "2.7.17",
py3 = "3.8.2",
)
Alternatively, your project can have rules_pyenv
use the host installed version of pyenv or pyenv-win and the
versions of Python it already manages. This can be useful if you find yourself needing to clean your workspace often
and are spending a lot of time waiting for pyenv
to compile the declared Python versions.
pyenv_install(
hermetic = False,
py2 = "2.7.17",
py3 = "3.8.2",
)
If you want to use rules_pyenv
on Windows you should enable symlinks
The interpreters are exposed as files, so you can refer to them in a repository rule.
You can refer to the python2
interpreter as @pyenv//:py2/python
and to the python3
interpreter as @pyenv//:py3/python
.
pyenv
is building Python from sources, so you need all things necessary to build Python. If you have any problems regarding this, you should see this page first.
- This thing needs tests
- This thing needs build automation
- You will probably find bugs. No, you're not crazy, it's just not working right; open an issue (PRs are welcome too)
- Since the native Bazel rules only support CPython your use of
pyenv
is restricted to CPython versions 2 and 3. If you want additional support for other Python impl
This work is dual-licensed as Apache-2.0 OR MIT
to achieve compatibility with GPLv2 and to be friendly for
both individuals and enterprise.
SPDX-License-Identifier: Apache-2.0 OR MIT