Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
oxidase committed Jul 3, 2024
1 parent ef2ca6c commit e75add5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
17 changes: 16 additions & 1 deletion examples/workspace/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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 = "../..",
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions python/poetry_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion python/private/poetry_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
Expand Down
14 changes: 8 additions & 6 deletions python/private/poetry_parse.bzl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e75add5

Please sign in to comment.