Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Subpar ignores Bazel imports #47

Closed
calder opened this issue Nov 1, 2017 · 3 comments
Closed

Subpar ignores Bazel imports #47

calder opened this issue Nov 1, 2017 · 3 comments

Comments

@calder
Copy link

calder commented Nov 1, 2017

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

@calder
Copy link
Author

calder commented Nov 1, 2017

Minimal example

Directory structure

  • WORKSPACE
  • foo/
    • BUILD
    • foo/
      • __init__.py
      • lib.py
      • main.py

Contents

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

➤ 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

@duggelz
Copy link
Contributor

duggelz commented Nov 1, 2017

Currently blocked on bazel: bazelbuild/bazel#2617

@duggelz
Copy link
Contributor

duggelz commented Nov 1, 2017

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.

duggelz pushed a commit that referenced this issue Nov 2, 2017
duggelz pushed a commit that referenced this issue Nov 8, 2017
* Add testcase for #47

* Retain Bazel's ordering of Python import paths.

* Alphabetize test names

* Actually alphabetize tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants