File tree Expand file tree Collapse file tree 4 files changed +34
-13
lines changed Expand file tree Collapse file tree 4 files changed +34
-13
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ git_repository(
1717 shallow_since = "1535728917 -0400" ,
1818)
1919
20- load ("//tools/build_defs:python_repo.bzl" , "python_interpreter" )
20+ # This allows using py_test and py_library against python3.
21+ register_toolchains ("//platform_defs:default_python3_toolchain" )
22+
23+ # This allows building C++ against python3 headers.
24+ load ("//tools/build_defs:python_repo.bzl" , "python_headers" )
25+ python_headers (name = "default_python3_headers" )
2126
22- python_interpreter (name = "default_python" )
Original file line number Diff line number Diff line change 1+ load ("@bazel_tools//tools/python:toolchain.bzl" , "py_runtime_pair" )
2+
3+ py_runtime (
4+ name = "python3" ,
5+ interpreter_path = "/usr/bin/python3" ,
6+ stub_shebang = "#!/usr/bin/env python3" ,
7+ python_version = "PY3" ,
8+ )
9+
10+ py_runtime_pair (
11+ name = "just_python3" ,
12+ py2_runtime = None ,
13+ py3_runtime = ":python3" ,
14+ )
15+
16+ toolchain (
17+ name = "default_python3_toolchain" ,
18+ toolchain = ":just_python3" ,
19+ toolchain_type = "@bazel_tools//tools/python:toolchain_type" ,
20+ )
21+
Original file line number Diff line number Diff line change @@ -4,20 +4,22 @@ cc_binary(
44 linkshared = 1 ,
55 deps = [
66 "//core:libjsonnet" ,
7- "@default_python //:headers" ,
7+ "@default_python3_headers //:headers" ,
88 ],
99)
1010
1111py_library (
1212 name = "_jsonnet" ,
1313 data = [":_jsonnet.so" ],
1414 imports = ["." ],
15+ srcs_version = "PY3" ,
1516 visibility = ["//visibility:public" ],
1617)
1718
1819py_test (
1920 name = "_jsonnet_test" ,
2021 srcs = ["_jsonnet_test.py" ],
2122 data = ["test.jsonnet" ],
23+ python_version = "PY3" ,
2224 deps = [":_jsonnet" ],
2325)
Original file line number Diff line number Diff line change 11build_file_contents = """\
22 package(default_visibility = ["//visibility:public"])
33
4- sh_binary(
5- name = "python",
6- srcs = ["bin/python"],
7- data = [":include"],
8- )
9-
104filegroup(
115 name = "include",
126 srcs = glob(["include/**"]),
@@ -19,7 +13,7 @@ cc_library(
1913)
2014"""
2115
22- def _python_interpreter (repository_ctx ):
16+ def _impl (repository_ctx ):
2317 rctx = repository_ctx
2418 if "/" in rctx .attr .path or "\\ " in rctx .attr .path :
2519 # Canonicalize the path
@@ -41,12 +35,12 @@ def _python_interpreter(repository_ctx):
4135 rctx .file ("BUILD" , build_file_contents )
4236
4337
44- python_interpreter = repository_rule (
45- implementation = _python_interpreter ,
38+ python_headers = repository_rule (
39+ implementation = _impl ,
4640 local = True ,
4741 attrs = {
4842 "path" : attr .string (
49- default = "python " ,
43+ default = "python3 " ,
5044 ),
5145 },
5246)
You can’t perform that action at this time.
0 commit comments