Skip to content

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

Merged
fruffy merged 1 commit into
mainfrom
fruffy/ci
May 20, 2025
Merged

Use uv to manage Python dependencies, add Ubuntu 24.04 CI test. #5047
fruffy merged 1 commit into
mainfrom
fruffy/ci

Conversation

@fruffy

@fruffy fruffy commented Dec 3, 2024

Copy link
Copy Markdown
Collaborator

This pull request adds a CI test for Ubuntu 24.04 and changes the way Python dependencies are installed. Part of the motivation is related to changes to PEP668 which mandates that, by default, Python dependencies should be externally managed, or local. This PEP takes effect with Ubuntu 24.04

To work around this, we introduce uv for dependency management. With uv, we can install and manage all Python dependency in a virtual environment local to the P4C repository. This also makes dependency management easier for us.

The downside is that we now have to run tests with a uv run prefix to avoid Python dependency problems. Similarly, when using sudo we have to use sudo -E env PATH="$PATH" uv run.

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

Copy link
Copy Markdown
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

fruffy commented Dec 3, 2024

Copy link
Copy Markdown
Collaborator Author

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

jafingerhut commented Dec 3, 2024

Copy link
Copy Markdown
Contributor

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

fruffy commented Dec 3, 2024

Copy link
Copy Markdown
Collaborator Author

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 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

fruffy commented Dec 17, 2024

Copy link
Copy Markdown
Collaborator Author

@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
Comment thread tools/install.sh Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
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 5 times, most recently from f53547b to 29a9bd8 Compare April 5, 2025 11:24
@fruffy

fruffy commented Apr 7, 2025

Copy link
Copy Markdown
Collaborator Author

@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
Copy Markdown
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

fruffy commented Apr 8, 2025

Copy link
Copy Markdown
Collaborator Author

@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
Copy Markdown
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
Copy Markdown
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 commented Apr 20, 2025

Copy link
Copy Markdown
Collaborator Author

@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

I finally found a way to fix the P4-TC tests, by using virtme-ng provided by the Debian repositories. Let me know whether that works for you.

@fruffy

fruffy commented Apr 21, 2025

Copy link
Copy Markdown
Collaborator Author

@jafingerhut The transition to Ubuntu 24.04 is almost completed with this. #5183 is a prerequisite, I will clean up that PR later this afternoon and then it is ready for review.

The Fedora failures are unrelated and happen because of the distro changes.

@vbnogueira

Copy link
Copy Markdown
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

I finally found a way to fix the P4-TC tests, by using virtme-ng provided by the Debian repositories. Let me know whether that works for you.

I think I tried that, but it didn't work at the time (probably because the virtme-ng for the previous ubuntu version was too outdated). Glad to see it works now, makes things easier to setup.

Signed-off-by: fruffy <fruffy@nyu.edu>
Comment thread tools/ci-build.sh
export CC=gcc-9
export CXX=g++-9
else
elif [[ "${DISTRIB_RELEASE}" != "24.04" ]] ; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this check for versions other than 24.04 mean that p4lang-bmv2 is not installed on Ubuntu 24.04 tests, and thus Ubuntu 24.40 CI does not run any tests that pass packets through bmv2?

If so, I guess the long term way to improve that is to create a way to build bmv2 binaries for p4c testing that run on Ubuntu 24.04?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes there is no p4lang-bmv2 for Ubuntu 24.04. We could build BMv2 from scratch, but that adds CI time.

@fruffy

fruffy commented May 18, 2025

Copy link
Copy Markdown
Collaborator Author

@jafingerhut This is ready for review now.

@jafingerhut jafingerhut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

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-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