bazelbuild / rules_python

Bazel Python Rules
https://rules-python.readthedocs.io
Apache License 2.0
538 stars 542 forks source link

Upgrading rules_python from 0.36.0 to 0.37.0 in Bazel has a bootstrapping problem #2392

Closed comius closed 1 week ago

comius commented 2 weeks ago

When updating rules_python in Bazel project at head, I get following error: Error: 'PyRuntimeInfo' value has no field or method 'pyc_tag' (full log below).

This happens because autodetecting toolchain is coming from previous Bazel version (i.e. 7.x.x), which is not fully using Python rules when defining the toolchain.

(I have a workaround)

ERROR: /usr/local/google/home/ilist/.cache/bazel/_bazel_ilist/e9eba874c4fa4205502c6d2768696dfb/external/rules_pkg+/pkg/private/tar/BUILD:63:11: in py_library rule @@rules_pkg+//pkg/private/tar:tar_writer: 
Traceback (most recent call last):
        File "/usr/local/google/home/ilist/.cache/bazel/_bazel_ilist/e9eba874c4fa4205502c6d2768696dfb/external/rules_python+/python/private/py_library_rule_bazel.bzl", line 39, column 33, in _py_library_impl
                return bazel_py_library_impl(
        File "/usr/local/google/home/ilist/.cache/bazel/_bazel_ilist/e9eba874c4fa4205502c6d2768696dfb/external/rules_python+/python/private/py_library.bzl", line 76, column 51, in py_library_impl
                precompile_result = semantics.maybe_precompile(ctx, direct_sources)
        File "/usr/local/google/home/ilist/.cache/bazel/_bazel_ilist/e9eba874c4fa4205502c6d2768696dfb/external/rules_python+/python/private/common_bazel.bzl", line 107, column 30, in maybe_precompile
                pyc = _precompile(ctx, src, use_pycache = keep_source)
        File "/usr/local/google/home/ilist/.cache/bazel/_bazel_ilist/e9eba874c4fa4205502c6d2768696dfb/external/rules_python+/python/private/common_bazel.bzl", line 168, column 32, in _precompile
                if not target_toolchain.pyc_tag:
Error: 'PyRuntimeInfo' value has no field or method 'pyc_tag'
Available attributes: bootstrap_template, coverage_files, coverage_tool, files, interpreter, interpreter_path, python_version, stub_shebang
rickeylev commented 1 week ago

This is https://github.com/bazelbuild/rules_python/issues/2364 -- closing this one as a duplicate. See also the end of this comment for some workarounds: https://github.com/bazelbuild/rules_python/issues/2364#issuecomment-2458642108