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

Update dependencies, update to Pydantic V2 #16

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
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
32 changes: 28 additions & 4 deletions mxcubecore/HardwareObjects/DataPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import gevent
import logging

from os import environ
from enum import Enum, unique

from mxcubecore.BaseHardwareObjects import HardwareObject
Expand Down Expand Up @@ -92,12 +93,35 @@ def init(self):
"""
super(DataPublisher, self).init()

rhost = self.get_property("host", "localhost")
rport = self.get_property("port", 6379)
rdb = self.get_property("db", 11)
rhost = self.get_property(
"host",
environ.get("MXCUBE_REDIS_HOST", "localhost"),
)
rport = self.get_property(
"port",
int(environ.get("MXCUBE_REDIS_PORT", "6379")),
)
username = self.get_property(
"username",
environ.get("MXCUBE_REDIS_USERNAME"),
)
password = self.get_property(
"password",
environ.get("MXCUBE_REDIS_PASSWORD"),
)
rdb = self.get_property(
"db",
int(environ.get("MXCUBE_REDIS_DB", "11")),
)

self._r = redis.Redis(
host=rhost, port=rport, db=rdb, charset="utf-8", decode_responses=True
host=rhost,
port=rport,
username=username,
password=password,
db=rdb,
charset="utf-8",
decode_responses=True,
)

if not self._subsribe_task:
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
Loading