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

allow v2.3 in metadataversion, fallback to any string #344

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/npe2/manifest/_package_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# https://packaging.python.org/specifications/core-metadata/

MetadataVersion = Literal["1.0", "1.1", "1.2", "2.0", "2.1", "2.2"]
MetadataVersion = Literal["1.0", "1.1", "1.2", "2.0", "2.1", "2.2", "2.3"]
_alphanum = "[a-zA-Z0-9]"
PackageName = constr(regex=f"^{_alphanum}[a-zA-Z0-9._-]*{_alphanum}$")

Expand All @@ -30,7 +30,9 @@ class PackageMetadata(BaseModel):
class Config:
extra = Extra.ignore

metadata_version: MetadataVersion = Field(
# allow str as a fallback in case the metata-version specification has been
# updated and we haven't updated the code yet
metadata_version: Union[MetadataVersion, str] = Field(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we provide a validator that checks if this string is a valid version number?

Copy link
Collaborator Author

@tlambert03 tlambert03 Mar 21, 2024

Choose a reason for hiding this comment

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

I assume you mean is it of the general pattern X.Y? You can if you want to, but I'm not sure it matters (and could bring back the future proof problem).

Copy link
Collaborator

Choose a reason for hiding this comment

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

So why we just don't annotate with plain str?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Czaki, you can do whatever you want. with my code above, I tried to indicate that normally this should be MetadataVersion, but yes we allow any string. along with the provided comment it gives the reader a bit more context. If you want to remove all that and make it just str, be my guest

"1.0", description="Version of the file format"
)
name: PackageName = Field( # type: ignore
Expand Down
Loading