Skip to content

Commit

Permalink
Restore workspace.bazel and build
Browse files Browse the repository at this point in the history
  • Loading branch information
sputt committed Sep 3, 2024
1 parent 05fc3e9 commit ce76a44
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ jobs:
- name: Run Tests
run: |
bazel test //...
- name: Run Tests (WORKSPACE.bazel)
run: |
bazel test //... --noenable_bzlmod
- name: Perform compilation
run: |
bazel run //3rdparty:requirements_compiler "--" --upgrade
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dist
/bazel-*
user.bazelrc
/.github/ci.bazelrc
/private/examples/multiplatform_py_test/bazel-*
33 changes: 32 additions & 1 deletion WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# Use MODULE.bazel instead.
workspace(name = "rules_req_compile")

load("//:repositories.bzl", "req_compile_dependencies")

req_compile_dependencies()

load("//:repositories_transitive.bzl", "req_compile_transitive_dependencies")

req_compile_transitive_dependencies()

load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
name = "python311",
python_version = "3.11",
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("//private/tests:test_repositories_1.bzl", "test_dependencies_1")

test_dependencies_1()

load("//private/tests:test_repositories_2.bzl", "test_dependencies_2")

test_dependencies_2()

load("//private/tests:test_repositories_3.bzl", "test_dependencies_3")

test_dependencies_3()
78 changes: 78 additions & 0 deletions private/tests/annotations/annotations_test_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Test dependencies for the annotations integration test"""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load(
"//:defs.bzl",
"py_requirements_repository",
package_annotation = "py_package_annotation",
)

_NUMPY_LIBRARY_TARGET = """\
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_req_compile//:defs.bzl", "py_package_annotation_target")
_INCLUDE_DIR = "site-packages/numpy/core/include"
cc_library(
name = "headers",
hdrs = glob(["{}/**/*.h".format(_INCLUDE_DIR)]),
includes = [_INCLUDE_DIR],
)
py_package_annotation_target(
name = "pkg.headers",
target = ":headers",
)
"""

def req_compile_test_annotations_deps():
maybe(
py_requirements_repository,
name = "req_compile_test_annotations",
requirements_locks = {
Label("//private/tests/annotations:requirements.linux.txt"): "@platforms//os:linux",
Label("//private/tests/annotations:requirements.macos.txt"): "@platforms//os:macos",
Label("//private/tests/annotations:requirements.windows.txt"): "@platforms//os:windows",
},
annotations = {
"numpy": package_annotation(
additive_build_file_content = _NUMPY_LIBRARY_TARGET,
data = [":pkg.headers"],
copy_srcs = {
"site-packages/numpy/conftest.py": "site-packages/numpy/conftest.copy.py",
},
copy_files = {
"site-packages/numpy-1.26.4.dist-info/entry_points.txt": "site-packages/numpy-1.26.4.dist-info/entry_points.copy.txt",
},
copy_executables = {
"site-packages/numpy/testing/setup.py": "site-packages/numpy/testing/setup.copy.py",
},
patches = [
Label("//private/tests/annotations:numpy.patch"),
],
deps = [
# Show that label dependencies can be added.
Label("@rules_python//python/runfiles"),
],
),
# Sphinx is known to have a circular dependency. The annotations here solve for that.
"sphinxcontrib-applehelp": package_annotation(
deps = ["-sphinx"],
),
"sphinxcontrib-devhelp": package_annotation(
deps = ["-sphinx"],
),
"sphinxcontrib-htmlhelp": package_annotation(
deps = ["-sphinx"],
),
"sphinxcontrib-jsmath": package_annotation(
deps_excludes = ["sphinx"],
),
"sphinxcontrib-qthelp": package_annotation(
deps_excludes = ["sphinx"],
),
"sphinxcontrib-serializinghtml": package_annotation(
deps_excludes = ["sphinx"],
),
},
)
21 changes: 21 additions & 0 deletions private/tests/pip_parse_compat/pip_parse_compat_test_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Test dependencies for `pip_parse` compatibility tests"""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//:defs.bzl", "py_requirements_repository")

def pip_parse_compat_test_deps():
maybe(
py_requirements_repository,
name = "req_compile_test_pip_parse_compat_single_plat",
requirements_lock = Label("//private/tests/pip_parse_compat:requirements.txt"),
)

maybe(
py_requirements_repository,
name = "req_compile_test_pip_parse_compat_multi_plat",
requirements_locks = {
Label("//private/tests/pip_parse_compat:requirements.linux.txt"): "@platforms//os:linux",
Label("//private/tests/pip_parse_compat:requirements.macos.txt"): "@platforms//os:macos",
Label("//private/tests/pip_parse_compat:requirements.windows.txt"): "@platforms//os:windows",
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Test dependencies for `pip_parse` compatibility tests"""

load(
"@req_compile_test_pip_parse_compat_multi_plat//:requirements.bzl",
pip_parse_compat_multi_plat_repositories = "install_deps",
)
load(
"@req_compile_test_pip_parse_compat_single_plat//:requirements.bzl",
pip_parse_compat_single_plat_repositories = "install_deps",
)

def pip_parse_compat_test_deps_install():
pip_parse_compat_multi_plat_repositories()
pip_parse_compat_single_plat_repositories()
56 changes: 56 additions & 0 deletions private/tests/test_repositories_1.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""req-compile Bazel integration test dependencies"""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@python311//:defs.bzl", "interpreter")
load("//:defs.bzl", "py_requirements_repository")
load("//private/tests/annotations:annotations_test_deps.bzl", "req_compile_test_annotations_deps")
load("//private/tests/find_links:find_links_test_repo.bzl", "find_links_test_repository")
load("//private/tests/pip_parse_compat:pip_parse_compat_test_deps.bzl", "pip_parse_compat_test_deps")

def test_dependencies_1():
"""req-compile Bazel integration test dependencies"""

maybe(
py_requirements_repository,
name = "req_compile_test_sdist",
# Required to compile sdists
interpreter = interpreter,
requirements_lock = Label("//private/tests/sdist:requirements.txt"),
)

maybe(
py_requirements_repository,
name = "req_compile_test_simple",
requirements_lock = Label("//private/tests/simple:requirements.txt"),
)

maybe(
py_requirements_repository,
name = "req_compile_test_platlib",
requirements_locks = {
Label("//private/tests/platlib:requirements.linux.txt"): "@platforms//os:linux",
Label("//private/tests/platlib:requirements.macos.txt"): "@platforms//os:macos",
Label("//private/tests/platlib:requirements.windows.txt"): "@platforms//os:windows",
},
)

maybe(
py_requirements_repository,
name = "req_compile_test_transitive_ins",
requirements_lock = Label("//private/tests/transitive_ins:requirements.txt"),
)

maybe(
find_links_test_repository,
name = "req_compile_find_links_test",
pyspark_wheel_data = Label("@req_compile_test_sdist__pyspark__sdist//:whl.json"),
build_file = Label("//private/tests/find_links:BUILD.find_links.bazel"),
# Needs to match `--find-links` in `//private/tests/find_links:requirements.in`
wheeldir = "wheeldir",
requirements_in = Label("//private/tests/find_links:requirements.in"),
requirements_txt = Label("//private/tests/find_links:requirements.txt"),
)

pip_parse_compat_test_deps()

req_compile_test_annotations_deps()
29 changes: 29 additions & 0 deletions private/tests/test_repositories_2.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""req-compile Bazel integration test transitive dependencies"""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@req_compile_test_annotations//:defs.bzl", annotations_repositories = "repositories")
load("@req_compile_test_platlib//:defs.bzl", platlib_repositories = "repositories")
load("@req_compile_test_sdist//:defs.bzl", sdist_repositories = "repositories")
load("@req_compile_test_simple//:defs.bzl", simple_repositories = "repositories")
load("@req_compile_test_transitive_ins//:defs.bzl", transitive_ins_repositories = "repositories")
load("//:defs.bzl", "py_requirements_repository")
load(
"//private/tests/pip_parse_compat:pip_parse_compat_test_deps_install.bzl",
"pip_parse_compat_test_deps_install",
)

def test_dependencies_2():
"""req-compile Bazel integration test transitive dependencies"""

annotations_repositories()
pip_parse_compat_test_deps_install()
platlib_repositories()
sdist_repositories()
simple_repositories()
transitive_ins_repositories()

maybe(
py_requirements_repository,
name = "req_compile_test_find_links",
requirements_lock = Label("@req_compile_find_links_test//:requirements.txt"),
)
7 changes: 7 additions & 0 deletions private/tests/test_repositories_3.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""req-compile Bazel integration test transitive dependencies"""

load("@req_compile_test_find_links//:defs.bzl", find_links_repositories = "repositories")

def test_dependencies_3():
"""req-compile Bazel integration test transitive dependencies"""
find_links_repositories()

0 comments on commit ce76a44

Please sign in to comment.