Skip to content

Commit 8d57915

Browse files
snowflake-provisionerSnowflake Authors
and
Snowflake Authors
authored
Project import generated by Copybara. (#19)
GitOrigin-RevId: f3a7f81fc4a4b7bf631292bf491cdf99e3e90e6c Co-authored-by: Snowflake Authors <[email protected]>
1 parent 69a4f0d commit 8d57915

File tree

226 files changed

+5187
-1909
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+5187
-1909
lines changed

BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ exports_files([
44
"conda-env.yml",
55
"mypy.ini",
66
"requirements.txt",
7+
"requirements.yml",
78
])

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,12 @@ Another useful command is, `bazel run`. This builds and then run the built targe
142142
### Python dependencies
143143

144144
To introduce a third-party Python dependency, first check if it is available as a package in the
145-
[Snowflake conda channel](https://repo.anaconda.com/pkgs/snowflake/). If so, add the package
146-
to [conda-env-snowflake.yml](https://github.com/snowflakedb/snowml/blob/main/conda-env-snowflake.yml),
147-
and run the following to re-generate
145+
[Snowflake conda channel](https://repo.anaconda.com/pkgs/snowflake/). Then modify
146+
[requirements.yml](https://github.com/snowflakedb/snowml/blob/main/requirements.yml) following the instruction there, and run the following to re-generate all requirements files, including
148147
[conda-env.yml](https://github.com/snowflakedb/snowml/blob/main/conda-env.yml):
149148

150149
```
151-
bazel build //bazel:conda-env.yml && cp bazel-bin/bazel/conda-env.yml .
150+
bazel run //bazel/requirements:sync_requirements
152151
```
153152

154153
Then, your code can use the package as if it were "installed" in the Python environment.

WORKSPACE

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ http_archive(
2424

2525
load("//third_party/rules_conda:defs.bzl", "conda_create", "load_conda", "register_toolchain")
2626

27+
http_archive(
28+
name = "aspect_bazel_lib",
29+
sha256 = "e3151d87910f69cf1fc88755392d7c878034a69d6499b287bcfc00b1cf9bb415",
30+
strip_prefix = "bazel-lib-1.32.1",
31+
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.32.1/bazel-lib-v1.32.1.tar.gz",
32+
)
33+
34+
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "register_yq_toolchains")
35+
36+
aspect_bazel_lib_dependencies()
37+
register_yq_toolchains()
38+
2739
# Below two conda environments (toolchains) are created and they require different
2840
# constraint values. Two platforms defined in bazel/platforms/BUILD provide those
2941
# constraint values. A toolchain matches a platform as long as the platform provides
@@ -44,6 +56,7 @@ conda_create(
4456
timeout = 3600,
4557
clean = False,
4658
environment = "@//:conda-env-snowflake.yml",
59+
coverage_tool = "@//bazel/coverage_tool:coverage_tool.py",
4760
quiet = True,
4861
)
4962

@@ -62,6 +75,7 @@ conda_create(
6275
timeout = 3600,
6376
clean = False,
6477
environment = "@//:conda-env.yml",
78+
coverage_tool = "@//bazel/coverage_tool:coverage_tool.py",
6579
quiet = True,
6680
)
6781

bazel/BUILD.bazel

-65
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
load("@rules_python//python:defs.bzl", native_py_test = "py_test")
2-
load(":py_rules.bzl", "py_binary", "py_library")
32

43
native_py_test(
54
name = "repo_paths_test",
@@ -8,67 +7,3 @@ native_py_test(
87
python_version = "PY3",
98
srcs_version = "PY3",
109
)
11-
12-
py_library(
13-
name = "conda_env_utils",
14-
srcs = ["conda_env_utils.py"],
15-
)
16-
17-
py_binary(
18-
name = "generate_conda_env",
19-
srcs = ["generate_conda_env.py"],
20-
deps = [":conda_env_utils"],
21-
)
22-
23-
py_binary(
24-
name = "generate_requirements",
25-
srcs = ["generate_requirements.py"],
26-
deps = [":conda_env_utils"],
27-
)
28-
29-
genrule(
30-
name = "conda_env_gen",
31-
srcs = [
32-
"//:conda-env-extended.yml",
33-
"//:conda-env-snowflake.yml",
34-
],
35-
outs = ["conda-env.yml"],
36-
cmd = "$(location :generate_conda_env) $(location //:conda-env-snowflake.yml) $(location //:conda-env-extended.yml)> $@",
37-
tools = [":generate_conda_env"],
38-
)
39-
40-
sh_test(
41-
name = "conda_env_test",
42-
srcs = ["conda_env_test.sh"],
43-
args = [
44-
"$(location //:conda-env.yml)",
45-
"$(location :conda-env.yml)",
46-
],
47-
data = [
48-
":conda-env.yml",
49-
"//:conda-env.yml",
50-
],
51-
)
52-
53-
genrule(
54-
name = "requirements_gen",
55-
srcs = [
56-
"//:conda-env.yml",
57-
],
58-
outs = ["requirements.txt"],
59-
cmd = "$(location :generate_requirements) $(location //:conda-env.yml) > $@",
60-
tools = [":generate_requirements"],
61-
)
62-
63-
sh_test(
64-
name = "requirements_conda_env_sync_test",
65-
srcs = ["requirements_conda_env_test.sh"],
66-
args = [
67-
"$(location //:requirements.txt)",
68-
"$(location :requirements.txt)",
69-
],
70-
data = [
71-
":requirements.txt",
72-
"//:requirements.txt",
73-
],
74-
)

bazel/conda_env_test.sh

-14
This file was deleted.

bazel/conda_env_utils.py

-51
This file was deleted.

bazel/coverage_tool/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
exports_files(["coverage_tool.py"])

bazel/coverage_tool/coverage_tool.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""This is a wrapper to the coverage tool.
2+
It injects a --ignore-errors argument when called to generate a coverage report, to avoid bazel fails when running
3+
coverage tool to collect coverage report on a source code file that does not exist, for example, zip-imported source.
4+
"""
5+
import re
6+
import sys
7+
8+
try:
9+
from coverage.cmdline import main
10+
except ImportError as e:
11+
raise ImportError(
12+
f"Unable to import coverage. Make sure coverage is added to the bazel conda environment. Actual error: {e}"
13+
)
14+
15+
if __name__ == "__main__":
16+
if len(sys.argv) < 2:
17+
raise ValueError("Too few arguments.")
18+
# This line is from the original coverage entrypoint.
19+
sys.argv[0] = re.sub(r"(-script\.pyw?|\.exe)?$", "", sys.argv[0])
20+
21+
action, options = sys.argv[1], sys.argv[2:]
22+
if action in ["report", "html", "xml", "json", "lcov", "annotate"]:
23+
options.insert(0, "--ignore-errors")
24+
args = [action] + options
25+
sys.exit(main(args))

bazel/generate_conda_env.py

-30
This file was deleted.

bazel/generate_requirements.py

-25
This file was deleted.

0 commit comments

Comments
 (0)