diff --git a/examples/workspace/WORKSPACE b/examples/workspace/WORKSPACE index 35ff15a..4454d69 100644 --- a/examples/workspace/WORKSPACE +++ b/examples/workspace/WORKSPACE @@ -1,3 +1,18 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "rules_python", + sha256 = "4912ced70dc1a2a8e4b86cec233b192ca053e82bc72d877b98e126156e8f228d", + strip_prefix = "rules_python-0.32.2", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.32.2/rules_python-0.32.2.tar.gz", +) + +load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") + +py_repositories() + +python_register_toolchains("black_mamba", "3.8") + local_repository( name = "rules_ophiuchus", path = "../..", @@ -6,7 +21,7 @@ local_repository( load("@rules_ophiuchus//python:poetry_parse.bzl", "poetry_parse") load("@rules_ophiuchus//python:repositories.bzl", install_poetry_dependencies = "install_dependencies") -install_poetry_dependencies() +install_poetry_dependencies("black_mamba", "3.8") poetry_parse( name = "poetry", diff --git a/python/poetry_deps.bzl b/python/poetry_deps.bzl index c731491..d7b86cd 100644 --- a/python/poetry_deps.bzl +++ b/python/poetry_deps.bzl @@ -61,6 +61,7 @@ def _package_impl(ctx): install_inputs = poetry_deps_info.files # Declare package output directory + print("python_version", python_version) output = ctx.actions.declare_directory("{}/{}/{}".format(python_version, runtime_tag, ctx.label.name)) # Collect installation tool arguments diff --git a/python/private/poetry_deps.bzl b/python/private/poetry_deps.bzl index f05d934..ea0fdeb 100644 --- a/python/private/poetry_deps.bzl +++ b/python/private/poetry_deps.bzl @@ -30,7 +30,9 @@ def _collect_version(parts): return ".".join(version) def _get_python_version(interpreter): - parts = interpreter.split("_") + print(interpreter) + parts = interpreter.replace(".", "_").split("_") + print(parts) for index in range(len(parts)): if parts[index].endswith("python3"): return "3." + _collect_version(parts[index + 1:]) diff --git a/python/private/poetry_parse.bzl b/python/private/poetry_parse.bzl index 1a4286f..7187681 100644 --- a/python/private/poetry_parse.bzl +++ b/python/private/poetry_parse.bzl @@ -1,3 +1,5 @@ +#load("@rules_python//:") + def dfs_cycles(graph): # Detect pip dependency cycles u->...->v...->w->v and remove edges w->v # Graph DFS with path tracking @@ -175,12 +177,12 @@ print(json.dumps(json.dumps(dict( return "{}" def _poetry_parse_impl(rctx): - print(rctx.attr._python_host) interpter = rctx.path(rctx.attr._python_host) - command = "import tomllib; print('{0}', 1); print(tomllib.load(open('{0}', 'rb')))".format(rctx.path(rctx.attr.lock)) - print(command) - exec_result = rctx.execute([interpter, "-c", command], quiet = False) - print(exec_result) + print("!!!", interpter) + # command = "import tomllib; print('{0}', 1); print(tomllib.load(open('{0}', 'rb')))".format(rctx.path(rctx.attr.lock)) + # print(command) + # exec_result = rctx.execute([interpter, "-c", command], quiet = False) + # print(exec_result) header = "# Autogenerated file _poetry_parse_impl at rules_ophiuchus/python/private/poetry_parse.bzl:175" rules_repository = str(rctx.path(rctx.attr._self)).split("/")[-4] @@ -207,7 +209,7 @@ poetry_parse = repository_rule( ), "_python_host": attr.label( allow_single_file = True, - default = "@python_3_12_host//:bin/python3", + default = "@python_xxx_host//:bin/python3", ), "_self": attr.label( allow_single_file = True, diff --git a/python/repositories.bzl b/python/repositories.bzl index 06d6444..e080561 100644 --- a/python/repositories.bzl +++ b/python/repositories.bzl @@ -16,6 +16,7 @@ _INTERNAL_DEPS = [ def _poetry_deps_repo_impl(ctx): poetry_version = "1.8.3" + # TODO: switch to # Intentionally use a host default interpreter as the repository only used in host tooling targets # This may lead to inconsistency if the repository will be used with a different toolchain python = ctx.which("python.exe" if "win" in ctx.os.name else "python3") @@ -55,7 +56,7 @@ poetry_deps_repo = repository_rule( }, ) -def install_dependencies(auth_patterns = {}, netrc = ""): +def install_dependencies(toolchain_prefix, python_version, auth_patterns = {}, netrc = ""): prefix = "rules_ophiuchus_" for (name, url, sha256, patches) in _INTERNAL_DEPS: