Globs in extra paths #2712
Replies: 22 comments 3 replies
-
Thanks for the request @itsdani, we will review the request and look at what it would take to get this functionality |
Beta Was this translation helpful? Give feedback.
-
Copying my info here from microsoft/pyright#1684 (comment)
|
Beta Was this translation helpful? Give feedback.
-
This is pretty critical for supporting monorepos with multiple python services. Support for this feature would also resolve many of the open issues related to My teams currently address this challenge with a bash script that is run whenever a new python service or library is added. #!/bin/bash
shopt -s dotglob
shopt -s nullglob
VENV_PATHS_ARR=(*/*/.venv/lib/*/site-packages/)
VENV_PATHS=$(printf ",\"%s\"" "${VENV_PATHS_ARR[@]}")
EXTRA_PATHS=${VENV_PATHS:1}
jq ".\"python.analysis.extraPaths\" = [${EXTRA_PATHS}]" .vscode/settings.json > .vscode/settings.tmp
mv .vscode/settings.tmp .vscode/settings.json |
Beta Was this translation helpful? Give feedback.
-
Can you clarify what you mean? I wouldn't expect anyone to use extraPaths to add paths that point to an interpreter. |
Beta Was this translation helpful? Give feedback.
-
We found If there's a better approach than With
Using
|
Beta Was this translation helpful? Give feedback.
-
You may be interested in https://github.com/microsoft/pyright/blob/main/docs/configuration.md#execution-environment-options, though I don't know to what extent it will have the behavior you're seeking. Execution environments are what @erictraut's team uses to manage their monorepo. |
Beta Was this translation helpful? Give feedback.
-
Execution environments are indeed helpful, in that it resolves the issue of resolving imports from outside the project path. This does require switching from Unfortunately, since it doesn't allow setting So I guess, if we can't get |
Beta Was this translation helpful? Give feedback.
-
The execution environment model is not suited to have separate interpreters, unfortunately. There used to be support, but it was broken as it was never intended to work. Multi-root runs separate analyzers, so they are able to have separate interpreters. Execution environments are within an analyzer, and can only have one. We need to come up with a spec to better reconcile the idea of execution environments and multiroot into something that can capture how people are using. I think details on how your monorepo is laid out and what you're expecting would be helpful for that (though, this issue was about globbing, not that redesign 🙂) |
Beta Was this translation helpful? Give feedback.
-
@jakebailey I'd be happy to support that effort in any way; we can move the interpreters/monorepo discussion. Here's an example of what I'm currently testing wtih. https://github.com/dermidgen/python-monorepo I yield the thread back to globbing 😁 |
Beta Was this translation helpful? Give feedback.
-
any updates? |
Beta Was this translation helpful? Give feedback.
-
Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
-
Are there any updates on this issue? It's quite painful to use VSCode with a bazel python repo without this feature |
Beta Was this translation helpful? Give feedback.
-
It would be great to have this feature. |
Beta Was this translation helpful? Give feedback.
-
Just keep the begging alive |
Beta Was this translation helpful? Give feedback.
-
Additional begging. |
Beta Was this translation helpful? Give feedback.
-
For those of you who are interested in this feature, it would be useful if you could provide some details about the problem you're trying to solve. That would allow us to consider other potential solutions. There's a good reason why we don't support globs in extraPaths today. The order of extraPaths is significant. This setting defines the specific order in which imports are resolved. This ordering matters, for the same reason that the order of |
Beta Was this translation helpful? Give feedback.
-
My original problem was that when I set up a monorepo project with Bazel, it collects the dependencies of the projects into directories like I suspect that extraPaths was never intended to do this kind of dependency inclusion. Virtual envs would be a better thing to do, but (when I tried doing this) Bazel did its own thing without using venvs. |
Beta Was this translation helpful? Give feedback.
-
For what it's worth, I have exactly the same use case: Bazel has an opinionated way of managing Python dependencies, and the only current solution is to regularly regenerate extraPaths with a shell script. Globbing would be the most obvious way to dynamically declare this list, but I'd be curious to hear alternative suggestions.
Oh, and I'm one of the poor souls stuck using bazel in a polyrepo (not monorepo) scenario, so I think it's best to think of the bazel/globbing and the monorepo discussions as separate but related.
…On Wed, Aug 23, 2023, 01:04 Daniel Segesdi ***@***.***> wrote:
My original problem was that when I set up a monorepo project with Bazel,
it collects the dependencies of the projects into directories like
./dependencies/pip/<package-name>/. So the executables are not in a
single directory, and the list of directories can easily grow/change if
someone adds a new dependency. In this scenario I would not care at all
about the order of the extraPaths entries, because they are all different
packages that should not conflict.
I suspect that extraPaths was never intended to do this kind of dependency
inclusion. Virtual envs would be a better thing to do, but (when I tried
doing this) Bazel did its own thing without using venvs.
—
Reply to this email directly, view it on GitHub
<#2712 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACD4G7EU5GXSIHFVWFZEA3XWW2P5ANCNFSM5WYQKR4A>
.
You are receiving this because you are subscribed to this thread.Message
ID: <microsoft/pylance-release/repo-discussions/2712/comments/6799676@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
One use case where this is useful is for people using ROS1 devel workspaces. ROS1 uses a model of masking workspaces for installation and development, with the primary installation workspace manually installing files to a known location, and the development workspaces linked to those shadowing the installed files via some path magic and link to the package directories directly. Since the development workspace contains multiple packages all at the same level (all code is in It would be useful for this application is the glob in extra paths expanded in place in the list of extra paths, so we could prioritize python packages in the system and installation spaces, but all packages within the glob have arbitrary dependency order. This may all seem somewhat convoluted, but it's the framework this system provides |
Beta Was this translation helpful? Give feedback.
-
This has been added to our backlog. You can track progress at #5364 |
Beta Was this translation helpful? Give feedback.
-
Still an issue. Managed to get a workaround similar to gdippolito's
Instead, I created a py_binary rule that must depend on all external python packages I use like so: py_binary(
name = "vscode_import_generator",
srcs = ["vscode_import_generator.py"],
deps = [
"@pypi//numpy",
...
],
) A bit annoying to have to keep it updated but couldn't find a better way since we can't glob dependencies in Bazel. This is my modified version of the script: https://gist.github.com/gdippolito/72fc9e099d9c0d99ff0d79fac37864f9 |
Beta Was this translation helpful? Give feedback.
-
This discussion seems to be divided into two requests: one for Mono users and the other for Bazel users. We probably need two separate solutions for each group. For Mono repo users, this will probably solve your issue? |
Beta Was this translation helpful? Give feedback.
-
I'm trying to setup a python monorepo build with bazel, and I'm struggling to make pylance recognize the library imports. I have managed to make it work by adding e.g.
<bazel-myproject>/external/<my-pip-dependencies>/pypi__numpy
topython.analysis.extraPaths
, but adding a line for each dependency on every computer we use doesn't seem to be right.My idea/request is that if we could add something like
dependencies/*/
ordependencies/pypi__*/
to the extra paths, it would solve this problem entirely. The expected behavior would be to add every (matching) directory underdependencies/
to the extra paths.Beta Was this translation helpful? Give feedback.
All reactions