From 1097784048b8ff06604c77c314382260990ddfc0 Mon Sep 17 00:00:00 2001 From: dayfine <26423504+dayfine@users.noreply.github.com> Date: Sun, 3 May 2020 18:09:14 -0700 Subject: [PATCH] re-organize py venv and use a bazel toolchain rule to specifiy expected py path --- .bazelignore | 2 +- .circleci/config.yml | 11 ++--------- .envrc | 8 ++++++++ .gitignore | 2 +- BUILD | 18 ++++++++++++++++++ WORKSPACE | 4 ++++ xlab/data/scripts/BUILD | 1 + 7 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 .envrc diff --git a/.bazelignore b/.bazelignore index 92b2793..1d17dae 100644 --- a/.bazelignore +++ b/.bazelignore @@ -1 +1 @@ -.direnv +.venv diff --git a/.circleci/config.yml b/.circleci/config.yml index 2f74358..e476449 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,10 +17,6 @@ commands: steps: - attach_workspace: at: *workspace_location - - run: - name: pwd - command: | - pwd # Install python as the bazel image is used instead of python image. install_python: @@ -43,11 +39,8 @@ commands: - run: name: Activate virtual environment command: | - python3.8 -m venv env --without-pip - source env/bin/activate - pwd - ls - which python3 + python3.8 -m venv .venv --without-pip + source .venv/bin/activate # Initializes the CI environment by setting up common environment variables. init_environment: diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3a8c4f2 --- /dev/null +++ b/.envrc @@ -0,0 +1,8 @@ +# Envrionment setup for local developmeent using direnv. + +source secrets.rc + +# https://github.com/direnv/direnv/wiki/Python +export VIRTUAL_ENV=.venv +layout python-venv python3.8 + diff --git a/.gitignore b/.gitignore index 0b55e87..b9c3cae 100644 --- a/.gitignore +++ b/.gitignore @@ -107,7 +107,6 @@ celerybeat.pid # Environments .env -.envrc .venv env/ venv/ @@ -115,6 +114,7 @@ ENV/ env.bak/ venv.bak/ .direnv +secrets.rc # Spyder project settings .spyderproject diff --git a/BUILD b/BUILD index e69de29..589164b 100644 --- a/BUILD +++ b/BUILD @@ -0,0 +1,18 @@ +load("@rules_python//python:defs.bzl", "py_runtime", "py_runtime_pair") + +py_runtime( + name = "python-3.8", + interpreter = ".venv/bin/python3.8", + python_version = "PY3", +) + +py_runtime_pair( + name = "py_runtime_pair", + py3_runtime = ":python-3.8", +) + +toolchain( + name = "py_toolchain", + toolchain = ":py_runtime_pair", + toolchain_type = "@rules_python//python:toolchain_type", +) diff --git a/WORKSPACE b/WORKSPACE index f04fe19..f537464 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -44,6 +44,8 @@ http_archive( url = "https://github.com/dillon-giacoppo/rules_python_external/archive/v{version}.zip".format(version = rules_python_external_version), ) +register_toolchains("//:py_toolchain") + load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") protobuf_deps() @@ -75,5 +77,7 @@ load("@rules_python_external//:defs.bzl", "pip_install") pip_install( name = "py_deps", + # TODO(dayfine): this should not be necesasry. + python_interpreter = "/usr/bin/python3.8", requirements = "//:requirements.txt", ) diff --git a/xlab/data/scripts/BUILD b/xlab/data/scripts/BUILD index 9e8abf8..ba49c7f 100644 --- a/xlab/data/scripts/BUILD +++ b/xlab/data/scripts/BUILD @@ -38,4 +38,5 @@ py_binary( "//xlab/util/status:errors", requirement("absl-py"), requirement("protobuf"), + ], )