-
Notifications
You must be signed in to change notification settings - Fork 543
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
py_common API #1647
Comments
cc @rickeylev
As such I marked this as P4, but will upgrade it to P2 once Starlarkification is done. |
@comius is there a tracking issue for porting the python rules to starlark? |
@comius @rickeylev friendly ping. Is there a tracking issue for the port to starlark? |
Sorry, didn't see this.
No, I don't think there's a GitHub issue tracking it, yet. I'd create one
now but am on vacation for a bit. Feel free to create one and assign it to
me, though.
Could you tell more about the problem you're trying to solve, and features
you want? Internally, we have 3-5+ cases that could be described as "create
a drop in replacement for py library", but each has some small differences
that need different "plugin" points. So I'm curious to know which part of
rule behavior your logic needs to intercept/customize/keep/drop
…On Mon, Jul 4, 2022, 10:21 AM UebelAndre ***@***.***> wrote:
@comius <https://github.com/comius> @rickeylev
<https://github.com/rickeylev> friendly ping. Is there a tracking issue
for the port to starlark?
—
Reply to this email directly, view it on GitHub
<#1647>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIEXQ6SZVUZOCCUFVSAFYLTVSMMSFANCNFSM5WSSU56Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I think the case that would be most impactful to me is being able to take my cc_binary-like rule and update it to provide an interface to python targets I have without needing to make a tree of macros as some of the attributes are hard to manage when select is used for some attributes. I'd come across the desire to do this a couple of times before writing this issue. In most cases I have a web of macros that could easily be condensed to a single rule. @rickeylev would you be able to enumerate the cases you're aware of? |
fyi, i created bazelbuild/bazel#15897 as a tracking issue for the starlark rewrite |
A quick brain dump of some known points of customization:
|
From Phillip Shrader over slack, the sort of customization they do at Aurora:
|
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team ( |
Cc @rickeylev this is still desired but maybe the issue can be moved to rules_puthon? Now that Bazel 7 is out and we can use the starlark rules there? |
@rickeylev do you know if this would be something that's easy to do? I still find myself wanting to make custom rules that build python binaries. Having an interface for that would be fantastic |
@rickeylev would it be acceptable to have an experimental flag that gates the use of some rules_python/python/private/common/py_executable.bzl Lines 140 to 156 in 084b877
This would cover my primary use for The only changes to |
@aignas do you have any thoughts here? |
This is to some degree a dupe of my #1860; interested in whatever the outcome here is. |
I would be willing to help drive some MVP but I'm concerned about potentially wasting time without prior design sign-off from the maintainers. |
Playaing devil's advocate here - why would we have to support this API when Aside from that, I am personally not super familiar with that part of the code, so cannot comment on implications or the maintenance burden in the long run. The request in general looks reasonable, but I would love to not expose anything that is not needed and the IMHO using |
If
Do you know who would have this context and could you ping them on this issue? Again, I ultimately don't care what form the implementation takes as long as the result is some publicly accessible API for creating python binaries in custom rules (and is available within the span of a month or two). |
I'm +1 on creating some sort of py_common API. It might be easier to discuss the API of it given some more concrete use cases.
I think it's supposed to be part of Bazel 8? Not sure on it wrt Bazel 7.
Semantics shouldn't be exposed. It's purely a mechanism to make it somewhat easier for Google to internally patch the code. It's also not a very stable API.
This signature is pretty internal, so exposing it as-is would be a bad idea. Exposing something without the semantics, is_test, and inherited_environment args seems pretty reasonable, though. For reference:
re: API considerations: The main consideration I have is: I don't want otherwise internal refactorings or non-breaking feature additions to be constrained because of a lower-level of API access. Some examples being:
What this loosely translates to is: exposing If there aren't any modifications of the existing attributes/rule-args desired, then exposing something like If there are modifications to the existing rule-args, then, well, that might be a bit more messy, but I'm thinking a builder-pattern esq dict-of-args might work OK. If you look around |
I would be happy to try to factor out an interface so consumers of periareon/rules_pytest@main...py_common The mock interface I was playing with looks like py_exec_info = py_common.create_executable(
ctx = ctx,
toolchain = py_toolchain,
main = ctx.file._main,
legacy_create_init = False,
deps = [pytest_toolchain.pytest] + ctx.attr.deps,
is_test = True,
) where the function signature might look something like def py_common_create_executable(
ctx,
toolchain,
main,
legacy_create_init,
deps,
is_test,
):
"""Create a python executable
Args:
ctx (ctx): The current rule's context object
toolchain (py_toolchain): The python toolchain
main (File): The source file to use as the entry point.
legacy_create_init (bool): Whether to implicitly create empty `__init__.py` files/
deps (list): A list of python dependencies.
is_test (bool): Indicates if the executable is a test executable.
Returns:
struct: A struct containiging:
- executable: The executable created.
- runfiles: All associated runfiles for the executable.
""" Would you say this is in the ballpark of possibilities? What changes would you make? I think if we can figure out the interface then the internals can change quickly and without impacting users. |
…#2251) This add some builders "classes" to make constructing PyInfo, depsets, and runfiles a bit cleaner. Previously, building such objects required creating multiple local variables for each arg/attribute of the object (e.g. list_of_files and list_of_depsets for building a depset). Keeping track of all the variables was verbose and tedious. To make it easier, encapsulate that bookkeeping in some objects. Accumulating parts is now much easier: builders have an `add()` method that looks at the input and stores it in the appropriate place. This builders will be exposed to users in an upcoming PR to make building and merging PyInfo objects easier. Work towards #1647
Small update in this area: We have a design for exposing analysis-time APIs. #2252 is the first installment of this to add a merge_py_infos() function. The loading-phase side of things isn't addressed yet, though. i.e. how to define a rule with necessary attributes (toolchains, fragments, implicit attributes, exec groups -- all the stuff that The basic idea I'm thinking for this is a function that returns a mutable dict of the args that would be passed to So, something like:
|
This adds a public API for rules (i.e. analysis-phase code) to use code from rules_python. The main motivation for this is so that users can propagate PyInfo without having to know all the fields of PyInfo and implement the merging logic. With upcoming PRs adding additional fields to PyInfo, this becomes much more important. The way the API is exposed is through a target. There are three reasons for this: 1. It avoids loading phase costs when the implementation of the API functions change. Within Google, this makes changes to rules_python much cheaper and easier to submit and revert. This also allows us to worry less about the loading-phase impact of our code. 2. Because a target can have dependencies, it allows us to hide some details from users. For example, if we want a flag to affect behavior, we can add it to the API target's attributes; users don't have to add it to their rule's attributes 3. By having the API take the user's `ctx` as an argument, it allows us to capture it and use it as part of future API calls (this isn't used now, but gives us flexibility in the future). Work towards #1647
Description of the feature request:
Similar to cc_common is there a
py_common
available?What underlying problem are you trying to solve with this feature?
I would like to have some rules which generate additional actions but would otherwise be interchangeable with a py_library. I've done similar things before using the
cc_common
API but cannot find one for python.Which operating system are you running Bazel on?
Any
What is the output of
bazel info release
?release 5.1.1
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD
?No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: