Skip to content

Commit 7fe223e

Browse files
committed
Build, testes, gera requirents
0 parents  commit 7fe223e

14 files changed

Lines changed: 3552 additions & 0 deletions

.bazelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
common --enable_bzlmod
2+
common --lockfile_mode=update
3+
4+
coverage --java_runtime_version=remotejdk_11
5+
6+
test --test_output=errors --enable_runfiles
7+
8+
# Windows requires these for multi-python support:
9+
build --enable_runfiles
10+
common:bazel7.x --incompatible_python_disallow_native_rules

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[**]
4+
end_of_line = lf
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
8+
[**.{yml,yaml,md}]
9+
insert_final_newline = true
10+
indent_style = space
11+
indent_size = 2
12+
13+
[*.{bzl,bazel}]
14+
indent_style = space
15+
indent_size = 4
16+
insert_final_newline = true
17+
18+

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bazel-bazel-simple
2+
bazel-bin
3+
bazel-out
4+
bazel-testlogs

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

BUILD.bazel

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
load("@rules_python//python:py_binary.bzl", "py_binary")
2+
load("@rules_python//python:py_library.bzl", "py_library")
3+
load("@rules_python//python:py_test.bzl", "py_test")
4+
load("@pip//:requirements.bzl", "requirement")
5+
6+
load("@rules_uv//uv:pip.bzl", "pip_compile")
7+
8+
package(default_visibility = ["//visibility:public"])
9+
10+
py_binary(
11+
name = "main",
12+
srcs = ["main.py"],
13+
deps = [
14+
"//mylib:name",
15+
]
16+
)
17+
18+
pip_compile(
19+
name = "generate_requirements_txt",
20+
requirements_in = "pyproject.toml",
21+
requirements_txt = "requirements.txt",
22+
)

MODULE.bazel

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module(
2+
name = "simple-bazel",
3+
version = "0.1",
4+
compatibility_level = 1,
5+
)
6+
7+
bazel_dep(name = "rules_python", version = "1.3.0-rc1")
8+
9+
# SEE: https://github.com/theoremlp/rules_uv/
10+
bazel_dep(name = "rules_uv", version = "0.63.0")
11+
12+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
13+
python.toolchain(
14+
python_version = "3.13",
15+
)
16+
17+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
18+
pip.parse(
19+
hub_name = "pip",
20+
python_version = "3.13",
21+
requirements_lock = "//:requirements.txt",
22+
)
23+
24+
use_repo(pip, "pip")
25+
26+
27+
28+

MODULE.bazel.lock

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

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Projeto de Exemplo: Monorepo com Python e Bazel
2+
3+
Este é um projeto de exemplo que demonstra o uso de [Bazel](https://bazel.build) para gerenciar um monorepo com Python.
4+
5+
## Estrutura do Projeto
6+
7+
```
8+
.
9+
├── bazel-bazel-simple # Diretório gerado pelo Bazel
10+
├── bazel-bin # Saída dos builds
11+
├── bazel-out # Cache e artefatos do Bazel
12+
├── bazel-testlogs # Logs de testes
13+
├── mylib/ # Módulo Python de exemplo
14+
├── main.py # Script principal
15+
├── BUILD.bazel # Configuração do Bazel
16+
├── MODULE.bazel # Definição do módulo Bazel
17+
├── MODULE.bazel.lock # Arquivo de bloqueio do módulo
18+
├── pyproject.toml # Configuração do projeto Python
19+
├── requirements.txt # Dependências do projeto
20+
```
21+
22+
## Compilando
23+
24+
Para gerar o arquivo `requirements.txt` a partir do `pyproject.toml`, execute:
25+
26+
```sh
27+
bazel run //:generate_requirements_txt
28+
```
29+
30+
Para compilar o projeto, utilize o seguinte comando:
31+
32+
```sh
33+
bazel build //...
34+
```
35+
36+
Para rodar os testes do projeto, utilize:
37+
38+
```sh
39+
bazel test //...
40+
```
41+
42+
## Requisitos
43+
44+
- Python >= 3.13
45+
- Bazel (bzlmod)

main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from mylib.name import getName
2+
3+
4+
def main():
5+
"""Main function of the project"""
6+
7+
print("Hello from", getName())
8+
9+
10+
if __name__ == "__main__":
11+
main()

mylib/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@pip//:requirements.bzl", "requirement")
2+
load("@rules_python//python:py_library.bzl", "py_library")
3+
load("@rules_python//python:py_test.bzl", "py_test")
4+
5+
py_library(
6+
name = "name",
7+
srcs = ["name.py"],
8+
visibility = ["//:__pkg__"]
9+
)
10+
11+
py_test(
12+
name = "test",
13+
srcs = ["test.py"],
14+
deps = [":name"],
15+
)

0 commit comments

Comments
 (0)