Skip to content
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

Merged
merged 1 commit into from
Oct 31, 2022

Conversation

jheidbrink
Copy link
Contributor

@jheidbrink jheidbrink commented Oct 25, 2022

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:

sudo apt install python3-venv && cd $MAGMA_ROOT && bazel run //dev_tools:python_env ~/python_ide_env

Now configure the IDE to use the Python interpreter /home/vscode/python_ide_env/bin/python3 (VS Code + Devcontainer) or sftp://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.

@jheidbrink jheidbrink requested a review from a team October 25, 2022 15:11
@jheidbrink jheidbrink requested a review from a team as a code owner October 25, 2022 15:11
@pull-request-size pull-request-size bot added the size/L Denotes a Pull Request that changes 100-499 lines. label Oct 25, 2022
@github-actions
Copy link
Contributor

Thanks for opening a PR! 💯

A couple initial guidelines

Howto

  • Reviews. The "Reviewers" listed for this PR are the Magma maintainers who will shepherd it.
  • Checks. All required CI checks must pass before merge.
  • Merge. Once approved and passing CI checks, use the ready2merge label to indicate the maintainers can merge your PR.

More info

Please take a moment to read through the Magma project's

If this is your first Magma PR, also consider reading

@github-actions github-actions bot added component: agw Access gateway-related issue component: orc8r Orchestrator-related issue labels Oct 25, 2022
lte/protos/BUILD.bazel Outdated Show resolved Hide resolved
lte/protos/oai/BUILD.bazel Outdated Show resolved Hide resolved
orc8r/protos/BUILD.bazel Outdated Show resolved Hide resolved
@jheidbrink jheidbrink added the bazel changes for the Bazelification effort label Oct 25, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 25, 2022

feg-workflow

    2 files  203 suites   39s ⏱️
374 tests 374 ✔️ 0 💤 0
388 runs  388 ✔️ 0 💤 0

Results for commit 5ec32fa.

♻️ This comment has been updated with latest results.

@github-actions github-actions bot removed the component: orc8r Orchestrator-related issue label Oct 25, 2022
@@ -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
Copy link
Contributor Author

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

Copy link
Contributor

@LKreutzer LKreutzer Oct 31, 2022

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.

@github-actions
Copy link
Contributor

dp-workflow

14 tests   14 ✔️  2m 10s ⏱️
  1 suites    0 💤
  1 files      0

Results for commit 5ec32fa.

@github-actions
Copy link
Contributor

agw-workflow

615 tests   611 ✔️  4m 41s ⏱️
    2 suites      4 💤
    2 files        0

Results for commit 5ec32fa.

@nstng
Copy link
Contributor

nstng commented Oct 28, 2022

Findings:

  • in general: works fast and nice!
  • we could add the python deps that we build our self, i.e., from bazel/external, e.g., ryu, bcc, aioh2, ...
  • some generated proto libs are missing, e.g., dp/protos, feg/protos
  • would it be better to have a glob target for the proto libs?
  • I can not navigate to netifaces (e.g., from lte/gateway/python/magma/pipelined/ifaces.py)
  • where should we document the setup?

@jheidbrink
Copy link
Contributor Author

would it be better to have a glob target for the proto libs?

I opted for explicitly specifying all the existing targets for two reasons:

  • We have some targets in //te/protos that reference .proto files from /orc8r/protos. Just sourcing all protos from the lte folder does not do the trick. In contrast the existing targets already get it right.
  • By using a glob, we would have to specify the united dependencies of all .proto files. The existing targets already correctly specify their dependencies, so by using those we don't have to declare the dependencies twice.

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.

@jheidbrink
Copy link
Contributor Author

I can not navigate to netifaces (e.g., from lte/gateway/python/magma/pipelined/ifaces.py)

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 make buildenv neither.

@sebathomas
Copy link
Contributor

I can not navigate to netifaces (e.g., from lte/gateway/python/magma/pipelined/ifaces.py)

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.

@jheidbrink
Copy link
Contributor Author

Yes, it seems IntelliJ generates a stub Python file. On my system the path is ~/.cache/JetBrains/IntelliJIdea2022.1/python_stubs/287614887/netifaces.py. It seem VS Code doesn't do that.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2022

Oops! Looks like you failed the PR Check DCO. Be sure to sign all your commits.

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`
Copy link
Contributor Author

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


Copy link
Contributor Author

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.

@jheidbrink
Copy link
Contributor Author

we could add the python deps that we build our self, i.e., from bazel/external, e.g., ryu, bcc, aioh2, ...

some generated proto libs are missing, e.g., dp/protos, feg/protos

Added protos and external Python deps (the latter in a hacky way unfortunately).

where should we document the setup?

I'll update the VS Code section and the IntelliJ section in the Wiki once this gets merged.

Copy link
Contributor

@LKreutzer LKreutzer left a 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
Copy link
Contributor

@LKreutzer LKreutzer Oct 31, 2022

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.

Signed-off-by: Jan Heidbrink <jan.heidbrink@tngtech.com>
@jheidbrink jheidbrink enabled auto-merge (squash) October 31, 2022 13:12
@jheidbrink jheidbrink merged commit 85b9025 into magma:master Oct 31, 2022
lucasgonze pushed a commit to lucasgonze/magma that referenced this pull request Feb 29, 2024
Signed-off-by: Jan Heidbrink <jan.heidbrink@tngtech.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bazel changes for the Bazelification effort component: agw Access gateway-related issue size/L Denotes a Pull Request that changes 100-499 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IDEs can navigate generated code without make
5 participants