Skip to content

Commit

Permalink
Update dependencies, update to Pydantic V2
Browse files Browse the repository at this point in the history
  • Loading branch information
oldfielj-ansto committed Oct 1, 2024
1 parent 52fa0e2 commit e3699c6
Show file tree
Hide file tree
Showing 23 changed files with 2,271 additions and 1,441 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ coverage.xml
.DS_Store
.vscode/
.python-version

test/HardwareObjectsMockup.xml/
11 changes: 5 additions & 6 deletions mxcubecore/BaseHardwareObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from collections import OrderedDict
import logging
from gevent import event, Timeout
import pydantic
from typing import (
TYPE_CHECKING,
Callable,
Expand All @@ -43,12 +42,12 @@
)
from typing_extensions import Self, Literal

from pydantic.v1 import BaseModel, Field, create_model
from mxcubecore.dispatcher import dispatcher
from mxcubecore.CommandContainer import CommandContainer

if TYPE_CHECKING:
from logging import Logger
from pydantic import BaseModel
from .CommandContainer import CommandObject

__copyright__ = """ Copyright © 2010-2020 by the MXCuBE collaboration """
Expand Down Expand Up @@ -656,11 +655,11 @@ def _get_type_annotations(self) -> None:
# Skipp return typehint
if _n != "return":
self._exports[attr_name].append(_n)
fdict[_n] = (_t, pydantic.Field(alias=_n))
fdict[_n] = (_t, Field(alias=_n))

_models[attr_name] = (
pydantic.create_model(attr_name, **fdict),
pydantic.Field(alias=attr_name),
create_model(attr_name, **fdict),
Field(alias=attr_name),
)

self._pydantic_models[attr_name] = _models[attr_name][0]
Expand All @@ -670,7 +669,7 @@ def _get_type_annotations(self) -> None:
attr_name
].schema_json()

model = pydantic.create_model(self.__class__.__name__, **_models)
model = create_model(self.__class__.__name__, **_models)
self._pydantic_models["all"] = model

def execute_exported_command(self, cmd_name: str, args: Dict[str, Any]) -> Any:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel
from pydantic.v1 import BaseModel
from typing import Optional, Union


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import Field, BaseModel
from pydantic.v1 import Field, BaseModel
from typing import Union, Optional


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import gevent

from typing_extensions import Literal
from pydantic import BaseModel, Field
from pydantic.v1 import BaseModel, Field
from devtools import debug

from mxcubecore import HardwareRepository as HWR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing_extensions import Literal

from pydantic import BaseModel, Field
from pydantic.v1 import BaseModel, Field
from devtools import debug

from mxcubecore.model.common import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import contextlib
import enum
import subprocess
from pydantic import BaseModel, Field
from pydantic.v1 import BaseModel, Field
from devtools import debug

from mxcubecore import HardwareRepository as HWR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing_extensions import Literal

from pydantic import Field
from pydantic.v1 import Field
from devtools import debug

from mxcubecore.model.common import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
import enum

from pydantic import BaseModel, Field
from pydantic.v1 import BaseModel, Field
from devtools import debug

from mxcubecore import HardwareRepository as HWR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing_extensions import Literal

from pydantic import BaseModel, Field
from pydantic.v1 import BaseModel, Field
from devtools import debug

from mxcubecore import HardwareRepository as HWR
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/GenericDiffractometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import enum

from typing import List, Tuple, Union, Dict
from pydantic import BaseModel, Field, ValidationError
from pydantic.v1 import BaseModel, Field, ValidationError

from mxcubecore.HardwareObjects import sample_centring
from mxcubecore.model import queue_model_objects
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/MiniDiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import json

from typing import Union
from pydantic import ValidationError
from pydantic.v1 import ValidationError

from mxcubecore.BaseHardwareObjects import Equipment
from mxcubecore.TaskUtils import task
Expand Down
2 changes: 0 additions & 2 deletions mxcubecore/HardwareObjects/TangoLimaMpegVideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def start_video_stream_process(self, port):
self._video_stream_process = subprocess.Popen(
[
"video-streamer",
"-tu",
self.get_property("tangoname").strip(),
"-hs",
"localhost",
"-p",
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/mockup/BeamlineActionsMockup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing_extensions import Literal

from pydantic import BaseModel, Field
from pydantic.v1 import BaseModel, Field
from mxcubecore.TaskUtils import task
from mxcubecore.CommandContainer import CommandObject
from mxcubecore.HardwareObjects.BeamlineActions import (
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/mockup/DiffractometerMockup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import random
import warnings

from pydantic import ValidationError
from pydantic.v1 import ValidationError

from mxcubecore.HardwareObjects.GenericDiffractometer import (
GenericDiffractometer,
Expand Down
2 changes: 0 additions & 2 deletions mxcubecore/HardwareObjects/mockup/MDCameraMockup.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ def start_video_stream_process(self, size):
self._video_stream_process = subprocess.Popen(
[
"video-streamer",
"-tu",
"test",
"-hs",
"localhost",
"-p",
Expand Down
2 changes: 2 additions & 0 deletions mxcubecore/configuration/ansto/mxcube-web/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ server:
- "http://localhost:3000"
- "ws://localhost:8000"
- "https://mxcube.mx3.beamline.synchrotron.org.au"
- "wss://mxcube.mx3.beamline.synchrotron.org.au"
- "http://mxcube.mx3.beamline.synchrotron.org.au"
- "ws://mxcube.mx3.beamline.synchrotron.org.au"

mxcube:
USE_EXTERNAL_STREAMER: False
Expand Down
4 changes: 2 additions & 2 deletions mxcubecore/configuration/checkxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import xmltodict
import argparse
import pprint
import pydantic
from pydantic.v1 import ValidationError

from colorama import Fore, Back, Style
from mxcubecore.model import configmodel
Expand Down Expand Up @@ -40,7 +40,7 @@ def check_xml(rpath="."):
if config_model:
try:
config_model(**_data_to_validate)
except pydantic.ValidationError as ex:
except ValidationError as ex:
print(f"{Fore.RED}WARNING in: {fpath}")
print(f"{str(ex)}")
print(Style.RESET_ALL)
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/model/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
from typing import Optional, Union
from pydantic import BaseModel, Field
from pydantic.v1 import BaseModel, Field


class CommonCollectionParamters(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/model/configmodel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, Field
from pydantic.v1 import BaseModel, Field


class ExporterNStateConfigModel(BaseModel):
Expand Down
5 changes: 2 additions & 3 deletions mxcubecore/model/procedure_model.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# -*- coding: utf-8 -*-

import pydantic
from pydantic import Field
from pydantic.v1 import BaseModel, Field


class ValidationError(Exception):
pass


class BaseModel(pydantic.BaseModel):
class BaseModel(BaseModel):
def __init__(self, *args, **kwargs):
try:
super(BaseModel, self).__init__(*args, **kwargs)
Expand Down
Loading

0 comments on commit e3699c6

Please sign in to comment.