Closed calder closed 6 years ago
WORKSPACE
foo/
BUILD
foo/
__init__.py
lib.py
main.py
WORKSPACE
:
git_repository(
name = "subpar",
remote = "https://github.com/google/subpar",
tag = "1.0.0",
)
foo/BUILD
:
load("@subpar//:subpar.bzl", "par_binary")
py_library(
name = "foo",
srcs = ["foo/lib.py"],
imports = ["."],
)
par_binary(
name = "foo_main",
srcs = ["foo/main.py"],
main = "foo/main.py",
deps = [
":foo",
],
)
foo/foo/__init__.py
: empty
foo/foo/lib.py
:
x = 123
foo/foo/main.py
:
from foo.lib import x
print "x = %d" % x
## Result
```sh
➤ bazel run //foo:foo_main.par
.................
INFO: Analysed target //foo:foo_main.par (11 packages loaded).
INFO: Found 1 target...
Target //foo:foo_main.par up-to-date:
bazel-bin/foo/foo_main.par
INFO: Elapsed time: 3.884s, Critical Path: 0.27s
INFO: Build completed successfully, 15 total actions
INFO: Running command line: bazel-bin/foo/foo_main.par
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File ".../.cache/bazel/.../execroot/__main__/bazel-out/local-fastbuild/bin/foo/foo_main.par/__main__.py", line 6, in <module>
ImportError: No module named lib
ERROR: Non-zero return code '1' from command: Process exited with status 1
Currently blocked on bazel: https://github.com/bazelbuild/bazel/issues/2617
Actually, in this case, it should work, but my brittle workaround is finding the wrong foo
first. I should be able to reorder the heuristic.
Subpar ignores Bazel py_library
imports
attributes. This is needed by any workspace with interdependent Python setuptools packages.The TODO currently references a Buganizer issue: https://github.com/google/subpar/blob/master/subpar.bzl#L62