Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

remove dataclasses_json #817

Merged
merged 1 commit into from
Jul 25, 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
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ install_requires =
bluesky
pyepics
flask-restful
dataclasses-json
zocalo
ispyb
scanspec
Expand Down
12 changes: 5 additions & 7 deletions src/artemis/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import argparse
import atexit
import threading
from dataclasses import dataclass
from dataclasses import asdict
from queue import Queue
from traceback import format_exception
from typing import Callable, Optional, Tuple

from bluesky import RunEngine
from dataclasses_json import dataclass_json
from flask import Flask, request
from flask_restful import Api, Resource
from pydantic.dataclasses import dataclass

import artemis.log
from artemis.exceptions import WarningException
Expand All @@ -34,7 +34,6 @@ class Command:
parameters: Optional[InternalParameters] = None


@dataclass_json
@dataclass
class StatusAndMessage:
status: str
Expand All @@ -45,7 +44,6 @@ def __init__(self, status: Status, message: str = "") -> None:
self.message = message


@dataclass_json
@dataclass
class ErrorStatusAndMessage(StatusAndMessage):
exception_type: str = ""
Expand Down Expand Up @@ -189,7 +187,7 @@ def put(self, plan_name: str, action: Actions):
status_and_message = self.runner.stop()
# no idea why mypy gives an attribute error here but nowhere else for this
# exact same situation...
return status_and_message.to_dict() # type: ignore
return asdict(status_and_message) # type: ignore


class StopOrStatus(Resource):
Expand All @@ -201,14 +199,14 @@ def put(self, action):
status_and_message = StatusAndMessage(Status.FAILED, f"{action} not understood")
if action == Actions.STOP.value:
status_and_message = self.runner.stop()
return status_and_message.to_dict()
return asdict(status_and_message)

def get(self, **kwargs):
action = kwargs.get("action")
status_and_message = StatusAndMessage(Status.FAILED, f"{action} not understood")
if action == Actions.STATUS.value:
status_and_message = self.runner.current_status
return status_and_message.to_dict()
return asdict(status_and_message)


def create_app(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any

import numpy as np
from dataclasses_json import DataClassJsonMixin
from dodal.devices.detector import TriggerMode
from dodal.parameters.experiment_parameter_base import AbstractExperimentParameterBase
from pydantic import validator
Expand All @@ -18,7 +17,7 @@


@dataclass
class GridScanWithEdgeDetectParams(DataClassJsonMixin, AbstractExperimentParameterBase):
class GridScanWithEdgeDetectParams(AbstractExperimentParameterBase):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Query: RotationScanParams inherits from BaseModel. Do we have a preference on when to do that and when to use pydantic.dataclass? From a google I think maybe BaseModel gives you more? So I would suggest we standardise on them all using BaseModel? This may be a different ticket...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, maybe it's better to use models for all of them, I just changed the ones which were still dataclass because it was easier

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, I'll make an issue

"""
Holder class for the parameters of a grid scan that uses edge detection to detect the grid.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/artemis/system_tests/test_main_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def test_when_blueskyrunner_initiated_and_skip_flag_is_set_then_setup_called_upo
):
runner = BlueskyRunner(MagicMock(), skip_startup_connection=True)
mock_setup.assert_not_called()
runner.start(MagicMock(), MagicMock(), "fast_grid_scan")
runner.start(None, None, "fast_grid_scan")
mock_setup.assert_called_once()


Expand Down