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 version module that allows to compare versions in python #678

Merged
merged 3 commits into from
Sep 19, 2024

Conversation

tmadlener
Copy link
Collaborator

@tmadlener tmadlener commented Sep 18, 2024

BEGINRELEASENOTES

  • Add a podio.version module exposing podio::version::Version also in python.
  • Remove the version_as_str method again, since that is handled by Version now.

ENDRELEASENOTES

@tmadlener
Copy link
Collaborator Author

Unless, there are any major concerns here, I would like to merge this later today and make a v01-01 tag tomorrow, once the nightlies have passed.

Copy link
Member

@andresailer andresailer left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@m-fila
Copy link
Contributor

m-fila commented Sep 18, 2024

Reading between the lines the bindings for Version from cppyy had broken comparisons magic methods, right?
Is it because cppyy doesn't handle <=>?

@m-fila
Copy link
Contributor

m-fila commented Sep 18, 2024

Wouldn't it be enough in python to just give a version as a string? And in the client code just use packaging.version.parse which is pretty standard?

@tmadlener
Copy link
Collaborator Author

Reading between the lines the bindings for Version from cppyy had broken comparisons magic methods, right?
Is it because cppyy doesn't handle <=>?

You are correct. I didn't check whether it's actually the <=> that isn't detected or whether it's the fact that we default it.

Wouldn't it be enough in python to just give a version as a string? And in the client code just use packaging.version.parse which is pretty standard?

We could also do that, but I am not sure how many physics users are aware of that ;) (I wasn't until an hour ago)

@m-fila
Copy link
Contributor

m-fila commented Sep 18, 2024

You are correct. I didn't check whether it's actually the <=> that isn't detected or whether it's the fact that we default it.

I think it's just any <=> since cppyy is C++17 😢
Using manually defined comparison operators works fine.
Maybe we could just remove the C++20 version from#if 😭

We could also do that, but I am not sure how many physics users are aware of that ;) (I wasn't until an hour ago)

Fair point. It just feels like a lot of code just to wrap the packaging.version in the end

@@ -1,6 +1,9 @@
#!/usr/bin/env python3
"""Module that facilitates working with the podio::version::Version"""

from functools import total_ordering
from packaging import version
Copy link
Contributor

@m-fila m-fila Sep 18, 2024

Choose a reason for hiding this comment

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

Should packaging also appear in the requirements.txt (and readme?).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed it should. I though it was part of the standard library.

@tmadlener
Copy link
Collaborator Author

One other issue is that cppyy can apparently not deal with aggregate initialization, because simply doing

if ROOT.gInterpreter.LoadFile("podio/podioVersion.h") == 0:  # noqa: E402
    from ROOT import podio  # noqa: E402 # pylint: disable=wrong-import-position

Version = podio.version.Version

v = Version(1, 2, 3)

leads to:

TypeError: none of the 3 overloaded methods succeeded. Full details:
  Version::Version(podio::version::Version&&) =>
    TypeError: takes at most 1 arguments (3 given)
  Version::Version() =>
    TypeError: takes at most 0 arguments (3 given)
  Version::Version(const podio::version::Version&) =>
    TypeError: takes at most 1 arguments (3 given)

In that case, I would rather keep the c++ version unchanged and do a bit more legwork on the python side, even if we effectively just re-wrap packaging.version.Version again.

@m-fila
Copy link
Contributor

m-fila commented Sep 18, 2024

Ouch, okay then 👍
I'm not sure if this isn't an error in ROOT cppyy, I'll ask later

@tmadlener
Copy link
Collaborator Author

I added an alternative implementation where we effectively leverage the c++ class and only add a new parse method as well as a shim for __str__ to get nicer print outputs. In the end the amount of code is pretty similar, considering that now a bunch more tests have to be added for version.parse. Any strong preferences for any of the two implementations?

@m-fila
Copy link
Contributor

m-fila commented Sep 18, 2024

No strong preferences. This version doesn't need the packaging in requirements and readme anymore 😉

@tmadlener
Copy link
Collaborator Author

Dropped the commits with the changes to requirements.txt. I am going with this one. If cppyy starts supporting operator<=> and aggregate initialization, we should be able to pick that up transparently.

@m-fila
Copy link
Contributor

m-fila commented Sep 19, 2024

Aggregation init issue root-project/root#16469

@tmadlener tmadlener merged commit 3e8f634 into AIDASoft:master Sep 19, 2024
18 checks passed
@tmadlener tmadlener deleted the python-version-comparisons branch September 19, 2024 08:35
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.

3 participants