Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated python scripts fail to import correctly #793

Closed
damienmg opened this issue Jan 16, 2016 · 3 comments
Closed

Generated python scripts fail to import correctly #793

damienmg opened this issue Jan 16, 2016 · 3 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Python Native rules for Python type: bug

Comments

@damienmg
Copy link
Contributor

This is a direct consequence of http://bugs.python.org/issue6386:

$ bazel run  b:bin
INFO: Found 1 target...
Target //b:bin up-to-date:
  bazel-genfiles/b/__init__.py
  bazel-bin/b/bin
INFO: Elapsed time: 0.097s, Critical Path: 0.00s

INFO: Running command line: bazel-bin/b/bin
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_dmarting/d13d2b815007acab3d9cf94b6c2cd8b9/tata/bazel-out/local_darwin-fastbuild/bin/b/bin.runfiles/b/__init__.py", line 1, in <module>
    import a
ImportError: No module named a
ERROR: Non-zero return code '1' from command: Process exited with status 1.
$ ls b
BUILD   a.py
$ cat b/BUILD 
genrule(
  name = "init",
  cmd = "echo 'import a' > $@",
  outs = ["__init__.py"],
)

py_binary(
  name = "bin",
  main = "__init__.py",
  srcs = ["__init__.py", "a.py"],
)
$ cat b/a.py 
print 'Hello, World!'
$ 

This should works.

@damienmg damienmg added type: bug P2 We'll consider working on this in future. (Assignee optional) Native rules (Java / C++ / Python) labels Jan 16, 2016
@damienmg damienmg changed the title Python scripts does not works as expected Generated python scripts failed to import correctly Jan 16, 2016
@damienmg damienmg changed the title Generated python scripts failed to import correctly Generated python scripts fail to import correctly Jan 16, 2016
@damienmg
Copy link
Contributor Author

workaround is to do a from b import a as the pythonpath is set to the workspace root.

@damienmg damienmg added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed P2 We'll consider working on this in future. (Assignee optional) labels Jan 16, 2016
@damienmg
Copy link
Contributor Author

fwiw, because of that bug, the .pyc files are generated in the workspace root if the main script is not generated and without sandboxing.

@sgowroji
Copy link
Member

Hi there! We're doing a clean up of old issues and will be closing this one. Please reopen if you’d like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Python Native rules for Python type: bug
Projects
None yet
Development

No branches or pull requests

5 participants