forked from spietras/rules_conda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefs.bzl
48 lines (42 loc) · 1.45 KB
/
defs.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load(":conda.bzl", "load_conda_rule")
load(":env.bzl", "conda_create_rule")
load(":toolchain.bzl", "toolchain_rule")
CONDA_REPO_NAME = "conda"
CONDA_DIR = "conda"
DEFAULT_CONDA_VERSION = "4.10.3"
DEFAULT_TOOLCHAIN_REPO_NAME = "conda_tools"
DEFAULT_TOOLCHAIN_NAME = "python_toolchain"
DEFAULT_MAMBA_VERSION = "0.17.0"
# download and install conda
def load_conda(conda_version = DEFAULT_CONDA_VERSION, mamba_version = DEFAULT_MAMBA_VERSION, **kwargs):
maybe(
load_conda_rule,
CONDA_REPO_NAME,
conda_dir = CONDA_DIR,
conda_version = conda_version,
mamba_version = mamba_version,
**kwargs
)
# create conda environment
def conda_create(name, **kwargs):
maybe(
conda_create_rule,
name,
conda_repo = CONDA_REPO_NAME,
conda_dir = CONDA_DIR,
**kwargs
)
# register python toolchain from environments
def register_toolchain(py3_env, py2_env = None, name = DEFAULT_TOOLCHAIN_REPO_NAME, toolchain_name = DEFAULT_TOOLCHAIN_NAME, **kwargs):
py2_runtime = "@{}//:python_runtime".format(py2_env) if py2_env else None
py3_runtime = "@{}//:python_runtime".format(py3_env)
maybe(
toolchain_rule,
name,
py2_runtime = py2_runtime,
py3_runtime = py3_runtime,
toolchain_name = toolchain_name,
**kwargs
)
native.register_toolchains("@{}//:{}".format(name, toolchain_name))