-
-
Notifications
You must be signed in to change notification settings - Fork 593
docs: rules_python bzlmod GA and 1.0 prep #2296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6fea69a
746492f
29858d8
665e434
7a445fa
b082b76
188c476
d16bb57
a517ca8
e9f01d6
bff95ed
60b81c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Getting started | ||
|
||
This doc is a simplified guide to help get started started quickly. It provides | ||
a simplified introduction to having a working Python program for both bzlmod | ||
This doc is a simplified guide to help get started quickly. It provides | ||
a simplified introduction to having a working Python program for both `bzlmod` | ||
and the older way of using `WORKSPACE`. | ||
|
||
It assumes you have a `requirements.txt` file with your PyPI dependencies. | ||
|
@@ -23,11 +23,11 @@ bazel_dep(name = "rules_python", version = "0.0.0") | |
|
||
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") | ||
pip.parse( | ||
hub_name = "my_deps", | ||
hub_name = "pypi", | ||
python_version = "3.11", | ||
requirements_lock = "//:requirements.txt", | ||
) | ||
use_repo(pip, "my_deps") | ||
use_repo(pip, "pypi") | ||
``` | ||
|
||
## Using a WORKSPACE file | ||
|
@@ -38,19 +38,14 @@ using Bzlmod. Here is a simplified setup to download the prebuilt runtimes. | |
```starlark | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
|
||
# Update the SHA and VERSION to the lastest version available here: | ||
# https://github.com/bazelbuild/rules_python/releases. | ||
|
||
SHA="84aec9e21cc56fbc7f1335035a71c850d1b9b5cc6ff497306f84cced9a769841" | ||
|
||
VERSION="0.23.1" | ||
# Update the snippet based on the latest release below | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Are you sure about this change? I'm +1 on increasing to a newer version. Doesn't the extracted variables make it easier to bump versions in future? Or are you thinking there aren't major benefits to the indirection? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am thinking that one needs to copy the sha and version separately instead of just replacing the whole block of What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right. Yes. If we could prepare a full copy-paste snippet somewhere that is kept up to date automatically, that would be cool. Im fine with your change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the snippet is in the |
||
# https://github.com/bazelbuild/rules_python/releases | ||
|
||
http_archive( | ||
name = "rules_python", | ||
sha256 = SHA, | ||
strip_prefix = "rules_python-{}".format(VERSION), | ||
url = "https://github.com/bazelbuild/rules_python/releases/download/{}/rules_python-{}.tar.gz".format(VERSION,VERSION), | ||
sha256 = "ca77768989a7f311186a29747e3e95c936a41dffac779aff6b443db22290d913", | ||
strip_prefix = "rules_python-0.36.0", | ||
url = "https://github.com/bazelbuild/rules_python/releases/download/0.36.0/rules_python-0.36.0.tar.gz", | ||
) | ||
|
||
load("@rules_python//python:repositories.bzl", "py_repositories") | ||
|
@@ -66,14 +61,12 @@ python_register_toolchains( | |
python_version = "3.11", | ||
) | ||
|
||
load("@python_3_11//:defs.bzl", "interpreter") | ||
|
||
load("@rules_python//python:pip.bzl", "pip_parse") | ||
|
||
pip_parse( | ||
... | ||
python_interpreter_target = interpreter, | ||
... | ||
name = "pypi", | ||
python_interpreter_target = "@python_3_11_host//:python", | ||
requirements_lock = "//:requirements.txt", | ||
) | ||
``` | ||
|
||
|
@@ -89,8 +82,8 @@ py_binary( | |
name = "main", | ||
srcs = ["main.py"], | ||
deps = [ | ||
"@my_deps//foo", | ||
"@my_deps//bar", | ||
"@pypi//foo", | ||
"@pypi//bar", | ||
] | ||
) | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.