-
Notifications
You must be signed in to change notification settings - Fork 11
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
Expose Python interpreter in a platform-independent way #31
Comments
I don't have a definitive answer, just some guesses to try. The colon needs to be the place in the path that has the BUILD file. Going with that, I would try If above doesn't work, you can try to make the python interpreter available as a filegroup: in
This could be accomplished by patching the file template in If none of these work, sorry about that. If something does work, we can incorporate it into |
I think @GabrielDougherty is almost correct, use Here is my local WORKSPACE pip_install(
requirements = "//:requirements.txt",
name = "ext_deps",
python_interpreter_target = "@conda_env//:conda_env/bin/python"
)
http_archive(
name = "rules_conda",
sha256 = "c5ad3a077bddff381790d64dd9cc1516b8133c1d695eb3eff4fed04a39dc4522",
url = "https://github.com/spietras/rules_conda/releases/download/0.0.6/rules_conda-0.0.6.zip"
)
load("@rules_conda//:defs.bzl", "conda_create", "load_conda", "register_toolchain")
load_conda(
version = "4.10.3",
quiet = False, # use True to hide conda output
)
conda_create(
name = "conda_env",
timeout = 600, # each execute action can take up to 600 seconds
clean = False, # use True if you want to clean conda cache (less space taken, but slower subsequent builds)
environment = "@//:conda_environment.yml", # label pointing to environment.yml file
quiet = False, # use True to hide conda output
)
register_toolchain(
py3_env = "conda_env",
) |
Thanks everyone! @yibum you are right! That worked! It turns out I had a fundamental misunderstanding of how labels really work. Labels are always relative to a package root and doesn't need to be in the same directory as a package - a subdirectory (and not subpackage) is fine. SO explains it nicely - the Bazel documentation also explains it but very tersely in the |
So yes, as @GabrielDougherty and @yibum already stated, if you are on Linux (or Mac, idk, I'm too poor) and your environment is named Making it work on all platforms would require making a symlink in the environment repository that will be called the same everywhere and point to different files on different platforms. However, symlinks are the last resort as they are not so friendly on Windows. Or |
I will convert this issue to be more about discussing the need to expose the interpreter in a platform-independent way. |
Thanks! I'm glad this turned into something useful rather than just fixing my silly build issues.
|
Sorry in advance for the meta-discussion. @spietras Do you prefer to discuss over issues? Or GitHub "discussions"? Or perhaps a gitter.im room? |
There is also And the last possibility is symlinking. I hope it's not the only one working, but I'm afraid it is.
If it's about something that should potentially change or be added then it's fine to discuss it in issues. If it's only a question about "how to do something" or "help, it doesn't work, but I think I am the one doing something wrong" then the Discussions tab is better for that. This one is for sure about something to change or add so we can stick here. |
I made a WORKSPACE (source repo here) and tried some things that did not work: ### this does not work (try #1):
filegroup(
name = "python_interpreter",
srcs = ["@py3_env//:py3_env/bin/python","@py3_env//:py3_env/python.exe"]
)
python_configure(
name = "local_config_python",
python_interpreter_target = ":python_interpreter",
)
### This does not work (try #2):
python_configure(
name = "local_config_python",
python_interpreter_target = select({
"@bazel_tools//src/conditions:windows": "@py3_env//:py3_env/python.exe",
"//conditions:default": "@py3_env//:py3_env/bin/python",
}),
)
### This does not work (try #3):
load("@//:interpreter.bzl", "interpreter")
interpreter("py3_env")
python_configure(
name = "local_config_python",
python_interpreter_target = "@://py3_env_interpreter",
)
### This works but is not platform-independent:
python_configure(
name = "local_config_python",
python_interpreter_target = "@py3_env//:py3_env/bin/python",
) try
try
Try
Basically I could only use a filegroup in a BUILD file instead of WORKSPACE file. And using
And a bifurcation of windows/non-windows BUILD rules, then one could use select() to switch the dependent rules for any targets. That would require a significant amount of redesign/implementation time on their end ( |
Context
I'm trying to use rules_conda with pybind11_bazel in Hermetic Python mode. This is necessary because pybind11 requires extension modules to be built for the correct Python version.
pybind11_bazel supplies a
python_configure
rule that takes an attrpython_interpreter_target
that's a of type Label:Problem
There does not seem to be a way to pass the Python interpreter created by rules_conda's environment to
python_configure
.My configuration
In
WORKSPACE
:Which generates a
external/conda_test_env/BUILD
file containing:On the file system, the Python interpreter is located at:
$(bazel info output_base)/external/conda_test_env/conda_test_env/bin/python
.Things I tried:
In WORKSPACE:
This doesn't work because it complains that
bin
is not a package: it requires aBUILD
file which makes sense. Changing.../bin/python
to/.../bin:python
returns a similar error.Manually adding a
BUILD
file to thebin
directory now causes a problem forpy_runtime
, which contains the line:interpreter = "conda_test_env/bin/python"
But adding the colon also fails, because apparently it must be a target name and not a label?
Any ideas?
The text was updated successfully, but these errors were encountered: