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

DM-45243: Migrate to Pydantic v2 and adopt ruff for linting and formatting #52

Merged
merged 12 commits into from
Jul 17, 2024

Conversation

jonathansick
Copy link
Member

Backwards-incompatible changes

  • Upgrade to Pydantic version 2. With this new Pydantic version, the custom Orcid and Ror types in the DocumentMetadata model are now implemented as functional validators with annotations.

  • Python version compatibility is now Python 3.10 and later.

  • Theme plugins are now required to implement a run_post_build method that post-processes the Lander site build. This method can be a no-op.

New features

  • Lander uses importlib to discover and load plugins, rather than pkg_resources.

Other changes

  • Lander is now linted and formatted with ruff.

This updates the Makefile to match the current SQuaRE template
https://github.com/lsst/templates/blob/main/project_templates/square_pypi_package/example/Makefile

One of the advantages of this template is that it uses uv natively.
- Update ci.yaml workflow to be consistent with the current SQuaRE
  package template
- Update to support Python 3.10 to 3.12.
This is based on the SQuaRE PyPI package template.
This includes code changes to fulfill ruff rules.
This drops the use of pkg_resources in favour of importlib in the
standard library for discovering and loading entrypoint plugins.
Typer doesn't support modern syntax for optional types like Path | None.
To prevent ruff from auto-upgrading the syntax we're using a noqa for
UP007 for now.
With ruff we're encouraged to make run_post_build an abstract method
which requires all plugin implementations to then have an implementation
of the method. I'm not sure this is a good idea or not, but this is
required at the moment.
With Pydantic 2, the custom orcid and ror URL types were difficult to
re-implement. Instead, I'm treating those as regular HttpUrl types and
using functional validators to validate the IDs.

Similarly, the CollapsedWhitespacestr functional validator replaces the
multi-field whitespace validator in the original DocumentMetadata model.
This is done because the UTC time zone is not available in Python 3.10.
@jonathansick jonathansick merged commit af9a2f3 into main Jul 17, 2024
5 checks passed
@jonathansick jonathansick deleted the tickets/DM-45243 branch July 17, 2024 20:14
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.

1 participant