-
Notifications
You must be signed in to change notification settings - Fork 592
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
chore(agw): Create Python environment with bazel #14266
Conversation
Thanks for opening a PR! 💯
Howto
More infoPlease take a moment to read through the Magma project's
If this is your first Magma PR, also consider reading
|
263bdb1
to
3a5509e
Compare
d022cd4
to
5ec32fa
Compare
@@ -82,9 +82,9 @@ | |||
"python.terminal.activateEnvironment": true, | |||
"python.analysis.extraPaths": [ | |||
"${containerWorkspaceFolder}/orc8r/gateway/python/", | |||
"${containerWorkspaceFolder}/lte/gateway/python/", | |||
"/home/vscode/build/python/lib/python3.8/site-packages" // has to be in sync with $PYTHON_VENV and $PYTHON_VERSION from .devcontainer/Dockerfile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line was unnecessary - that folder should already be taken into account when the interpreter is set to /home/vscode/build/python/bin/python3.8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the PR description: the path /home/vscode/python_ide_env/bin/python3
did not work for me when building the env in the VM, but it did work when I built it in the devcontainer. I assume it is due to ~/python_ide_env
not being mounted.
Findings:
|
I opted for explicitly specifying all the existing targets for two reasons:
Of course the drawback is that the list doesn't automatically update. I think this is ok given that a change will probably just break a small part of the code navigation at worst. |
I think that's because netifaces is not written in Python and only available as shared object file. I cannot navigate there using the environment created with |
I can navigate there in Intellij but it only shows method interfaces and constants, not implementations. Not sure if VS Code has implemented that feature. |
Yes, it seems IntelliJ generates a stub Python file. On my system the path is |
Oops! Looks like you failed the Howto
♻️ Updated: ✅ The check is passing the PR Check DCO after the last commit. |
@@ -10,7 +10,7 @@ Requirements.txt holds all Python dependencies which are required by Python-base | |||
|
|||
`cd $MAGMA/bazel/external` | |||
|
|||
`pip-compile --generate-hashes --output-file=requirements.txt requirements.in` | |||
`pip-compile --upgrade-package --generate-hashes --output-file=requirements.txt requirements.in` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated but I stumbled upon it while working on this PR. The point is that without this parameter, when a requirements.txt
already exists and the versions satisfy the constraints from requirements.in
, they are not upgraded. With --upgrade-package
, versions in an existing requirements.in are upgraded to the highest versions that satisfy the constraints.
@@ -206,74 +207,4 @@ RUN GOBIN="/usr/bin/" go install -v golang.org/x/tools/gopls@v0.8.3 | |||
#### Update shared library configuration | |||
RUN ldconfig -v | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the removed block, we will use the Python environment built by Bazel. This requires us to build that environment initially - I'll update https://github.com/magma/magma/wiki/Contributing-Code-with-VSCode and https://github.com/magma/magma/wiki/Contributing-Code-with-IntelliJ once this gets merged.
While having to build the Python environment is inconvenient, this reduces the devcontainer download size by 175 MB. Given that not all contributors are working on Python code, that seems to be a good tradeoff.
Added protos and external Python deps (the latter in a hacky way unfortunately).
I'll update the VS Code section and the IntelliJ section in the Wiki once this gets merged. |
d44da39
to
fc6487f
Compare
fc6487f
to
e07bca1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally
@@ -82,9 +82,9 @@ | |||
"python.terminal.activateEnvironment": true, | |||
"python.analysis.extraPaths": [ | |||
"${containerWorkspaceFolder}/orc8r/gateway/python/", | |||
"${containerWorkspaceFolder}/lte/gateway/python/", | |||
"/home/vscode/build/python/lib/python3.8/site-packages" // has to be in sync with $PYTHON_VENV and $PYTHON_VERSION from .devcontainer/Dockerfile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the PR description: the path /home/vscode/python_ide_env/bin/python3
did not work for me when building the env in the VM, but it did work when I built it in the devcontainer. I assume it is due to ~/python_ide_env
not being mounted.
e07bca1
to
d25187a
Compare
Signed-off-by: Jan Heidbrink <jan.heidbrink@tngtech.com>
d25187a
to
c4a3fcb
Compare
Signed-off-by: Jan Heidbrink <jan.heidbrink@tngtech.com>
Summary
Fixes #14036
Uses rules_pyvenv to generate a virtual environment for IDEs. The environment contains PyPI dependencies and compiled Protobuf Python libraries.
Test Plan
In the VM or devcontainer:
Now configure the IDE to use the Python interpreter
/home/vscode/python_ide_env/bin/python3
(VS Code + Devcontainer) orsftp://vagrant@localhost:2222/home/vagrant/python_ide_env/bin/python3
(IntelliJ IDEA Ultimate + magma_dev VM). You might have to restart the IDE for the change to be effective.