-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add example of local package with pip parse
Signed-off-by: Amaury Pouly <[email protected]>
- Loading branch information
Showing
7 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
load("@rules_python//python:defs.bzl", "py_test") | ||
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary") | ||
|
||
py_test( | ||
name = "test_hello", | ||
srcs = ["test_hello.py"], | ||
deps = [ | ||
"@pypi//hello", | ||
], | ||
) | ||
|
||
py_console_script_binary( | ||
name = "hello_parse", | ||
pkg = "@pypi//hello", | ||
script = "parse", | ||
) | ||
|
||
sh_test( | ||
name = "test_hello_script", | ||
srcs = ["test_hello_script.sh"], | ||
data = [":hello_parse"], | ||
env = { | ||
"HELLO_PARSE": "$(rootpaths :hello_parse)", | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module(name = "rules_python_pip_parse_local_package_example") | ||
|
||
bazel_dep(name = "rules_python", version = "0.0.0") | ||
local_path_override( | ||
module_name = "rules_python", | ||
path = "../..", | ||
) | ||
|
||
python = use_extension("@rules_python//python/extensions:python.bzl", "python") | ||
python.toolchain( | ||
# We can specify the exact version. | ||
python_version = "3.9.13", | ||
) | ||
|
||
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") | ||
pip.parse( | ||
hub_name = "pypi", | ||
# If we want to expand the PROJECT_ROOT variable in the requirement lock file, | ||
# we need to pass a label to the file defining the project root. | ||
project_root = "//:pyproject.toml", | ||
# We need to use the same version here as in the `python.toolchain` call. | ||
python_version = "3.9.13", | ||
requirements_lock = "//:requirements_lock.txt", | ||
) | ||
use_repo(pip, "pypi", "pypi_39_hello") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[project] | ||
name = "test" | ||
version = "0.0.0" | ||
dependencies = [ | ||
# Test | ||
"hello @ file://${PROJECT_ROOT}/hello", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This file was autogenerated by uv via the following command: | ||
# uv pip compile pyproject.toml -o requirements_lock.txt | ||
hello @ file://${PROJECT_ROOT}/hello | ||
# via test (pyproject.toml) | ||
hjson==3.1.0 | ||
# via hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import hello | ||
|
||
EXAMPLE_HJSON = """ | ||
{ | ||
# TL;DR | ||
human: Hjson | ||
machine: JSON | ||
} | ||
""" | ||
|
||
res = hello.parse(EXAMPLE_HJSON) | ||
assert res["human"] == "Hjson" | ||
assert res["machine"] == "JSON" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
TEST_HJSON=$(mktemp) | ||
|
||
echo "{ | ||
# TL;DR | ||
human: Hjson | ||
machine: JSON | ||
}" > $TEST_HJSON | ||
|
||
$HELLO_PARSE $TEST_HJSON |