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 py_wheel_push rule and automatic versioning capability for wheels #451

Closed
wants to merge 4 commits into from

Conversation

mvukov
Copy link

@mvukov mvukov commented Apr 9, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

  • Does not include precompiled binaries, eg. .par files. See CONTRIBUTING.md for info
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

At the moment a wheel version can only be entered manually. There is no rule at the moment for pushing wheels to repositories.

What is the new behavior?

This PR adds capability to do automatic versioning/stamping as e.g.:

py_wheel(
    name = "my_wheel",
    distribution = "my_wheel",
    version = "{MY_WHEEL_VERSION}",
    deps = [":my_lib"],
)

where MY_WHEEL_VERSION can be calculated via workspace status by using --workspace_status_command included through the use of .bazelrc. For instance, we can calculate MY_WHEEL_VERSION using some git info. This is handy for automating pushes of wheels on CI.

The second feature this PR introduces is a new py_wheel_push rule that internally uses twine. This enables pushing wheels to private wheel repositories.

Does this PR introduce a breaking change?

  • Yes
  • No

The new py_wheel outputs a wheel named <target_name>.whl and a version file <target_name>_version.txt. The old/current rule outputs the wheel with (already) compliant name. In principle, the version is only relevant when pushing wheels and the new rule for pushing wheels uses the version file to assemble the final compliant wheel file name.

Other information

Docs/testing are still missing, but would like first we agree on the approach.

@google-cla
Copy link

google-cla bot commented Apr 9, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Apr 9, 2021
@google-cla
Copy link

google-cla bot commented Apr 9, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Apr 9, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Apr 9, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

Copy link
Collaborator

@pstradomski pstradomski left a comment

Choose a reason for hiding this comment

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

Can we split the versioning change from the upload one?

Regarding approach: wouldn't it be much simpler to just use https://docs.bazel.build/versions/master/be/make-variables.html support? Then you'd just need to call ctx.expand_make_variables on ctx.attr.version

progress_message = "Versioning wheel",
)

wheel_file = ctx.actions.declare_file(ctx.label.name + ".whl")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this generating a wrong filename though, without all the platform and version information?

Copy link
Author

@mvukov mvukov Apr 12, 2021

Choose a reason for hiding this comment

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

I think if I make a wheel, then my intention would be to push it to a repo. At least this is my current use-case. In this light, name of a wheel file that py_wheel outputs is less relevant IMO. py_wheel_push assembles a correct file name before pushing a wheel. But I may be missing some other important use-cases. I am open to discuss this further.

@mvukov
Copy link
Author

mvukov commented Apr 12, 2021

Regarding approach: wouldn't it be much simpler to just use https://docs.bazel.build/versions/master/be/make-variables.html support? Then you'd just need to call ctx.expand_make_variables on ctx.attr.version

What I have in mind is the following. Let's say that CI is set up to push a wheel to a private repo on a tag. I want to use that git tag as a version for a wheel -- let's assume for simplicity the git tag is conformant according to PEP440. After doing some research, I found that only way to inject this info to Bazel is via a workspace status script. Now, the contents of ctx.info_file and ctx.version_file cannot be used in a Starlark script -- please correct me if I am wrong. That's why I made wheelversioner.py that figures out a version and dumps that info to a file.

Please paste here a small snippet with make variables, in case you have a clear idea in mind. Thanks in advance.

I am not sure how to split the PR, the versioning PR would not be standalone without the new py_wheel_push rule... WDYT?

@pstradomski
Copy link
Collaborator

pstradomski commented Apr 12, 2021 via email

@pstradomski
Copy link
Collaborator

pstradomski commented Apr 12, 2021 via email

@pstradomski
Copy link
Collaborator

pstradomski commented Apr 12, 2021 via email

@mvukov
Copy link
Author

mvukov commented Apr 13, 2021

Btw your PR already populates a provider with the desired version number,
so you can just as well populate TemplateVariableInfo with that desired
version number.

In WheelInfo I have version_file field, which routes the file with version generated in py_wheel rule using wheelversioner.py. wheelpusher.py then reads this file to get the version and assembles correct file name for the wheel.

Unless I am mistaken, Bazel context doesn't provide functionality to read data from files. If I would be able to read a file using ctx, then I could assign it to an output variable or use TemplateVariableInfo.

Thanks for the examples. https://github.com/JulianSchmid/example-bazel-add-git-hash/blob/master/bake_git_hash.bzl dumps git info to a file, similar to how I dump wheel version to a file.

The bottom line is, as I see it, py_wheel info needs to declare the wheel file and return it via a provider such that py_wheel_push can consume it. To declare the wheel file I need to know it's file name. The file name depends on the version which I cannot fetch from a file when the script is processed, since it could depend ctx.info_file and ctx.version_file. So, py_wheel sets a "dummy" name <target_name>.whl in py_wheel. py_wheel_push, wheelpusher.py in fact, is in charge to assemble correct file name for the wheel before pushing it to a repo.

@pstradomski
Copy link
Collaborator

pstradomski commented Apr 13, 2021 via email

@mvukov
Copy link
Author

mvukov commented Apr 13, 2021

How about the following: if the user specifies version = "FOO" we immediately output correct wheel file name from py_wheel. On the other hand, if the user gives version = "{FOO}", py_wheel sets the wheel name <target_name>.whl. py_wheel_push in that case would always compute the correct file name before pushing to a repo. WDYT?

@pstradomski
Copy link
Collaborator

pstradomski commented Apr 14, 2021 via email

@mvukov
Copy link
Author

mvukov commented Apr 15, 2021

@googlebot I signed it!

@google-cla
Copy link

google-cla bot commented Apr 15, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@franklouwers
Copy link

@googlebot we signed it

@github-actions
Copy link

This Pull Request has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!

@github-actions github-actions bot added the Can Close? Will close in 30 days if there is no new activity label Dec 31, 2021
@github-actions
Copy link

This PR was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

@github-actions github-actions bot closed this Jan 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Can Close? Will close in 30 days if there is no new activity cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants