Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for rules_python. #65

Closed
wants to merge 1 commit into from
Closed

Add initial support for rules_python. #65

wants to merge 1 commit into from

Conversation

junyer
Copy link
Contributor

@junyer junyer commented Nov 27, 2023

Fixes #64.

@junyer
Copy link
Contributor Author

junyer commented Nov 27, 2023

Hmm. GitHub won't let me assign @rickeylev as well.

bazel_dep(name = "rules_python", version = "0.27.0")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
use_repo(python, "pythons_hub")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @pythons_hub is an internal detail of rules_python. It's basically just a registry so that it can auto-register the toolchains and make pip integration easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feared as much. Hence why I really wanted you to review. :)

@@ -167,6 +168,23 @@ def _get_python_bin(repository_ctx):
python_bin = _norm_path(python_bin)
return python_bin

if (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way this is trying to work is fundamentally flawed. The core issue is the repository phase can't know what interpreter a target will use, and it can't know the full set of toolchains registered. The @pythons_hub only keeps track of python.toolchain() calls, but that doesn't include any custom user toolchains.

I'm not really sure this will work, either. IIRC, the label isn't a canonical one (one that starts with '@@`, so it won't be able to resolve (you would have to use_repo() the apparent name)

From what I remember, these labels are also host specific. This is because they're just used to drive pip.parse() (which does various repository phase things, so has to have a host-capable interpreter available).

What you really want is to get this information from the toolchain directly. e.g., in the regular rule code, do something like

def _pybindthing_impl(ctx):
   py_lib_path = ctx.toolchains["pything"].lib_path
   ctx.actions.run(...stuff using py_lib_path...)

This should be pretty easy. If you can give a run down of the information needed, we can figure out how to make it available from the toolchains.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh snap. I just realised that I still owe you a reply on bazelbuild/rules_python#824 (comment). :(

@junyer
Copy link
Contributor Author

junyer commented Nov 28, 2023

I'm going to close this PR since it isn't going to fly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

initial support for rules_python
3 participants