Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ exports_files([
"conda-env.yml",
"mypy.ini",
"requirements.txt",
"requirements.yml",
])
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,12 @@ Another useful command is, `bazel run`. This builds and then run the built targe
### Python dependencies

To introduce a third-party Python dependency, first check if it is available as a package in the
[Snowflake conda channel](https://repo.anaconda.com/pkgs/snowflake/). If so, add the package
to [conda-env-snowflake.yml](https://github.com/snowflakedb/snowml/blob/main/conda-env-snowflake.yml),
and run the following to re-generate
[Snowflake conda channel](https://repo.anaconda.com/pkgs/snowflake/). Then modify
[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
[conda-env.yml](https://github.com/snowflakedb/snowml/blob/main/conda-env.yml):

```
bazel build //bazel:conda-env.yml && cp bazel-bin/bazel/conda-env.yml .
bazel run //bazel/requirements:sync_requirements
```

Then, your code can use the package as if it were "installed" in the Python environment.
Expand Down
14 changes: 14 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ http_archive(

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

http_archive(
name = "aspect_bazel_lib",
sha256 = "e3151d87910f69cf1fc88755392d7c878034a69d6499b287bcfc00b1cf9bb415",
strip_prefix = "bazel-lib-1.32.1",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.32.1/bazel-lib-v1.32.1.tar.gz",
)

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "register_yq_toolchains")

aspect_bazel_lib_dependencies()
register_yq_toolchains()

# Below two conda environments (toolchains) are created and they require different
# constraint values. Two platforms defined in bazel/platforms/BUILD provide those
# constraint values. A toolchain matches a platform as long as the platform provides
Expand All @@ -44,6 +56,7 @@ conda_create(
timeout = 3600,
clean = False,
environment = "@//:conda-env-snowflake.yml",
coverage_tool = "@//bazel/coverage_tool:coverage_tool.py",
quiet = True,
)

Expand All @@ -62,6 +75,7 @@ conda_create(
timeout = 3600,
clean = False,
environment = "@//:conda-env.yml",
coverage_tool = "@//bazel/coverage_tool:coverage_tool.py",
quiet = True,
)

Expand Down
65 changes: 0 additions & 65 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@rules_python//python:defs.bzl", native_py_test = "py_test")
load(":py_rules.bzl", "py_binary", "py_library")

native_py_test(
name = "repo_paths_test",
Expand All @@ -8,67 +7,3 @@ native_py_test(
python_version = "PY3",
srcs_version = "PY3",
)

py_library(
name = "conda_env_utils",
srcs = ["conda_env_utils.py"],
)

py_binary(
name = "generate_conda_env",
srcs = ["generate_conda_env.py"],
deps = [":conda_env_utils"],
)

py_binary(
name = "generate_requirements",
srcs = ["generate_requirements.py"],
deps = [":conda_env_utils"],
)

genrule(
name = "conda_env_gen",
srcs = [
"//:conda-env-extended.yml",
"//:conda-env-snowflake.yml",
],
outs = ["conda-env.yml"],
cmd = "$(location :generate_conda_env) $(location //:conda-env-snowflake.yml) $(location //:conda-env-extended.yml)> $@",
tools = [":generate_conda_env"],
)

sh_test(
name = "conda_env_test",
srcs = ["conda_env_test.sh"],
args = [
"$(location //:conda-env.yml)",
"$(location :conda-env.yml)",
],
data = [
":conda-env.yml",
"//:conda-env.yml",
],
)

genrule(
name = "requirements_gen",
srcs = [
"//:conda-env.yml",
],
outs = ["requirements.txt"],
cmd = "$(location :generate_requirements) $(location //:conda-env.yml) > $@",
tools = [":generate_requirements"],
)

sh_test(
name = "requirements_conda_env_sync_test",
srcs = ["requirements_conda_env_test.sh"],
args = [
"$(location //:requirements.txt)",
"$(location :requirements.txt)",
],
data = [
":requirements.txt",
"//:requirements.txt",
],
)
14 changes: 0 additions & 14 deletions bazel/conda_env_test.sh

This file was deleted.

51 changes: 0 additions & 51 deletions bazel/conda_env_utils.py

This file was deleted.

3 changes: 3 additions & 0 deletions bazel/coverage_tool/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package(default_visibility = ["//visibility:public"])

exports_files(["coverage_tool.py"])
25 changes: 25 additions & 0 deletions bazel/coverage_tool/coverage_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""This is a wrapper to the coverage tool.
It injects a --ignore-errors argument when called to generate a coverage report, to avoid bazel fails when running
coverage tool to collect coverage report on a source code file that does not exist, for example, zip-imported source.
"""
import re
import sys

try:
from coverage.cmdline import main
except ImportError as e:
raise ImportError(
f"Unable to import coverage. Make sure coverage is added to the bazel conda environment. Actual error: {e}"
)

if __name__ == "__main__":
if len(sys.argv) < 2:
raise ValueError("Too few arguments.")
# This line is from the original coverage entrypoint.
sys.argv[0] = re.sub(r"(-script\.pyw?|\.exe)?$", "", sys.argv[0])

action, options = sys.argv[1], sys.argv[2:]
if action in ["report", "html", "xml", "json", "lcov", "annotate"]:
options.insert(0, "--ignore-errors")
args = [action] + options
sys.exit(main(args))
30 changes: 0 additions & 30 deletions bazel/generate_conda_env.py

This file was deleted.

25 changes: 0 additions & 25 deletions bazel/generate_requirements.py

This file was deleted.

Loading