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

Add Python 3.13 Support #2080

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

Conversation

ni-jfitzger
Copy link
Collaborator

  • This contribution adheres to CONTRIBUTING.md.
  • I've updated CHANGELOG.md if applicable.
  • I've added tests applicable for this pull request

What does this Pull Request accomplish?

  1. Adds official Python 3.13 support to nimi-python through testing.
    The version of Python used by readthedocs for documentataion generation remains unchanged at 3.11. I prefer to be intentional about changes to the generation of documentation.

  2. Update grpcio, grpcio-tools, protobuf deps for Python 3.13 compatibility and regenerate .pb2 files.

grpcio-tools compatibility for version 1.67.0 (The earliest version witha a 3.13 wheel)

  • grpcio >= grpcio-tools version
  • protobuf >=4.21.6?
    • Not so sure about this. I think it may need to be bumped. The generated pb2 files seem to require protobuf 5.27.2.

List issues fixed by this Pull Request below, if any.

What testing has been done?

PR Checks

@codecov-commenter
Copy link

codecov-commenter commented Feb 5, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.45%. Comparing base (dd57eae) to head (409fd5d).

❌ Your project status has failed because the head coverage (84.45%) is below the target coverage (85.00%). You can increase the head coverage or adjust the target coverage.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

❗ There is a different number of reports uploaded between BASE (dd57eae) and HEAD (409fd5d). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (dd57eae) HEAD (409fd5d)
nidigitalsystemtests 1 0
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2080      +/-   ##
==========================================
- Coverage   91.33%   84.45%   -6.89%     
==========================================
  Files          66       61       -5     
  Lines       16274    14310    -1964     
==========================================
- Hits        14864    12085    -2779     
- Misses       1410     2225     +815     
Flag Coverage Δ
codegenunittests 84.95% <ø> (ø)
nidcpowersystemtests 85.35% <ø> (-9.21%) ⬇️
nidcpowerunittests 89.53% <ø> (ø)
nidigitalsystemtests ?
nidigitalunittests 68.45% <ø> (ø)
nidmmsystemtests 92.72% <ø> (ø)
nifakeunittests 87.24% <ø> (ø)
nifgensystemtests 85.30% <ø> (-9.56%) ⬇️
nimodinstsystemtests 73.85% <ø> (ø)
nimodinstunittests 94.20% <ø> (ø)
niscopesystemtests 84.94% <ø> (-8.00%) ⬇️
niscopeunittests 43.20% <ø> (ø)
nisesystemtests 91.50% <ø> (ø)
niswitchsystemtests 71.26% <ø> (-10.78%) ⬇️
nitclksystemtests 94.87% <ø> (ø)
nitclkunittests 98.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 20 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd57eae...409fd5d. Read the comment docs.

@@ -46,7 +46,7 @@ setup(
extras_require={
'grpc': [
'grpcio>=1.59.0,<2.0',
'protobuf>=4.21.6,<5.0'
'protobuf>=4.21.6'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seems like it needs to be updated to 5.27.2. System Tests are randomly failing on imports when we install old protobuf versions. I'm puzzled how the system tests managed to pass in my original PR.

build_test: pytest
build_test: coverage
build_test: mako
build_test: hacking
build_test: pep8-naming
codegen: mako
codegen: packaging
codegen: grpcio-tools == 1.59.0 # First version to support Python 3.12
codegen: grpcio-tools == 1.67.0 # First version to support Python 3.13
Copy link
Contributor

Choose a reason for hiding this comment

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

Using grpcio-tools 1.67.0 all the time breaks compatibility with grpcio <= 1.67.0 and will likely force users to update protobuf.

The technique we used for nidaqmx-python is to generate code using the oldest compatible Python and oldest compatible grpcio-tools, check the generated code into version control, then test against newer Python and grpcio versions.

Copy link
Contributor

Choose a reason for hiding this comment

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

oldest compatible grpcio-tools

clarification: I mean the grpcio-tools corresponding to the oldest compatible grpcio. The package doesn't actually depend on grpcio-tools, but it includes files generated by grpcio-tools, and those require the corresponding grpcio version or newer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What a pain. I'd rather not be stuck using an old Python version for non-test steps. That's likely to accumulate tech debt.

Why should we go out of our way to avoid an update to protobuf and grpcio if the new versions are still compatible with the files generated by the old version of grpcio-tools?

Copy link
Contributor

Choose a reason for hiding this comment

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

What a pain. I'd rather not be stuck using an old Python version for non-test steps. That's likely to accumulate tech debt.

Do the nimi-python build/codegen scripts need features or tools that are not available in Python 3.9?

It looks like you last updated the build/codegen scripts to use Python 3.8+ syntax: #2043

I would try it myself and see, if nimi-python used mainstream Python tooling such as Poetry, but I don't want to bother setting up WSL, GNU make, etc. Last time I tried that, I ran into conflicts between pyenv on Linux and pyenv-win on Windows.

Why should we go out of our way to avoid an update to protobuf and grpcio if the new versions are still compatible with the files generated by the old version of grpcio-tools?

I have been avoiding this for the packages I maintain because they don't need any new protobuf/grpcio features, so it seems like updating the version constraints doesn't provide any user value.

It seems weird to say "Python 3.9 users, you have to upgrade to grpcio 1.67 or later because that's the first version that supports Python 3.13, which you are not using, but which we use in our build pipeline."

However, there are unpatched security vulnerabilities in older versions of these packages, so maybe it's fine to start requiring newer versions. Users who pin/lock their dependencies to use older versions of protobuf/grpcio can continue to use older versions of NI packages as well.

I guess the biggest concern is that nimi-python, nidaqmx-python, and measurement-plugin-python are still compatible with each other:

  • Each of these packages contains a copy of session_pb2.py. The serialized descriptors in these files must be identical, or users will get errors when importing more than one copy. I just tried this with your branch and the nidaqmx-python master branch and I didn't get an error, so I think it's still fine.
  • measurement-plugin-python currently requires protobuf = "^4.21", so existing versions will be incompatible with the updated nimi-python. But I suppose that pip, Poetry, etc. should backtrack and install the old nimi-python in this scenario.

Cc: @mshafer-NI

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do the nimi-python build/codegen scripts need features or tools that are not available in Python 3.9?

No, we just historically run all steps on the newest Python and run a limited set of steps on the older versions.
Until this PR, we ran all of the steps on Python 3.12, so we could continue to do that and make no changes to pb2 files and no changes to gRPC deps apart from editing/removing the protobuf upper bound. It just feels like tech debt.

However, there are unpatched security vulnerabilities in older versions of these packages, so maybe it's fine to start requiring newer versions. Users who pin/lock their dependencies to use older versions of protobuf/grpcio can continue to use older versions of NI packages as well.

Sounds like a solid reason to upgrade.

Each of these packages contains a copy of session_pb2.py. The serialized descriptors in these files must be identical, or users will get errors when importing more than one copy. I just tried this with your branch and the nidaqmx-python master branch and I didn't get an error, so I think it's still fine.

You have my attention, now. This seems like a strong reason to stick with our current version of grpcio-tools, even if our tests pass and you didn't get an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Python 3.13 support and loosen protobuf version constraint
3 participants