rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

`pip.parse(python_version=)` should not be mandatory

Open mering opened this issue 1 year ago • 5 comments

🐞 bug report

Affected Rule

Bzlmod pip.parse()

Is this a regression?

Yes, was not a problem in WORKSPACE.

Description

The arg documentation says the following: https://github.com/bazelbuild/rules_python/blob/711186f144af06b431bd416b2d742874de3a2dea/python/private/bzlmod/pip.bzl#L391-L398

It specifically describes If not specified, then the default Python version (as set by the root module or rules_python) will be used. So this attribute should be optional but currently is mandatory.

🔬 Minimal Reproduction

pip.parse() without python_version.

🔥 Exception or Error

ERROR: in tag at <root>/MODULE.bazel:42:10, mandatory attribute python_version isn't being specified

🌍 Your Environment

Operating System:

  
Linux
  

Output of bazel version:

  
2024/01/19 15:28:42 Warning: used fallback version "6.3.2"
Bazelisk version: v1.19.0
INFO: Running bazel wrapper (see //tools/bazel for details), bazel version 6.1.2 will be used instead of system-wide bazel installation.
Build label: 6.1.2
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Apr 18 15:29:54 2023 (1681831794)
Build timestamp: 1681831794
Build timestamp as int: 1681831794
  

Rules_python version:

  
0.27.1
  

Anything else relevant?

mering avatar Jan 19 '24 15:01 mering

Could you explain a little more how having a requirement on this mandatory argument make it more difficult to use rules_python? Are there cases where you cannot do this? Usually requirements.txt files are python version and platform dependent, so I'd be curious to hear out more about your usecase.

aignas avatar Jan 24 '24 13:01 aignas

Could you explain a little more how having a requirement on this mandatory argument make it more difficult to use rules_python? Are there cases where you cannot do this? Usually requirements.txt files are python version and platform dependent, so I'd be curious to hear out more about your usecase.

When you create a module which uses a requirements.txt but is meant to be depended upon by another module, my module doesn't know with which version the dependent module wants to use. So I have to run this for all available Python versions. If I could instead just leave this out and have it determined automatically by the action graph which version is required, it would be much easier to use.

mering avatar Jan 26 '24 15:01 mering

Did you find a solution for this? https://github.com/mvukov/rules_ros2/blob/1e16de8c3797d94b54ea589524fa7be0e45481d9/MODULE.bazel#L34-L67 is a workaround, but I hate it :P

lalten avatar May 21 '24 11:05 lalten

This may be possible once I finish #1837, but it is not in scope, so contributions in a form of PRs are definitely welcome. I would be more than happy to review those.

That said, I am curious of the usecase that you are trying to cover by using all of the Python versions and requirements. Is it for testing that your dependencies work on all python versions or is it something else?

aignas avatar Jun 01 '24 00:06 aignas

I am curious of the usecase that you are trying to cover by using all of the Python versions and requirements. Is it for testing that your dependencies work on all python versions or is it something else?

Isn't this required when you don't know which Python version other modules which depend on your module are using?

Let's say, I develop module X which has pip dependencies. When module A wants to depend on X and uses Python version 3.8, this version needs to be declared in X's pip_parse(). When module B wants to depend on X and uses Python version 3.11, this version also needs to be declared in X's pip_parse(). As a developer of module X I don't know which Python versions the users of my module want to use, so I need to declare all of them at the moment. It would be preferable if I would only need to declare my requirements.txt file and have Bazel figure out the correct Python version to use in module X based on the toolchains used in dependent modules.

mering avatar Jun 01 '24 06:06 mering