From https://github.com/bazelbuild/rules_docker/issues/169
On Linux Ubuntu 14.10 and bazel 0.5.4:
$ bazel build --force_python=py3 --python_path=/usr/bin/python3 :bazel-srcs
INFO: Analysed target //:bazel-srcs (0 packages loaded).
INFO: Found 1 target...
ERROR: /usr/local/google/home/dmarting/git/bazel/BUILD:63:1: error executing shell command: 'bazel-out/host/bin/tools/build_defs/pkg/build_tar --flagfile=bazel-out/local-py3-fastbuild/bin/bazel-srcs.args' failed (Exit 1)
Traceback (most recent call last):
File "/usr/local/google/home/dmarting/.cache/bazel/_bazel_dmarting/4c68128ea7d752c9535d956d14249eea/bazel-sandbox/5414131446493874244/execroot/io_bazel/bazel-out/host/bin/tools/build_defs/pkg/build_tar.runfiles/io_bazel/tools/build_defs/pkg/build_tar.py", line 23, in <module>
from third_party.py import gflags
File "/usr/local/google/home/dmarting/.cache/bazel/_bazel_dmarting/4c68128ea7d752c9535d956d14249eea/bazel-sandbox/5414131446493874244/execroot/io_bazel/bazel-out/host/bin/tools/build_defs/pkg/build_tar.runfiles/io_bazel/third_party/py/gflags/__init__.py", line 1, in <module>
from gflags import *
ImportError: No module named 'gflags'
Target //:bazel-srcs failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.721s, Critical Path: 0.83s
FAILED: Build did NOT complete successfully
$ bazel build :bazel-srcs
INFO: Analysed target //:bazel-srcs (0 packages loaded).
INFO: Found 1 target...
Target //:bazel-srcs up-to-date:
bazel-bin/bazel-srcs.tar
INFO: Elapsed time: 0.867s, Critical Path: 0.03s
INFO: Build completed successfully, 2 total actions
Looking at this change: https://github.com/bazelbuild/bazel/commit/d7f5c120417bc2d2344dfb285322355f225d9153#diff-9b37129659ed5796bc9a42ed36bb49e1
That updates gflags to 3.1.0. Comparing Bazel's copy to stock gflags 3.1.0, it appears to have manually edited all the import statements from a compatible form, to a form that can only work in Python 2. Presumably there was some other problem that motivated this?
CC @spxtr
That's curious. On my arch box both bazel build --force_python=py3 --python_path=/usr/bin/python3 :bazel-srcs and bazel build :bazel-srcs complete successfully.
Comparing Bazel's copy to stock gflags 3.1.0, it appears to have manually edited all the import statements from a compatible form, to a form that can only work in Python 2. Presumably there was some other problem that motivated this?
How do you mean? IIRC I just copied the code directly.
Would it be worth using the newly-released abseil version of gflags directly, rather than importing a local copy: https://github.com/abseil/abseil-py/tree/master/absl/flags ?
Comparing Bazel's copy to stock gflags 3.1.0, it appears to have manually edited all the import statements from a compatible form, to a form that can only work in Python 2. Presumably there was some other problem that motivated this?
How do you mean? IIRC I just copied the code directly.
Comparing upstream vs. bazel versions of gflags 3.1.0, it looks like from gflags was omitted from the import statements.
The correct thing to do here is move off of gflags entirely, not carry your own copy of the ancient dead code at all. Use absl.flags from https://pypi.org/project/absl-py/.
Most helpful comment
Would it be worth using the newly-released abseil version of gflags directly, rather than importing a local copy: https://github.com/abseil/abseil-py/tree/master/absl/flags ?