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

Versioning the ASDF tags #3

Open
WilliamJamieson opened this issue Mar 30, 2023 · 0 comments
Open

Versioning the ASDF tags #3

WilliamJamieson opened this issue Mar 30, 2023 · 0 comments

Comments

@WilliamJamieson
Copy link

This is a place to discuss versioning the ASDF tags by asdf-pydantic, and a continuation of asdf-format/asdf#1507 (comment).

As a recap of my suggestion:

  • AsdfPydanticModel should be able to generate its version number (by default) from the version of the library defining the model/extension.
  • Warnings should be issued if the current version number of the extension doesn't match the version number of the object in question, but pydantic still validates the data. (Technically the tags will change and it won't round-trip correctly)
  • This make it intuitive for users to figure out which version of the extension library is needed to read the file, and manual forward porting can take place.

The converter can accommodate this by defining the tag in it registers using <tag>-* instead of using the exact version.

The AsdfPydanticModel can introspect this version automatically using something like:

@property
def _tag_version(self):
    mod = inspect.getmodule(self)
    pack = mod.__name__.split(".")[0]
	return importlib.import_module(pack).__version__

I think an override should be available to override the version number as the user needs.

I would further argue that extension writers should only need to provide a base_uri to the models they construct, rather than the full tag_uri. The specific name attached to the end of the tag can be intuited from the name of the class defined (such as convert the class.__name__ from CamelCase to snake_case), and the version number can be determined as above. Again it might be reasonable to provide an override for the name portion too.

By doing this extension authors can define a class:

class MyBaseModel(AsdfPydanticModel):
    _base_uri = "asdf://my_extension/"

Then inherit all their subsequent extension models from this. This way one only needs to define the base_uri once rather than coping and changing it.

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

No branches or pull requests

1 participant