Skip to content

Commit

Permalink
Enable gazelle Python and convert tests to Bazel.
Browse files Browse the repository at this point in the history
  • Loading branch information
sputt committed Dec 28, 2024
1 parent 05518d6 commit 68cfa3e
Show file tree
Hide file tree
Showing 78 changed files with 1,131 additions and 175 deletions.
4 changes: 4 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ private/examples
private/tests/override_module_repos/overrider
private/tests/override_module_repos/overridee
.ijwb
build
dist
venv
.wheeldir
36 changes: 4 additions & 32 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@ jobs:
pip install -r 3rdparty/requirements.txt --user
- name: Run mypy
run: |
python -m mypy req_compile
python -m mypy req_compile private
env:
MYPYPATH: req-compile/stubs
- name: Run pylint
run: |
python -m pylint req_compile tests
- name: Test with pytest
run: |
python -m pytest -v --ignore=private
python -m pylint req_compile tests private
formatting:
runs-on: ubuntu-latest
Expand All @@ -58,10 +55,10 @@ jobs:
pip install -r 3rdparty/requirements.txt --user
- name: Run black
run: |
black --check --diff req_compile
black --check --diff req_compile private
- name: Run isort
run: |
isort --check-only req_compile
isort --check-only req_compile private
bazel-bzlmod:
strategy:
Expand Down Expand Up @@ -107,28 +104,3 @@ jobs:
run: |
bazel test //...
working-directory: private/tests/override_module_repos/overrider

bazel_lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v2
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r 3rdparty/requirements.txt --user
pip install -e .
- name: Run isort
run: |
isort --check-only private
- name: Run black
run: |
black --check --diff private
- name: Run pylint
run: |
python -m pylint private
- name: Run buildifier
run: bazel run //:buildifier.check
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.whl
*.tar.gz
*.pyc
__pycache__/
.pytest_cache
/venv*
/.venv*
Expand All @@ -13,8 +14,9 @@ dist
/bazel-*
user.bazelrc
/.github/ci.bazelrc
/private/examples/dep_with_dup_extras/bazel-*
/private/examples/multiplatform_py_test/bazel-*

# Ignore the module lock for now, since the sdist repo rules incorrectly record the calling
# platform's Python intepreter as the _only_ interprete in the lock.
# platform's Python intepreter as the _only_ interpreter in the lock.
MODULE.bazel.lock
2 changes: 2 additions & 0 deletions 3rdparty/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
load("//:defs.bzl", "py_reqs_compiler", "py_reqs_solution_test")

exports_files(["requirements.linux.txt"])

filegroup(
name = "requirements",
srcs = ["bazel-requirements.in"],
Expand Down
38 changes: 32 additions & 6 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@rules_python//python:defs.bzl", "py_library")

# gazelle:python_manifest_file_name private/tools/gazelle_python.yaml
# gazelle:resolve py python.runfiles @rules_python//python/runfiles
# gazelle:python_label_convention :$distribution_name$
# gazelle:python_generation_mode file

exports_files([
"MODULE.bazel",
"requirements.in",
"test-requirements.in",
"version.bzl",
"defs.bzl",
"pyproject.toml",
])

alias(
name = "buildifier",
actual = "//private/tools:buildifier",
)

alias(
name = "buildifier.check",
actual = "//private/tools:buildifier.check",
test_suite(
name = "buildifier_test",
tests = ["//private/tools:buildifier_test"],
)

alias(
Expand All @@ -24,12 +31,32 @@ alias(
tags = ["manual"],
)

py_library(
name = "setup",
testonly = True,
srcs = [
"setup.py",
],
data = [
"CHANGELOG.rst",
"LICENSE.txt",
"README.rst",
"requirements.in",
"version.bzl",
],
visibility = ["//tests:__subpackages__"],
deps = [
"//req_compile:req_compile_bin",
],
)

bzl_library(
name = "defs",
srcs = ["defs.bzl"],
visibility = ["//visibility:public"],
deps = [
"//private:annotation",
"//private:compiler_rule",
"//private:reqs_repo",
"//private:whl_repo",
],
Expand All @@ -46,13 +73,12 @@ bzl_library(
],
)

# keep
bzl_library(
name = "repositories_transitive",
srcs = ["repositories_transitive.bzl"],
visibility = ["//visibility:public"],
deps = [
"@rules_python//python:repositories_bzl",
],
deps = [],
)

bzl_library(
Expand Down
5 changes: 2 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ module(

bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_python", version = "1.0.0")

bazel_dep(name = "buildozer", version = "7.1.2", dev_dependency = True)

bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_cc", version = "0.0.16")

Expand Down Expand Up @@ -220,3 +217,5 @@ bazel_dep(name = "gazelle", version = "0.40.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.7.2", dev_dependency = True)
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.7.1", dev_dependency = True)
bazel_dep(name = "protobuf", version = "29.2", dev_dependency = True)
bazel_dep(name = "rules_python_gazelle_plugin", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "buildozer", version = "7.1.2", dev_dependency = True)
3 changes: 3 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ README for Req-Compile Python Requirements Compiler
:alt: PyPI package version
:target: https://pypi.python.org/pypi/req-compile

.. image:: https://github.com/periareon/req-compile/actions/workflows/build.yml/badge.svg
.. image:: https://github.com/periareon/req-compile/actions/workflows/build.yaml/badge.svg
:alt: Github build status
:target: https://github.com/periareon/req-compile

Expand All @@ -29,7 +29,9 @@ to compile a requirements solution and install third-party distributions from th
project differs from ``rules_python`` in that the URLs for the distributions are written to the
solution, enabling deterministic and repo-cacheable downloads and installs of third-party dependencies.

To get started with bzlmod on Bazel 7::
To get started with bzlmod on Bazel 7:

.. code-block:: python
# Find {version} on the req-compile GitHub releases page.
bazel_dep(name = "rules_req_compile", version = "{version}")
Expand All @@ -45,7 +47,9 @@ To get started with bzlmod on Bazel 7::
)
use_repo(requirements, "my_pip_deps")
Using WORKSPACE.bazel::
Using WORKSPACE.bazel:

.. code-block:: python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
Expand Down Expand Up @@ -322,4 +326,3 @@ together and ensure that their requirements will all install into the same envir

> req-candidates --paths-only | req-compile --extra test --solution compiled-requirements.txt --wheel-dir .wheeldir > compiled-requirements.txt
.. all reqs and all test reqs compiled together...

2 changes: 1 addition & 1 deletion defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ load(
_py_package_annotation_target = "py_package_annotation_target",
)
load(
"//private:compiler.bzl",
"//private:compiler_rule.bzl",
_py_reqs_compiler = "py_reqs_compiler",
_py_reqs_solution_test = "py_reqs_solution_test",
)
Expand Down
2 changes: 1 addition & 1 deletion docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stardoc(
tags = ["manual"],
deps = [
"//:defs",
"//private:compiler",
"//private:compiler_rule",
"@protobuf//bazel:cc_proto_library_bzl",
"@rules_cc//cc:bzl_srcs",
"@rules_cc//cc/common",
Expand Down
20 changes: 14 additions & 6 deletions private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ py_binary(
)

py_binary(
name = "compiler_bin",
name = "compiler",
srcs = ["compiler.py"],
main = "compiler.py",
visibility = ["//visibility:public"],
deps = [
"//req_compile",
"//req_compile:cmdline",
"//req_compile:compile",
"//req_compile:containers",
"//req_compile:dists",
"//req_compile:errors",
"//req_compile/repos:__init__",
"//req_compile/repos:repository",
"@rules_python//python/runfiles",
],
)
Expand All @@ -31,7 +37,7 @@ py_binary(
srcs = ["solution_tester.py"],
visibility = ["//visibility:public"],
deps = [
":compiler_bin",
":compiler",
"@rules_python//python/runfiles",
],
)
Expand All @@ -40,7 +46,9 @@ bzl_library(
name = "annotation",
srcs = ["annotation.bzl"],
visibility = ["//:__subpackages__"],
deps = ["@rules_cc//cc:bzl_srcs"],
deps = [
"@rules_cc//cc:bzl_srcs", # keep: this is the correct import for our version of rules_cc
],
)

bzl_library(
Expand Down Expand Up @@ -78,8 +86,8 @@ bzl_library(
)

bzl_library(
name = "compiler",
srcs = ["compiler.bzl"],
name = "compiler_rule",
srcs = ["compiler_rule.bzl"],
visibility = ["//:__subpackages__"],
)

Expand Down
2 changes: 1 addition & 1 deletion private/compiler.bzl → private/compiler_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ bazel run //:requirements.update -- --upgrade
"_compiler": attr.label(
cfg = "exec",
executable = True,
default = Label("//private:compiler_bin"),
default = Label("//private:compiler"),
),
"_copier": attr.label(
cfg = "exec",
Expand Down
1 change: 1 addition & 0 deletions private/reqs_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def parse_constraint(data, lockfile, wheel_dirs):
for entry in data[2:-1]:
text = entry.replace("# via", "#")
pkg, _, _ = text.strip(" #").partition(" ")

# TODO: Support extras.
# Split off the extra.
pkg, _, _ = pkg.partition("[")
Expand Down
4 changes: 3 additions & 1 deletion private/tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

# keep
bzl_library(
name = "test_repositories_1",
srcs = ["test_repositories_1.bzl"],
Expand All @@ -10,6 +11,7 @@ bzl_library(
],
)

# keep
bzl_library(
name = "test_repositories_2",
srcs = ["test_repositories_2.bzl"],
Expand All @@ -20,9 +22,9 @@ bzl_library(
],
)

# keep
bzl_library(
name = "test_repositories_3",
srcs = ["test_repositories_3.bzl"],
visibility = ["//:__subpackages__"],
deps = [],
)
Loading

0 comments on commit 68cfa3e

Please sign in to comment.