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

Use uv to manage Python dependencies, add Ubuntu 24.04 CI test. #5047

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Dec 3, 2024

WiP. Try to modernize the way we set up our Python environment.

@fruffy fruffy added the infrastructure Topics related to code style and build and test infrastructure. label Dec 3, 2024
@jafingerhut
Copy link
Contributor

Out of curiosity, when you say modernize, do you perhaps mean accepting the perhaps-unpleasant change in pip3 that prevents (or very strongly discourages) one from installing Python packages in system-wide directories? Perhaps considering using a Python virtual environment?

@fruffy
Copy link
Collaborator Author

fruffy commented Dec 3, 2024

Out of curiosity, when you say modernize, do you perhaps mean accepting the perhaps-unpleasant change in pip3 that prevents (or very strongly discourages) one from installing Python packages in system-wide directories? Perhaps considering using a Python virtual environment?

Yes. We might have to go with the times here because the workarounds are quite aggressive/invasive.

I am exploring using poetry + virtualenv. If I work the kinks out you should be able to set up the entire Python environment in few commands:

sudo apt-get install -y python3-poetry python3-venv
cd p4c
poetry install
poetry shell

sudo applications can be run using sudo -E env PATH="$PATH" python3

@jafingerhut
Copy link
Contributor

jafingerhut commented Dec 3, 2024

FYI, my install-p4dev-v8.sh script here: https://github.com/jafingerhut/p4-guide/blob/master/bin/install-p4dev-v8.sh

can run as a normal user, with liberal sudo commands sprinkled throughout when needed, that start from unmodified Ubuntu 20.04, 22.04, or 24.04 system and install gRPC, Thrift, PI, BMv2, p4c, ptf, and mininet, all working together at least enough for the p4lang/tutorials repo exercises to work, and it uses a single Python venv for all Python packages installed.

I doubt that exactly what it does is what you need for this work, but just wanted to point it out as a working example of using a venv for all these tools together.

I believe I also needed LD_LIBRARY_PATH=$LD_LIBRARY_PATH in addition to PATH=$PATH from some sudo commands, perhaps ones like make check run in p4c/build.

Oh, and sometimes I found that instead of a command like sudo PATH=$PATH ... mn, where mn was installed in the Python venv, the best working alternative I found so far is sudo PATH=$PATH ... which mn``.

@fruffy
Copy link
Collaborator Author

fruffy commented Dec 3, 2024

FYI, my install-p4dev-v8.sh script here: https://github.com/jafingerhut/p4-guide/blob/master/bin/install-p4dev-v8.sh

can run as a normal user, with liberal sudo commands sprinkled throughout when needed, that start from unmodified Ubuntu 20.04, 22.04, or 24.04 system and install gRPC, Thrift, PI, BMv2, p4c, ptf, and mininet, all working together at least enough for the p4lang/tutorials repo exercises to work, and it uses a single Python venv for all Python packages installed.

I doubt that exactly what it does is what you need for this work, but just wanted to point it out as a working example of using a venv for all these tools together.

I believe I also needed LD_LIBRARY_PATH=$LD_LIBRARY_PATH in addition to PATH=$PATH from some sudo commands, perhaps ones like make check run in p4c/build.

Yes, I am aware of these and have recommended it to students I work with! But for the sake of the compiler installation we can stay be much simpler. Nonetheless, the changes here should definitely integrate with your scripts. I'll explore further.

@fruffy fruffy force-pushed the fruffy/ci branch 6 times, most recently from bca3a83 to cefdc44 Compare December 3, 2024 20:51
@fruffy fruffy added run-ubuntu18 Use this tag to trigger a Ubuntu-18 CI run. run-validation Use this tag to trigger a Validation CI run. run-sanitizer Use this tag to run a Clang+Sanitzers CI run. run-static Use this tag to trigger static build CI run. labels Dec 16, 2024
@fruffy fruffy force-pushed the fruffy/ci branch 7 times, most recently from ac75baf to eceef54 Compare December 17, 2024 08:03
@fruffy
Copy link
Collaborator Author

fruffy commented Dec 17, 2024

@jafingerhut Poetry works really well for managing Python dependencies. It was not difficult at all to set this up for all our distributions. All you need to do is call poetry shell in the p4c folder and you are working the correct Python environment.

Poetry also exposes a bunch of small issues we had hidden in the environment. For example, we are relying on the external p4runtime Python packages instead of the local p4runtime version from Github for testing.

One thing: It looks Poetry is not supported well Ubuntu18.04. This might be a good opportunity to finally deprecate this version.

@fruffy fruffy force-pushed the fruffy/ci branch 7 times, most recently from eb1ef3d to 1c1268d Compare December 22, 2024 20:41
@fruffy fruffy force-pushed the fruffy/ci branch 6 times, most recently from 6f47c5f to d75e137 Compare April 4, 2025 11:33
@fruffy fruffy added the p4tc Topics related to the P4-TC back end. On PRs, also triggers p4tc CI tests to run. label Apr 4, 2025
@fruffy fruffy force-pushed the fruffy/ci branch 3 times, most recently from 257e094 to 99f3b3e Compare April 4, 2025 16:20

sudo apt-get install -y python3-poetry python3-venv
poetry install
poetry shell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is my understanding correct that uv is a poetry replacement, and if we use uv, there is no need to install poetry at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I am trying out uv as an alternative and it is pretty neat for dependency management so far.

@fruffy fruffy force-pushed the fruffy/ci branch 4 times, most recently from daacc39 to f53547b Compare April 5, 2025 10:05
fruffy added 3 commits April 5, 2025 13:23
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
@fruffy
Copy link
Collaborator Author

fruffy commented Apr 7, 2025

@vbnogueira Trying to refactor the Python setup for TC STF I am seeing timeouts. Do you know possible reasons for that? Could be a simple fix.

@fruffy fruffy changed the title CI installation refactoring. Use uv to manage Python dependencies, add Ubuntu 24.04 CI test. Apr 7, 2025
@vbnogueira
Copy link
Contributor

@vbnogueira Trying to refactor the Python setup for TC STF I am seeing timeouts. Do you know possible reasons for that? Could be a simple fix.

I tested it out and I believe the VM is not getting started because the runner is not finding the virtme-run executable. It was expecting to find it under backends/tc/runtime/virtme-ng/bin/, but there is a change that seems to skip that part of the installation process [1].
I wasn't able to figure out a fix yet because today unfortunately was a complex day, but will do tomorrow.
Probably just need to figure a sane way to change where it looks for virtme-run

[1] https://github.com/p4lang/p4c/pull/5047/files#diff-76f06548e16be4f20ba423b3768e29bfca82a8ecd274407c02b37b3b5816f0c8L233

@fruffy
Copy link
Collaborator Author

fruffy commented Apr 8, 2025

@vbnogueira Trying to refactor the Python setup for TC STF I am seeing timeouts. Do you know possible reasons for that? Could be a simple fix.

I tested it out and I believe the VM is not getting started because the runner is not finding the virtme-run executable. It was expecting to find it under backends/tc/runtime/virtme-ng/bin/, but there is a change that seems to skip that part of the installation process [1]. I wasn't able to figure out a fix yet because today unfortunately was a complex day, but will do tomorrow. Probably just need to figure a sane way to change where it looks for virtme-run

[1] https://github.com/p4lang/p4c/pull/5047/files#diff-76f06548e16be4f20ba423b3768e29bfca82a8ecd274407c02b37b3b5816f0c8L233

Thanks, that already helps me. I can likely fix this.

@@ -0,0 +1 @@
3.12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is adding this .python-version intentional? What uses it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this picks the default Python version for this particular project. It's optional, I might remove it once I clean up these particular files.

@fruffy fruffy force-pushed the fruffy/ci branch 2 times, most recently from 4280b4c to c17124b Compare April 8, 2025 14:38
Signed-off-by: fruffy <fruffy@nyu.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Topics related to code style and build and test infrastructure. p4tc Topics related to the P4-TC back end. On PRs, also triggers p4tc CI tests to run. run-sanitizer Use this tag to run a Clang+Sanitzers CI run. run-static Use this tag to trigger static build CI run. run-ubuntu18 Use this tag to trigger a Ubuntu-18 CI run. run-validation Use this tag to trigger a Validation CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants