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

Pydantic 2.x compatibility #106

Merged
merged 9 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ Release Notes

The full list of releases can be found in the GitHub repository's `releases page <https://github.com/fsoubelet/PyhDToolkit/releases>`_.

Version 1.4.0
-------------

.. toctree::
:maxdepth: 2

releases/v1.4.0

Version 1.3.2
-------------

.. toctree::
:maxdepth: 2

releases/v1.3.2

Version 1.3.1
-------------

Expand Down
14 changes: 14 additions & 0 deletions docs/releases/v1.3.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. _release_1.4.0:

1.4.0
-----

Release `1.4.0`` is a small compatibility release with `pydantic v2.x`.

Maintenance
~~~~~~~~~~~

* The version requirement on `pydantic` has been updated to `>=2.0`.
* Carious places in the `PyhDToolkit` codebase have been updated to be compatible with `pydantic v2.x`.

See `v1.4.0 release notes on GitHub <https://github.com/fsoubelet/PyhDToolkit/releases/tag/1.4.0>`_ and the `full changes since v1.3.2 <https://github.com/fsoubelet/PyhDToolkit/compare/1.3.2...1.4.0>`_.
13 changes: 13 additions & 0 deletions docs/releases/v1.4.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _release_1.3.1:

1.3.2
-----

Release `1.3.2` is a small compatibility release.

Maintenance
~~~~~~~~~~~

* The version requirement on `pydantic` has been constrained to `>=1.0,<2.0` to guarantee code bases compatibility.

See `v1.3.2 release notes on GitHub <https://github.com/fsoubelet/PyhDToolkit/releases/tag/1.3.2>`_ and the `full changes since v1.3.1 <https://github.com/fsoubelet/PyhDToolkit/compare/1.3.1...1.3.2>`_.
8 changes: 4 additions & 4 deletions pyhdtoolkit/models/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class BeamParameters(BaseModel):
One can find a usage example in the :ref:`beam enveloppe demo <demo-beam-enveloppe>`.
"""

pc_GeV: Optional[float] # Beam momentum [GeV]
pc_GeV: Optional[float] = None # Beam momentum [GeV]
E_0_GeV: Optional[float] = 0.9382720813 # Particle rest mass energy [GeV], defaults to that of a proton
charge: Optional[float] = 1 # Particle charge in [e], defaults to that of a proton
en_x_m: Optional[float] # Horizontal normalized emittance [m]
en_y_m: Optional[float] # Vertical normalized emittance [m]
deltap_p: Optional[float] # Momentum deviation
en_x_m: Optional[float] = None # Horizontal normalized emittance [m]
en_y_m: Optional[float] = None # Vertical normalized emittance [m]
deltap_p: Optional[float] = None # Momentum deviation

@property
def B_rho_Tm(self) -> float:
Expand Down
4 changes: 3 additions & 1 deletion pyhdtoolkit/models/htc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Union

from pendulum import DateTime
from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict


class BaseSummary(BaseModel):
Expand Down Expand Up @@ -47,6 +47,8 @@ class HTCTaskSummary(BaseModel):

Class to encompass and validate a specific job's line in the ``condor_q`` output.
"""
# This is so pydantic accepts pendulum.DateTime as a validated type
model_config = ConfigDict(arbitrary_types_allowed=True)

owner: str
batch_name: int
Expand Down
14 changes: 7 additions & 7 deletions pyhdtoolkit/utils/htc_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ def _make_cluster_table(owner_name: str, cluster: ClusterSummary) -> Table:
for i, source in enumerate(["query", "user", "cluster"]):
table.add_row(
"Query" if i == 0 else ("All Users" if i == 2 else owner_name),
str(cluster.dict()[source]["jobs"]),
str(cluster.dict()[source]["completed"]),
str(cluster.dict()[source]["running"]),
str(cluster.dict()[source]["idle"]),
str(cluster.dict()[source]["held"]),
str(cluster.dict()[source]["suspended"]),
str(cluster.dict()[source]["removed"]),
str(cluster.model_dump()[source]["jobs"]),
str(cluster.model_dump()[source]["completed"]),
str(cluster.model_dump()[source]["running"]),
str(cluster.model_dump()[source]["idle"]),
str(cluster.model_dump()[source]["held"]),
str(cluster.model_dump()[source]["suspended"]),
str(cluster.model_dump()[source]["removed"]),
)
return table

Expand Down
2 changes: 1 addition & 1 deletion pyhdtoolkit/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "1.3.2"
VERSION = "1.4.0"


def version_info() -> str:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Physics",
Expand All @@ -61,7 +62,7 @@ dependencies = [
"loguru < 1.0",
"cpymad >= 1.9",
"rich >= 12.0",
"pydantic >= 1.0,<2.0",
"pydantic >= 2.0",
"pendulum >= 2.0",
"optics-functions >= 0.1",
]
Expand Down
Binary file modified tests/inputs/utils/correct_cluster_summary.pkl
Binary file not shown.
Binary file modified tests/inputs/utils/correct_user_tasks.pkl
Binary file not shown.