From ab9f4586fbd4a4bc8c884adae98e08e944364e09 Mon Sep 17 00:00:00 2001 From: Andreas Berthoud Date: Thu, 3 Jun 2021 19:45:46 +0200 Subject: [PATCH] Chosing the python version an pip requirements work --- .bazelrc | 1 + .gitignore | 6 ++++++ BUILD | 17 +++++++++++++++++ WORKSPACE | 13 +++++++++++++ main.py | 15 +++++++++++++++ requirements.txt | 2 ++ 6 files changed, 54 insertions(+) create mode 100644 .bazelrc create mode 100644 .gitignore create mode 100644 BUILD create mode 100644 WORKSPACE create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..f0f013d --- /dev/null +++ b/.bazelrc @@ -0,0 +1 @@ +run --incompatible_use_python_toolchains=false --python_top=//:python38 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..33dedea --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.swp + +bazel-bazel* +bazel-bin* +bazel-out* +bazel-testlogs* diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..cfe325a --- /dev/null +++ b/BUILD @@ -0,0 +1,17 @@ +load("@rules_python//python:defs.bzl", "py_binary") +load("@my_deps//:requirements.bzl", "requirement") + +py_runtime( + name = "python38", + interpreter_path = "/usr/local/bin/python3.8", +) + +py_binary( + name = "main", + srcs = ["main.py"], + srcs_version = "PY3", + deps = [ + requirement("pyyaml"), + requirement("flask"), + ], +) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..e1c0cc4 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,13 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_python", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.2.0/rules_python-0.2.0.tar.gz", + sha256 = "778197e26c5fbeb07ac2a2c5ae405b30f6cb7ad1f5510ea6fdac03bded96cc6f", +) + +load("@rules_python//python:pip.bzl", "pip_install") +pip_install( + name = "my_deps", + requirements = "//:requirements.txt", +) diff --git a/main.py b/main.py new file mode 100644 index 0000000..05e368e --- /dev/null +++ b/main.py @@ -0,0 +1,15 @@ +import os +import sys + +import flask +import yaml + + +def main(): + print("hello from {}".format(os.getcwd())) + print("version: {}".format(sys.version)) + print("interpreter: {}".format(sys.executable)) + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f3da9a5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pyyaml +flask