Skip to content

Commit

Permalink
bazel: use hermetic python interpreter (scionproto#4267)
Browse files Browse the repository at this point in the history
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 bazelbuild/rules_python#807)
Note that rules_python is still requires an interpreter on the host to bootstrap (see bazelbuild/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.
  • Loading branch information
oncilla authored and benthor committed Nov 24, 2022
1 parent fbafa52 commit 85fdaa3
Show file tree
Hide file tree
Showing 18 changed files with 502 additions and 55 deletions.
29 changes: 21 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,27 @@ gazelle_dependencies()
# Python rules
http_archive(
name = "rules_python",
sha256 = "a30abdfc7126d497a7698c29c46ea9901c6392d6ed315171a6df5ce433aa4502",
strip_prefix = "rules_python-0.6.0",
url = "https://github.com/bazelbuild/rules_python/archive/0.6.0.tar.gz",
sha256 = "8c8fe44ef0a9afc256d1e75ad5f448bb59b81aba149b8958f02f7b3a98f5d9b4",
strip_prefix = "rules_python-0.13.0",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.13.0.tar.gz",
)

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

pip_install(
name = "pip3_deps",
requirements = "//tools/env/pip3:requirements.txt",
python_register_toolchains(
name = "python3_10",
python_version = "3.10",
)

load("@python3_10//:defs.bzl", "interpreter")
load("//tools/env/pip3:deps.bzl", "python_deps")

python_deps(interpreter)

load("@com_github_scionproto_scion_python_deps//:requirements.bzl", install_python_deps = "install_deps")

install_python_deps()

http_archive(
name = "rules_pkg",
sha256 = "62eeb544ff1ef41d786e329e1536c1d541bb9bcad27ae984d57f18f314018e66",
Expand Down Expand Up @@ -257,7 +266,11 @@ bbcp_repository()

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

python_lint_deps()
python_lint_deps(interpreter)

load("@com_github_scionproto_scion_python_lint_deps//:requirements.bzl", install_python_lint_deps = "install_deps")

install_python_lint_deps()

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

Expand Down
2 changes: 1 addition & 1 deletion acceptance/common/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@pip3_deps//:requirements.bzl", "requirement")
load("@com_github_scionproto_scion_python_deps//:requirements.bzl", "requirement")
load("//tools/lint:py.bzl", "py_library", "py_test")

package(default_visibility = ["//visibility:public"])
Expand Down
2 changes: 1 addition & 1 deletion acceptance/common/raw.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//tools/lint:py.bzl", "py_binary", "py_library", "py_test")
load("@pip3_deps//:requirements.bzl", "requirement")
load("@com_github_scionproto_scion_python_deps//:requirements.bzl", "requirement")

def raw_test(
name,
Expand Down
5 changes: 3 additions & 2 deletions acceptance/common/topogen.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//tools/lint:py.bzl", "py_binary", "py_library", "py_test")
load("@pip3_deps//:requirements.bzl", "requirement")
load("@com_github_scionproto_scion_python_deps//:requirements.bzl", "requirement")

def topogen_test(
name,
Expand Down Expand Up @@ -33,6 +33,7 @@ def topogen_test(
name = "%s_lib" % name,
srcs = [src],
deps = [
requirement("pyyaml"),
requirement("plumbum"),
"//acceptance/common:base",
"//acceptance/common:log",
Expand All @@ -47,7 +48,7 @@ def topogen_test(
"--topo=$(location %s)" % topo,
]
if gateway:
common_args += ["--setup-params='--sig'"]
common_args.append("--setup-params='--sig'")

common_data = [
"//scion-pki/cmd/scion-pki",
Expand Down
13 changes: 9 additions & 4 deletions doc/build/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ To add/remove or update dependencies:
Python
^^^^^^

The python dependencies are listed in a ``requirements.txt`` file.
This file is generated from the adjoining ``requirements.in`` by `pip-compile
<https://pypi.org/project/pip-tools/>`_. Only direct dependencies have to be
listed, the transitive dependencies are inferred by ``pip-compile``.
The python dependencies are listed in ``requirements.txt`` files. They are generated with bazel from the
adjoining ``requirements.in`` files.

The python dependencies are listed in `tools/env/pip3/requirements.txt
<https://github.com/scionproto/scion/blob/master/tools/env/pip3/requirements.txt>`__
and `tools/lint/python/requirements.txt
<https://github.com/scionproto/scion/blob/master/tools/lint/python/requirements.txt>`__.
These files is generated from the adjoining ``requirements.in`` by bazel. Only
direct dependencies have to be listed, the transitive dependencies are inferred.
The exact command to update ``requirements.txt`` is described in a comment in
the header of the file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Copyright (c) 1993-1999 Ioi Kim Lam.
Copyright (c) 2000-2001 Tix Project Group.
Copyright (c) 2004 ActiveState

This software is copyrighted by the above entities
and other parties. The following terms apply to all files associated
with the software unless explicitly disclaimed in individual files.

The authors hereby grant permission to use, copy, modify, distribute,
and license this software and its documentation for any purpose, provided
that existing copyright notices are retained in all copies and that this
notice is included verbatim in any distributions. No written agreement,
license, or royalty fee is required for any of the authorized uses.
Modifications to this software may be copyrighted by their authors
and need not follow the licensing terms described here, provided that
the new terms are clearly indicated on the first page of each file where
they apply.

IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
MODIFICATIONS.

GOVERNMENT USE: If you are acquiring this software on behalf of the
U.S. government, the Government shall have only "Restricted Rights"
in the software and related documentation as defined in the Federal
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
are acquiring the software on behalf of the Department of Defense, the
software shall be classified as "Commercial Computer Software" and the
Government shall have only "Restricted Rights" as defined in Clause
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
authors grant the U.S. Government and others acting in its behalf
permission to use and distribute the software in accordance with the
terms specified in this license.

----------------------------------------------------------------------

Parts of this software are based on the Tcl/Tk software copyrighted by
the Regents of the University of California, Sun Microsystems, Inc.,
and other parties. The original license terms of the Tcl/Tk software
distribution is included in the file docs/license.tcltk.

Parts of this software are based on the HTML Library software
copyrighted by Sun Microsystems, Inc. The original license terms of
the HTML Library software distribution is included in the file
docs/license.html_lib.
Loading

0 comments on commit 85fdaa3

Please sign in to comment.