Skip to content

Commit

Permalink
Increased execute timeout and released new version
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Pietras committed Sep 5, 2020
1 parent 4c81dac commit 35dd105
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_conda",
sha256 = "f5c5e6be86ddc28ef2ed9163878f5a073defc5d79b82e60570f502549c9ef602",
url = "https://github.com/spietras/rules_conda/releases/download/0.0.1/rules_conda-0.0.1.zip"
sha256 = "3258a44335f10a8ecffd983a5caf5f5c37b92ea191bfe743bb85280ef864cfd9",
url = "https://github.com/spietras/rules_conda/releases/download/0.0.2/rules_conda-0.0.2.zip"
)

load("@rules_conda//:defs.bzl", "load_conda", "conda_create", "register_toolchain")
Expand Down
10 changes: 6 additions & 4 deletions conda.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load(":utils.bzl", "INSTALLER_SCRIPT_EXT_MAP", "CONDA_EXT_MAP", "get_os", "get_arch", "execute_waitable_windows", "windowsify")
load(":utils.bzl", "INSTALLER_SCRIPT_EXT_MAP", "CONDA_EXT_MAP", "EXECUTE_TIMEOUT", "get_os", "get_arch", "execute_waitable_windows", "windowsify")


# CONDA CONFIGURATION
CONDA_MAJOR = "3"
Expand Down Expand Up @@ -31,6 +32,7 @@ CONDA_BUILD_FILE_TEMPLATE = """# This file was automatically generated by rules_
exports_files(['{conda}'])
"""


def _get_installer_flags(rctx, dir):
os = get_os(rctx)
flags = CONDA_INSTALLER_FLAGS[os]
Expand Down Expand Up @@ -71,9 +73,9 @@ def _install_conda(rctx, installer):
# TODO: fix always returning 0
# it seems that either miniconda installer returns 0 even on failure or the wrapper does something wrong
# also stdout and stderr are always empty
result = execute_waitable_windows(rctx, args, quiet=rctx.attr.quiet, environment={"CONDA_DLL_SEARCH_MODIFICATION_ENABLE": ""})
result = execute_waitable_windows(rctx, args, quiet=rctx.attr.quiet, environment={"CONDA_DLL_SEARCH_MODIFICATION_ENABLE": ""}, timeout=EXECUTE_TIMEOUT)
else:
result = rctx.execute(args, quiet=rctx.attr.quiet)
result = rctx.execute(args, quiet=rctx.attr.quiet, timeout=EXECUTE_TIMEOUT)

if result.return_code:
fail("Failure installing conda.\n{}\n{}".format(result.stdout, result.stderr))
Expand All @@ -85,7 +87,7 @@ def _update_conda(rctx, executable):
conda_with_version = "conda={}".format(rctx.attr.version)
args = [rctx.path(executable), "install", conda_with_version, "-y"]
# update conda itself
result = rctx.execute(args, quiet=rctx.attr.quiet, working_directory=rctx.attr.conda_dir)
result = rctx.execute(args, quiet=rctx.attr.quiet, working_directory=rctx.attr.conda_dir, timeout=EXECUTE_TIMEOUT)
if result.return_code:
fail("Failure updating conda.\n{}\n{}".format(result.stdout, result.stderr))

Expand Down
7 changes: 4 additions & 3 deletions env.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load(":utils.bzl", "CONDA_EXT_MAP", "PYTHON_EXT_MAP", "get_os")
load(":utils.bzl", "CONDA_EXT_MAP", "PYTHON_EXT_MAP", "EXECUTE_TIMEOUT", "get_os")


BUILD_FILE_CONTENT = """# This file was automatically generated by rules_conda
package(default_visibility = ["//visibility:public"])
Expand All @@ -23,15 +24,15 @@ def _create_environment(rctx, executable, env_name):

args = [rctx.path(executable), "env", "create", "-f", env_file, "-p", "./{}".format(env_name)]

result = rctx.execute(args, quiet=rctx.attr.quiet)
result = rctx.execute(args, quiet=rctx.attr.quiet, timeout=EXECUTE_TIMEOUT)
if result.return_code:
fail("Failure creating environment.\n{}\n{}".format(result.stdout, result.stderr))


# check if python2 or python3 has been installed
def _get_py_major(rctx, env_path, interpreter_path):
interpreter = "{}/{}".format(env_path, interpreter_path)
result = rctx.execute([rctx.path(interpreter), "--version"])
result = rctx.execute([rctx.path(interpreter), "--version"], timeout=EXECUTE_TIMEOUT)
output = result.stdout if result.stdout else result.stderr
return int(output.replace("Python ", "").partition(".")[0])

Expand Down
4 changes: 2 additions & 2 deletions example/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ http_archive(
#)

RULES_CONDA_NAME = "rules_conda"
RULES_CONDA_TAG = "0.0.1"
RULES_CONDA_SHA = "f5c5e6be86ddc28ef2ed9163878f5a073defc5d79b82e60570f502549c9ef602"
RULES_CONDA_TAG = "0.0.2"
RULES_CONDA_SHA = "3258a44335f10a8ecffd983a5caf5f5c37b92ea191bfe743bb85280ef864cfd9"
RULES_CONDA_REPO = "spietras"
RULES_CONDA_ARCHIVE = "zip"
RULES_CONDA_URL = "https://github.com/{repo}/{name}/releases/download/{tag}/{name}-{tag}.{archive}".format(repo=RULES_CONDA_REPO, name=RULES_CONDA_NAME, tag=RULES_CONDA_TAG, archive=RULES_CONDA_ARCHIVE)
Expand Down
3 changes: 3 additions & 0 deletions utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ PYTHON_EXT_MAP = {
"Linux": ""
}

EXECUTE_TIMEOUT = 1800


def get_os(rctx):
os_family = rctx.os.name.lower()
if "windows" in os_family:
Expand Down

0 comments on commit 35dd105

Please sign in to comment.