Skip to content

Commit a34e090

Browse files
committed
Not workign attempt to use bazel as a monorepo
See also https://github.com/aspect-build/rules_py as a possibly alternative that works with importlib. Although testing against built wheels would still be ideal.
1 parent 29aad2e commit a34e090

File tree

10 files changed

+3289
-4
lines changed

10 files changed

+3289
-4
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,16 @@ scripts/semconv/semantic-conventions
6969

7070
# Benchmark result files
7171
*-benchmark.json
72+
# gitignore template for Bazel build system
73+
# website: https://bazel.build/
74+
75+
# Ignore all bazel-* symlinks. There is no full list since this can change
76+
# based on the name of the directory bazel is cloned into.
77+
/bazel-*
78+
79+
# Directories for the Bazel IntelliJ plugin containing the generated
80+
# IntelliJ project files and plugin configuration. Seperate directories are
81+
# for the IntelliJ, Android Studio and CLion versions of the plugin.
82+
/.ijwb/
83+
/.aswb/
84+
/.clwb/

BUILD

Whitespace-only changes.

MODULE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# See https://rules-python.readthedocs.io/en/latest/getting-started.html
2+
3+
bazel_dep(name = "rules_python", version = "1.0.0")
4+
5+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
6+
pip.parse(
7+
hub_name = "api_deps",
8+
python_version = "3.11",
9+
requirements_lock = "//opentelemetry-api:requirements.lock.txt",
10+
)
11+
use_repo(pip, "api_deps")

MODULE.bazel.lock

Lines changed: 3132 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opentelemetry-api/BUILD

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
load("@api_deps//:requirements.bzl", "requirement")
2+
load("@rules_python//python:packaging.bzl", "py_package", "py_wheel")
3+
load("@rules_python//python:py_binary.bzl", "py_binary")
4+
load("@rules_python//python:py_import.bzl", "py_import")
5+
load("@rules_python//python:py_library.bzl", "py_library")
6+
load("@rules_python//python:py_test.bzl", "py_test")
7+
load("//tools:pytest_test.bzl", "pytest_test")
8+
9+
py_library(
10+
name = "api",
11+
srcs = glob(["src/**/*.py"]),
12+
imports = ["src/"],
13+
deps = [
14+
requirement("Deprecated"),
15+
requirement("importlib-metadata"),
16+
],
17+
)
18+
19+
py_package(
20+
name = "opentelemetry_api_pkg",
21+
packages = ["opentelemetry"],
22+
deps = [":api"],
23+
)
24+
25+
py_wheel(
26+
name = "opentelemetry_api_wheel",
27+
# Package data. We're building "example_minimal_package-0.0.1-py3-none-any.whl"
28+
distribution = "opentelemetry-api",
29+
python_tag = "py3",
30+
strip_path_prefixes = ["opentelemetry-api/src"],
31+
version = "0.0.1",
32+
deps = [":opentelemetry_api_pkg"],
33+
)
34+
35+
# This doesn't work, can I use whl_library?
36+
py_import(
37+
name = "opentelemetry_api_wheel_lib",
38+
srcs = [":opentelemetry_api_wheel.dist"],
39+
deps = [],
40+
)
41+
42+
py_binary(
43+
name = "foo",
44+
srcs = ["foo.py"],
45+
deps = [":opentelemetry_api_wheel_lib"],
46+
)
47+
48+
pytest_test(
49+
name = "api_test",
50+
srcs = glob(["tests/**/*.py"]),
51+
deps = [":opentelemetry_api_wheel_lib"],
52+
)

opentelemetry-api/foo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import code
2+
3+
print("hello foo")
4+
5+
code.interact(local=locals())
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile test-requirements.txt -o requirements.lock.txt
3+
asgiref==3.7.2
4+
# via -r test-requirements.txt
5+
deprecated==1.2.14
6+
# via -r test-requirements.txt
7+
importlib-metadata==8.5.0
8+
# via -r test-requirements.txt
9+
iniconfig==2.0.0
10+
# via
11+
# -r test-requirements.txt
12+
# pytest
13+
packaging==24.0
14+
# via
15+
# -r test-requirements.txt
16+
# pytest
17+
pluggy==1.5.0
18+
# via
19+
# -r test-requirements.txt
20+
# pytest
21+
py-cpuinfo==9.0.0
22+
# via -r test-requirements.txt
23+
pytest==7.4.4
24+
# via -r test-requirements.txt
25+
tomli==2.0.1
26+
# via -r test-requirements.txt
27+
typing-extensions==4.10.0
28+
# via -r test-requirements.txt
29+
wrapt==1.16.0
30+
# via
31+
# -r test-requirements.txt
32+
# deprecated
33+
zipp==3.20.2
34+
# via
35+
# -r test-requirements.txt
36+
# importlib-metadata

opentelemetry-api/test-requirements.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,3 @@ tomli==2.0.1
1010
typing_extensions==4.10.0
1111
wrapt==1.16.0
1212
zipp==3.20.2
13-
-e opentelemetry-sdk
14-
-e opentelemetry-semantic-conventions
15-
-e tests/opentelemetry-test-utils
16-
-e opentelemetry-api

tools/BUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@api_deps//:requirements.bzl", "requirement")
2+
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
3+
4+
# This lets you run pytest
5+
py_console_script_binary(
6+
name = "pytest",
7+
pkg = requirement("pytest"),
8+
visibility = ["//visibility:public"],
9+
)
10+
11+
# exports_files([
12+
# "rules_python_entry_point_pytest.py",
13+
# ])

tools/pytest_test.bzl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
load("@api_deps//:requirements.bzl", "requirement")
2+
load("@rules_python//python:defs.bzl", "py_test")
3+
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
4+
5+
# This is cute, but it creates additinoal py_console_script_binary's genrule invocations for
6+
# each of the macro. It would be better to cache the script that gets generated.
7+
#
8+
# Run `bazel query --output=build //opentelemetry-api:api_test` and notice that there is a
9+
# one-off main script created for pytest
10+
# "//opentelemetry-api:rules_python_entry_point_pytest.py".
11+
def pytest_test(*, name, srcs = [], deps = [], main = None, **test_kwargs):
12+
"""TODO"""
13+
14+
if main != None:
15+
fail("Do not pass main to pytest_test, instead use py_test directly if you need main.")
16+
17+
test_srcs = srcs
18+
test_deps = deps
19+
20+
def py_test_wrapper(*, srcs, main, deps, **_):
21+
py_test(name = name, srcs = test_srcs + srcs, main = main, deps = test_deps + deps, **test_kwargs)
22+
23+
py_console_script_binary(
24+
name = "pytest",
25+
binary_rule = py_test_wrapper,
26+
pkg = requirement("pytest"),
27+
)

0 commit comments

Comments
 (0)