Skip to content

Provide current_py_toolchain - #731

Merged
f0rmiga merged 2 commits into
bazel-contrib:mainfrom
jheaff1:current_py_toolchain
Jun 21, 2022
Merged

Provide current_py_toolchain#731
f0rmiga merged 2 commits into
bazel-contrib:mainfrom
jheaff1:current_py_toolchain

Conversation

@jheaff1

@jheaff1 jheaff1 commented Jun 14, 2022

Copy link
Copy Markdown
Contributor

This PR introduces the current_py_toolchain rule, exposing the
PYTHON2 and PYTHON3 "make" variables in bazel rules, analagous to
@bazel_tools//tools/cpp:current_cc_toolchain.

This is useful when building 3rd party libraries which require python via rules_foreign_cc.

See
https://docs.bazel.build/versions/main/be/make-variables.html#custom_variables

PR Checklist

Please check if your PR fulfills the following requirements:

  • 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?

Issue Number: N/A

What is the new behavior?

Bazel rules can refer to the python interpreter via "Make" Variables.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@jheaff1
jheaff1 force-pushed the current_py_toolchain branch 2 times, most recently from 913db56 to 6b4ec43 Compare June 14, 2022 15:51
@jheaff1
jheaff1 marked this pull request as ready for review June 14, 2022 16:39
@jheaff1
jheaff1 force-pushed the current_py_toolchain branch 3 times, most recently from a443073 to e9b8226 Compare June 15, 2022 13:52
@jheaff1

jheaff1 commented Jun 15, 2022

Copy link
Copy Markdown
Contributor Author

CI now passes, may I please ask for a review?

Comment thread python/defs.bzl Outdated
Comment thread python/defs.bzl Outdated
Comment thread python/defs.bzl
@jheaff1
jheaff1 force-pushed the current_py_toolchain branch from 09824e0 to e9b8226 Compare June 16, 2022 10:30
This commit introduces the current_py_toolchain rule, exposing the
PYTHON2 and PYTHON3 "make" variables in bazel rules, analagous to
@bazel_tools//tools/cpp:current_cc_toolchain.

See
https://docs.bazel.build/versions/main/be/make-variables.html#custom_variables
@jheaff1
jheaff1 force-pushed the current_py_toolchain branch from 8beb89d to 94ca634 Compare June 16, 2022 10:33
@jheaff1

jheaff1 commented Jun 16, 2022

Copy link
Copy Markdown
Contributor Author

@f0rmiga Thanks for the review, I have applied your suggested changes

@f0rmiga

f0rmiga commented Jun 21, 2022

Copy link
Copy Markdown
Member

@jheaff1 thanks for addressing my comments!

@f0rmiga
f0rmiga merged commit c49bab3 into bazel-contrib:main Jun 21, 2022
@jheaff1
jheaff1 deleted the current_py_toolchain branch June 22, 2022 06:17
mattem pushed a commit to mattem/rules_python that referenced this pull request Jul 7, 2022
This commit introduces the current_py_toolchain rule, exposing the
PYTHON2 and PYTHON3 "make" variables in bazel rules, analagous to
@bazel_tools//tools/cpp:current_cc_toolchain.

See
https://docs.bazel.build/versions/main/be/make-variables.html#custom_variables

Co-authored-by: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com>
name = "test_current_py_toolchain",
srcs = [],
outs = ["out.txt"],
cmd = "$(PYTHON3) --version > $(location out.txt)",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is there a way to use genrule and a python toolchain in conjunction with pip deps?

@aryeh-looker aryeh-looker Jan 17, 2023

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See the use of entry_point in pip.md

you could use this in a genrule

@jheaff1 jheaff1 Jan 17, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I’m assuming you want to run T he entrypoint of a pip package? If you want to use a pip package as a library, use the requirement macro and setup the PYTHONPATH environment variable to include the location of the pip packages. Eg

”PYTHONPATH=$(location {}”.format(requirement(‘the_pip_package’)

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.

3 participants