Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions py/private/py_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def _make_imports_depset(ctx):
import_paths = [
_make_import_path(ctx.label, ctx.workspace_name, base, im)
for im in ctx.attr.imports
] + [
# Add the workspace name in the imports such that repo-relative imports work.
ctx.workspace_name
]

return depset(
Expand Down
1 change: 1 addition & 0 deletions py/tests/external-deps/expected_pathing
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sys path:
(pwd)/bazel-out/host/bin/py/tests/external-deps/pathing.runfiles/pathing.venv/lib/python3.9/site-packages
(pwd)/bazel-out/host/bin/py/tests/external-deps/pathing.runfiles
(pwd)/bazel-out/host/bin/py/tests/external-deps/pathing.runfiles/aspect_rules_py/py/tests/external-deps
(pwd)/bazel-out/host/bin/py/tests/external-deps/pathing.runfiles/aspect_rules_py

Entrypoint Path: (pwd)/bazel-out/host/bin/py/tests/external-deps/pathing.runfiles/aspect_rules_py/py/tests/external-deps/pathing.py

Expand Down
5 changes: 3 additions & 2 deletions py/tests/import-pathing/tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ def _can_resolve_path_in_workspace_test_impl(ctx):
imports = py_library.make_imports_depset(fake_ctx).to_list()
asserts.equals(env, "aspect_rules_py/foo/bar", imports[0])

# Empty imports array results in no imports
# Empty imports array results in just the workspace root import
fake_ctx = _ctx_with_imports([])
imports = py_library.make_imports_depset(fake_ctx).to_list()
asserts.equals(env, 0, len(imports))
asserts.equals(env, 1, len(imports))
asserts.equals(env, "aspect_rules_py", imports[0])

# The import path is the parent package
fake_ctx = _ctx_with_imports([".."])
Expand Down
7 changes: 7 additions & 0 deletions py/tests/repo_relative_imports/lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("//py:defs.bzl", "py_library")

py_library(
name = "lib",
srcs = ["adder.py"],
visibility = ["//visibility:public"],
)
2 changes: 2 additions & 0 deletions py/tests/repo_relative_imports/lib/adder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def add(a, b):
return a + b
7 changes: 7 additions & 0 deletions py/tests/repo_relative_imports/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("//py:defs.bzl", "py_test")

py_test(
name = "test",
srcs = ["test.py"],
deps = ["//py/tests/repo_relative_imports/lib"],
)
3 changes: 3 additions & 0 deletions py/tests/repo_relative_imports/test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from py.tests.repo_relative_imports.lib import adder

assert adder.add(2, 3) == 5