Skip to content

Add multiple C-API version infrastructure and C-API v1.1.0a.1#71

Open
jbreue16 wants to merge 3 commits intomasterfrom
feature/CAPIversioning
Open

Add multiple C-API version infrastructure and C-API v1.1.0a.1#71
jbreue16 wants to merge 3 commits intomasterfrom
feature/CAPIversioning

Conversation

@jbreue16
Copy link
Copy Markdown
Contributor

@jbreue16 jbreue16 commented Mar 20, 2026

This PR adds infrastructure to implement support for multiple C-API versions and v1.1.0a1
The str lookup for the version number should be changed to the type @schmoelder suggested to make comparisons (>, < =) work
to be continued by @AntoniaBerger

  • Add a test
  • Developer guide

@AntoniaBerger
Copy link
Copy Markdown

AntoniaBerger commented Mar 23, 2026

@jbreue16 Is this the pull request you worked on Friday where you added the new C-API versioning to the cpp site? It’s cadet/CADET-Core#366.

_fields_ = _setup_api(_signatures_)


class CADETAPI_V1_0_0(ctypes.Structure):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If I recall correctly, the idea is to call the _set_api function with a string instead of the dictionary of signatures. Then, within _set_api, compare which string is greater.
What’s the benefit of doing it this way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes exactly, but not using a string but this other type that Jo mentioned which supports comparisons of PEP440 version numbers. The benefit is that we can use this to successively add functions introduced in later (minor or pre-release) versions instead of repeating the whole list

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.

from packaging.version import Version

latest = "5.1.0"

current = Version("5.2.0a_1")

if current > Version("5.1.0"):
    print("Something that was implemented in 5.2.0")

class CADETAPI_V1_0_0(ctypes.Structure):
"""Mimic cdtAPIv1.0.0 struct of CADET C-API in ctypes."""
_fields_ = _setup_api("1.0.0")
# class CADETAPI_V1_0_0(ctypes.Structure):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I dont see a difference here?

self._cadet_capi_version = cdtGetLatestCAPIVersion().decode('utf-8')

# Check which C-API is provided by CADET (given the current install path)
#current suppurted versions are: 1.0.0 and 1.1.0_a1
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

supported

if version == Version("1.0.0"):
signatures = dict(CADET_API_V1_SIGNATURES.signatures_1_0_0)

elif version >= Version("1.1.0"):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

v1.1.0a1 is smaller than v1.1.0

fields = []

signatures = {}
if version == Version("1.0.0"):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we can put a > 1.0.0 && < 2.0.0 here and then not set signatures = dict(CADET_API_V1_SIGNATURES.signatures_1_0_0) for the other cases

Also, we could add a last case with < 1.0.0 || > 1.1.0a1 that raises an exception? @schmoelder

@AntoniaBerger
Copy link
Copy Markdown

AntoniaBerger commented Mar 27, 2026

This would be my suggestions to implement the versioning and timeout in cadet_dll.py.

Key points:

  • Create a dictionary _VERSION_SIGNATURES outside of classes that depends on the version.
  • Add a new attribute _version to c-api classes. The _setup_api() method uses the corresponding _VERSION_SIGNATURES based on the _version.
  • The dll_runner attempts to create the latest c-api version. If unavailable on the cpp site, it defaults to version 1.0.0.

@AntoniaBerger AntoniaBerger force-pushed the feature/CAPIversioning branch from 0bd1ad7 to 59130ee Compare March 30, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants