Skip to content

Commit 8fc1648

Browse files
authored
bazel: use hermetic python interpreter (#4267)
Update the rules_python to the latest release and register the hermetic python interpreter with version 3.10. This also removes the usage of the deprecated pip_install (see bazel-contrib/rules_python#807) Note that rules_python is still requires an interpreter on the host to bootstrap (see bazel-contrib/rules_python#691). This should remove our reliance on the host interpreter as much as possible if the python tools are executed with bazel. E.g., when running an acceptance test, when linting, or when running the topology generator with bazel run.
1 parent 50f06eb commit 8fc1648

File tree

18 files changed

+502
-55
lines changed

18 files changed

+502
-55
lines changed

WORKSPACE

+21-8
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,27 @@ gazelle_dependencies()
8888
# Python rules
8989
http_archive(
9090
name = "rules_python",
91-
sha256 = "a30abdfc7126d497a7698c29c46ea9901c6392d6ed315171a6df5ce433aa4502",
92-
strip_prefix = "rules_python-0.6.0",
93-
url = "https://github.com/bazelbuild/rules_python/archive/0.6.0.tar.gz",
91+
sha256 = "8c8fe44ef0a9afc256d1e75ad5f448bb59b81aba149b8958f02f7b3a98f5d9b4",
92+
strip_prefix = "rules_python-0.13.0",
93+
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.13.0.tar.gz",
9494
)
9595

96-
load("@rules_python//python:pip.bzl", "pip_install")
96+
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
9797

98-
pip_install(
99-
name = "pip3_deps",
100-
requirements = "//tools/env/pip3:requirements.txt",
98+
python_register_toolchains(
99+
name = "python3_10",
100+
python_version = "3.10",
101101
)
102102

103+
load("@python3_10//:defs.bzl", "interpreter")
104+
load("//tools/env/pip3:deps.bzl", "python_deps")
105+
106+
python_deps(interpreter)
107+
108+
load("@com_github_scionproto_scion_python_deps//:requirements.bzl", install_python_deps = "install_deps")
109+
110+
install_python_deps()
111+
103112
http_archive(
104113
name = "rules_pkg",
105114
sha256 = "62eeb544ff1ef41d786e329e1536c1d541bb9bcad27ae984d57f18f314018e66",
@@ -257,7 +266,11 @@ bbcp_repository()
257266

258267
load("//tools/lint/python:deps.bzl", "python_lint_deps")
259268

260-
python_lint_deps()
269+
python_lint_deps(interpreter)
270+
271+
load("@com_github_scionproto_scion_python_lint_deps//:requirements.bzl", install_python_lint_deps = "install_deps")
272+
273+
install_python_lint_deps()
261274

262275
load("//rules_openapi:dependencies.bzl", "rules_openapi_dependencies")
263276

acceptance/common/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@pip3_deps//:requirements.bzl", "requirement")
1+
load("@com_github_scionproto_scion_python_deps//:requirements.bzl", "requirement")
22
load("//tools/lint:py.bzl", "py_library", "py_test")
33

44
package(default_visibility = ["//visibility:public"])

acceptance/common/raw.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("//tools/lint:py.bzl", "py_binary", "py_library", "py_test")
2-
load("@pip3_deps//:requirements.bzl", "requirement")
2+
load("@com_github_scionproto_scion_python_deps//:requirements.bzl", "requirement")
33

44
def raw_test(
55
name,

acceptance/common/topogen.bzl

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("//tools/lint:py.bzl", "py_binary", "py_library", "py_test")
2-
load("@pip3_deps//:requirements.bzl", "requirement")
2+
load("@com_github_scionproto_scion_python_deps//:requirements.bzl", "requirement")
33

44
def topogen_test(
55
name,
@@ -33,6 +33,7 @@ def topogen_test(
3333
name = "%s_lib" % name,
3434
srcs = [src],
3535
deps = [
36+
requirement("pyyaml"),
3637
requirement("plumbum"),
3738
"//acceptance/common:base",
3839
"//acceptance/common:log",
@@ -47,7 +48,7 @@ def topogen_test(
4748
"--topo=$(location %s)" % topo,
4849
]
4950
if gateway:
50-
common_args += ["--setup-params='--sig'"]
51+
common_args.append("--setup-params='--sig'")
5152

5253
common_data = [
5354
"//scion-pki/cmd/scion-pki",

doc/build/dependencies.rst

+9-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ To add/remove or update dependencies:
4141
Python
4242
^^^^^^
4343

44-
The python dependencies are listed in a ``requirements.txt`` file.
45-
This file is generated from the adjoining ``requirements.in`` by `pip-compile
46-
<https://pypi.org/project/pip-tools/>`_. Only direct dependencies have to be
47-
listed, the transitive dependencies are inferred by ``pip-compile``.
44+
The python dependencies are listed in ``requirements.txt`` files. They are generated with bazel from the
45+
adjoining ``requirements.in`` files.
46+
47+
The python dependencies are listed in `tools/env/pip3/requirements.txt
48+
<https://github.com/scionproto/scion/blob/master/tools/env/pip3/requirements.txt>`__
49+
and `tools/lint/python/requirements.txt
50+
<https://github.com/scionproto/scion/blob/master/tools/lint/python/requirements.txt>`__.
51+
These files is generated from the adjoining ``requirements.in`` by bazel. Only
52+
direct dependencies have to be listed, the transitive dependencies are inferred.
4853
The exact command to update ``requirements.txt`` is described in a comment in
4954
the header of the file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Copyright (c) 1993-1999 Ioi Kim Lam.
2+
Copyright (c) 2000-2001 Tix Project Group.
3+
Copyright (c) 2004 ActiveState
4+
5+
This software is copyrighted by the above entities
6+
and other parties. The following terms apply to all files associated
7+
with the software unless explicitly disclaimed in individual files.
8+
9+
The authors hereby grant permission to use, copy, modify, distribute,
10+
and license this software and its documentation for any purpose, provided
11+
that existing copyright notices are retained in all copies and that this
12+
notice is included verbatim in any distributions. No written agreement,
13+
license, or royalty fee is required for any of the authorized uses.
14+
Modifications to this software may be copyrighted by their authors
15+
and need not follow the licensing terms described here, provided that
16+
the new terms are clearly indicated on the first page of each file where
17+
they apply.
18+
19+
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
20+
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
21+
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
22+
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
23+
POSSIBILITY OF SUCH DAMAGE.
24+
25+
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
26+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
27+
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
28+
IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
29+
NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
30+
MODIFICATIONS.
31+
32+
GOVERNMENT USE: If you are acquiring this software on behalf of the
33+
U.S. government, the Government shall have only "Restricted Rights"
34+
in the software and related documentation as defined in the Federal
35+
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
36+
are acquiring the software on behalf of the Department of Defense, the
37+
software shall be classified as "Commercial Computer Software" and the
38+
Government shall have only "Restricted Rights" as defined in Clause
39+
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
40+
authors grant the U.S. Government and others acting in its behalf
41+
permission to use and distribute the software in accordance with the
42+
terms specified in this license.
43+
44+
----------------------------------------------------------------------
45+
46+
Parts of this software are based on the Tcl/Tk software copyrighted by
47+
the Regents of the University of California, Sun Microsystems, Inc.,
48+
and other parties. The original license terms of the Tcl/Tk software
49+
distribution is included in the file docs/license.tcltk.
50+
51+
Parts of this software are based on the HTML Library software
52+
copyrighted by Sun Microsystems, Inc. The original license terms of
53+
the HTML Library software distribution is included in the file
54+
docs/license.html_lib.

0 commit comments

Comments
 (0)