-
Notifications
You must be signed in to change notification settings - Fork 18
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
Setup suggestions for VSCode #110
Comments
Hey @scottanderson42, I can see 3 options.
I usually use the Shared virtual environment also to avoid creating tons of virtual environments in my CI/CD pipeline, but let me know if that doesn't work for you, so, we can think about a better way to switch the virtual environment in a simpler way. |
Well, that's the thing: we're starting with separate virtual environments, one per project, to avoid problems with incompatibility when using libraries like numpy and pytorch. Some of the AI models we use can have very particular version requirements and they don't play well together. |
makes sense, and depending on the number of projects you have, switching the virtual environment in the VSCOde select interpreter might be not so productive, let me do some research about it, and see if there are some options to activate the virtual environment based on the folder, I'll let you know, sounds good? |
Sounds great, appreciate it! |
cool, in the meantime you can switch the virtual environment using the select interpreter menu, Pylance will stop complaining about references. |
Hey @scottanderson42, after some research, I didn't find a way to make VSCode identify the virtual environment by folder, someone posted a question on the python VSCode plugin repo microsoft/vscode-python#9673 and we can't change the interpreter programmatically, well, we can change the However, I did some tests using VSCode workspaces using the same example workspaces we were using yesterday, and in this way VSCode can easily switch the virtual environment based on the project. there is a discussion opened microsoft/vscode-python#21204, that could solve permanently this issue in the future.
{
"folders": [
{
"name": "root",
"path": "."
},
{
"name": "apps / test-app",
"path": "apps/test-app"
},
{
"name": "libs / test-one",
"path": "libs/test-one"
},
{
"name": "libs / test-two",
"path": "libs/test-two"
}
],
"settings": {}
} And for each Python project:
{
"python.defaultInterpreterPath": "./.venv/bin/python",
} In this way, VSCode can use the correct virtual environment, What do you think? Note: I can handle those files inside the |
I tried it out, thanks for working on this.
If you do go this route, I'd volunteer to write a plugin to manage |
Hey @scottanderson42 regarding the testing command, can you check that your terminal doesn't have any Python virtual environment activated? Because sometimes when you select the Python interpreter in the VSCode and open a terminal it activates in the terminal automatically, and if it is a different virtual environment then Regarding the We can discuss more about it, I'm happy to help! |
The wrong
This won't work for shared |
Idea: Hybrid Project StructureRandom idea I had on a walk this morning: for repos with individual .venvs, also maintain the central .venv at the root of the workspace. I'm not sure this is better than fighting the local Benefits over just individual .venvs:
Benefits over just a single .venv:
Cons:
Alternative to the above idea: "tracked tree-shaking"In this idea, don't create the individual .venvs, but keep |
Hey @scottanderson42, thanks for thinking about it, well, I use this approach in my projects, of course, there are some limitations related to version conflicts, but it is the best approach in my point of view because you can use it easily in VSCode, it is also faster to install in the CI/CD pipeline. There is an Nx generator to convert the individual npx nx generate @nxlv/python:migrate-to-shared-venv As you described, there will be a
Example. npx nx run test-app:add --name pendulum This command is gonna add the Could you play a little bit with this feature and let me know if that fits your use case? Have a nice weekend |
For some reason I thought the shared root venv removed the pyproject.toml files for all of the subprojects. Is that not the case then? |
Hey @scottanderson42, no, it's not, it only maintains a pyproject in the root and keeps all in sync, all the projects have their own pyproject and they can have different packages as dependencies The only limitation is the versions needs to be the same. |
Hi @lucasvieirasilva, my apologies for being confused about how the root venv configuration worked. Figures you were already ahead of me there. 😄 I gave it a try by converting my test workspace. The conversion went fine, the root .venv is there and activated, but the tests are failing.
|
Hey @scottanderson42, no worries, did you activate the root venv in your terminal before running the command? |
Yes, whoops, I formatted the code wrong. As you can see now though the |
Interesting, can I see your root pyproject? |
|
Hmm, looks correct, can check if your root venv has the test_app in the lib folder? |
Sure.
|
Well, it looks right, all the local dependencies are there, should work, did you remove the shell code that you added to activate the venv before running the test in the test target inside the project.json? |
Yes, I did. Everything looks like it should work. |
Yes, the venv is ok, activated in the terminal, the target command is also ok, I don't know hehe, I need to reproduce that, sorry man, I'm not at home now, I get back Monday, I feel that is something very silly |
No worries, it's not a blocker and we'll figure it out. Enjoy your weekend. |
Thanks man, you too! |
Hey @scottanderson42 I could reproduce the issue here, it is something really silly. In the However, the But when we move to the root virtual environment pytest (from external sources) could not identity as a virtual environment, even with the virtual environment activated. I output the
['/Users/lucasvieira/Projects/issues/nx-plugins/issue-sam/packages/test-app', '/usr/local/bin', '/usr/local/Cellar/[email protected]/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/usr/local/Cellar/[email protected]/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9', '/usr/local/Cellar/[email protected]/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/Users/lucasvieira/Library/Python/3.9/lib/python/site-packages', '/usr/local/lib/python3.9/site-packages'] It only has the Command: Code: import sys
print(sys.path) Output: ['', '/Users/lucasvieira/.pyenv/versions/3.9.5/lib/python39.zip', '/Users/lucasvieira/.pyenv/versions/3.9.5/lib/python3.9', '/Users/lucasvieira/.pyenv/versions/3.9.5/lib/python3.9/lib-dynload', '/Users/lucasvieira/Projects/issues/nx-plugins/issue-sam/.venv/lib/python3.9/site-packages', '/Users/lucasvieira/Projects/issues/nx-plugins/issue-sam/packages/app1', '/Users/lucasvieira/Projects/issues/nx-plugins/issue-sam/packages/lib1', '/Users/lucasvieira/Projects/issues/nx-plugins/issue-sam/packages/test-app', '/Users/lucasvieira/Projects/issues/nx-plugins/issue-sam/packages/test-one', '/Users/lucasvieira/Projects/issues/nx-plugins/issue-sam/packages/test-two'] You can see that all local paths are present, So, I thought that needs to be something related to the Then, I installed the pytest dependencies in the root level poetry add pytest pytest-cov pytest-html Then everything works fine. Could you try adding those If yes, I guess I need to change the |
That fixes it, yes! Thanks for the sleuthing. Does it make sense to instead copy all of the |
Hey @scottanderson42, yes it does, and I guess the changes are also related to the issues you opened last week #111, Currently, by default, the project generator does not add the |
Documentation issue
Is there a specific documentation page you are reporting?
We're looking for suggestions on setting up VSCode with the
pyproject.toml
-per-project approach. Since there isn't a single.venv
for the workspace Pylance doesn't seem to quite know what to do with the individual libraries and their imports, as you can see here:Pylance can't find the import, and there are no linting errors for the types on the functions.
The text was updated successfully, but these errors were encountered: