-
-
Notifications
You must be signed in to change notification settings - Fork 644
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
Allow [python_tool].version
and [python-tool].extra_requirements
to point to python_requirement
targets?
#12449
Comments
It's really a retro-posal. V1 worked this way. |
Wouldn't it be better to just get rid of the distinction between |
And in the future it could point to any binary target that we build from source... |
The distinction is intentional to make it much easier to change the defaults. You can easily the version while not touching the default extra reqs, or vice versa. Updating the default for a list option is clunky, you have to completely override it unless you're only adding/removing elements. |
Yes, but that problem can be eliminated under this proposal. We can have |
…].extra_requirements` (#12597) ### Background Before Pants 2.6, using third-party type stubs was awkward because [we did not yet have dependency inference](https://blog.pantsbuild.org/introducing-pants-2-6/). Instead, you either had to explicitly add the dependency or hijack `[mypy].extra_requirements`. The latter would mean installing the dep more times than it's actually needed. To allow putting type stubs in `[mypy].extra_requirements`, we had to install those deps _both_ in the `mypy.pex` tool PEX, and in the `typechecked_venv.pex`, which is a `VenvPex` where we grab the Python interpreter to point MyPy's `--python-executable` at. This meant installing `[mypy].extra_requirements` twice. ### Solution Instead, `[mypy].extra_requirements` should only be used for what is needed to run MyPy itself, such as MyPy plugins. It should not include type stubs, which should be installed via normal dependencies like in `requirements.txt`. Clearing this up has the benefits of: - bringing conceptual clarity - not installing `[mypy].extra_requirements` twice - facilitating adding a tool lockfile for MyPy ### Awkward bit: MyPy plugins w/ type stubs embedded Some requirements like `django-stubs` both act as a MyPy plugin and include type stubs. In fact, `django-stubs` was the motivating case for the original implementation. Now, you will need to install `django-stubs` and its kin in both `[mypy].extra_requirements` (for the plugin part) and as a normal dependency (for the type stubs). (The duplication of requirement strings could be solved by #12449). This is awkward, but conceptually sound. [ci skip-rust] [ci skip-build-wheels]
[python_tool].version
and [python-tool].extra_requirements
to point to python_requirement_library
targets?[python_tool].version
and [python-tool].extra_requirements
to point to python_requirement
targets?
Note that v2 JVM tools have been using this hybrid approach: you can either use a "coordinate string" or an address to a |
This just bit me for |
A user migrating from poetry pointed out that they would like to be able to leverage the flake eight plug-ins they already have defined with poetry. Right now, they must duplicate the requirement strings. This issue would solve the problem |
Along similar lines: For the code in My goal is to separate the pylint plugins' requirements so they aren't in the python-default resolve any more. I guess this proposal is very similar but goes in the opposite direction: reference a requirement from the python-default resolve in the tool requirements. So, I guess my question about this proposal is, how does using a requirement interact with multiple resolves? |
I had pointed @cognifloyd at this ticket thinging that it was necessary for source plugins. Until I remembered #14320. While the design has some awkward edges, I think source plugins work good enough already. They do not need this ticket at all. |
Another example/use case I posted in Slack: Getting this on 00:57:24.50 [WARN] Pants cannot infer owners for the following imports in the target helloworld/translator/translator_test.py:tests:
* pytest (line: 4)
If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see https://www.pantsbuild.org/v2.15/docs/troubleshooting#import-errors-and-missing-dependencies for common problems. This goes away if I add pytest to my requirements.txt |
What about we go the other direction: Add a target, similar to Maybe call it python_tool_requirements(
tool="pytest",
resolve="my-resolve",
) Or, we add a BUILD symbol that allows referencing metadata in pants.toml. python_requirement(
name="pytest",
requirements=[
pants_toml["pytest"]["version"],
] + pants_toml["pytest"]["extra_requirements"],
resolve="my-resolve",
) |
spinning further on that direction.. oh, I misread pants.toml for pyproject.toml.. Oh, I'll post anyway as I think it's an interesting idea (and the pattern may be applied kind of generically too I believe): # Generates targets as appropriate from a pyproject.toml poetry config
import_poetry_project(
source="pyproject.toml",
dependencies=True,
devDependencies=False,
distribution=True,
...
) |
I think I like that. Although, we often don't want everything from the resolve. You may only directly import n of the requirements from the tool.
we have |
Well, that would be just the I'm not saying this is something we necessarily want to do.. but in case there are multiple aspects of some setup that you want to create targets for, having an "umbrella" target to manage it may make sense to reduce boilerplate and explicit know-how of all the various types involved.. |
+1 for this. A use case we have is that we use dependabot/renovate to manage dependency upgrades, and its really only compatible with a |
I'm +1 on pants.toml referring to other, standard places (rather than the reverse) |
After raising an issue on the slack channel @thejcannon asked me to add my (potential) use case here: I’m trying to set up debugging (for the test and run goals) in VSCode. I’m on an M1 mac with Python 3.9. When I try to run
It seems that pants isn't building debugpy and there isn't a wheel available. This issue might get around that problem. |
Another reason to love this: https://www.pantsbuild.org/docs/reference-flake8#extra_files is superfluous 😄 |
This is addressed in a different way by #18481, which allows a tool to be installed from a user resolve. In fact, the |
A weird thing with our tool support is that you can have the same requirement both to run a tool and as a library imported by your code.
Classic example: Pytest. Right now, you have to be careful to set the pytest version in both your requirements.txt and
[pytest].version
, violating DRY.Instead, this proposal would update
PythonToolBase
to allow either using a raw requirement string or a target address for apython_requirement_library
, so you could do this:The text was updated successfully, but these errors were encountered: