Skip to content

Commit

Permalink
small import and annotation fixes to make mypy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
eudoxos committed Oct 6, 2024
1 parent c2d6609 commit d8e8795
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
doc/build
__pycache__
.ipynb_checkpoints

.pytest_cache
5 changes: 2 additions & 3 deletions mupifDB/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import datetime
import sys
import os
import table_structures
import tempfile
import importlib
import re
Expand All @@ -12,7 +11,8 @@
import pydantic
from typing import List,Optional,Literal

from .. import models
from .. import models
from .. import table_structures

from rich import print_json
from rich.pretty import pprint
Expand Down Expand Up @@ -115,7 +115,6 @@ def insertWorkflowHistory(wf: models.Workflow_Model):
@if_granta(granta._getGrantaExecutionRecords)
@pydantic.validate_call
def getExecutionRecords(workflow_id: str|None=None, workflow_version: int|None=None, label: str|None=None, num_limit: int|None=None, status: str|None=None) -> List[models.WorkflowExecution_Model]:
data = []
query = "executions/?noparam"
for n,a in [('num_limit',num_limit),('label',label),('workflow_id',workflow_id),('workflow_version',workflow_version),('status',status)]:
if a is not None: query += f"&{n}={str(a)}"
Expand Down
2 changes: 1 addition & 1 deletion mupifDB/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
log=logging.getLogger('restApi')


import table_structures
from .. import table_structures

client = MongoClient("mongodb://localhost:"+os.environ.get('MUPIFDB_MONGODB_PORT','27017'))
db = client.MuPIF
Expand Down
8 changes: 4 additions & 4 deletions mupifDB/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Parent_Model(pydantic.BaseModel):
id: str

class MongoObj_Model(pydantic.BaseModel):
dbID: Optional[str]=Field(None,alias=AliasChoices('_id','dbID'),serialization_alias='_id')
dbID: Optional[str]=Field(None,alias=AliasChoices('_id','dbID'),serialization_alias='_id') # type: ignore[arg-type]
parent: Optional[Parent_Model]=None

class UseCase_Model(MongoObj_Model):
Expand Down Expand Up @@ -66,10 +66,10 @@ class InputOutputBase_Model(pydantic.BaseModel):
Name: str
Description: Optional[str]=None
Type: str
Type_ID: str = Field(...,alias=AliasChoices('Type_ID','TypeID'))
Type_ID: str = Field(...,alias=AliasChoices('Type_ID','TypeID')) # type: ignore[arg-type]
ValueType: Literal['Vector','Scalar','Tensor','VectorArray']='Scalar'
Units: str
ObjID: Optional[str|List[str]] = Field(None,alias=AliasChoices('ObjID','Obj_ID'))
ObjID: Optional[str|List[str]] = Field(None,alias=AliasChoices('ObjID','Obj_ID')) # type: ignore[arg-type]
@property
def TypeID(self): return self.Type_ID
# @property.setter(self,val): self.Type_ID=val
Expand All @@ -83,7 +83,7 @@ class Output_Model(InputOutputBase_Model):
Outputs: List[Output_Model]
wid: str
Description: str
GridFSID: str = None
GridFSID: Optional[str] = None
UseCase: str
IOCard: IOCard_Model
modulename: str
Expand Down
2 changes: 1 addition & 1 deletion mupifDB/mupifdbRestApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
sys.path.append(os.path.dirname(os.path.abspath(__file__))+"/.")
import mupifDB
from mongoflask import MongoJSONEncoder, ObjectIdConverter
import table_structures
from .. import table_structures
import mupif as mp


Expand Down
22 changes: 22 additions & 0 deletions mupifDB/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[mypy]
plugins = pydantic.mypy

# https://docs.pydantic.dev/latest/integrations/mypy/#configuring-the-plugin
[pydantic-mypy]
init_forbid_extra = True
init_typed = True
# those are used in models.py aliases
warn_required_dynamic_aliases = False

[mypy-numpy]
ignore_missing_imports = True
[mypy-pidfile]
ignore_missing_imports = True
[mypy-jsonpickle]
ignore_missing_imports = True
[mypy-Pyro5]
ignore_missing_imports = True
[mypy-mupif]
ignore_missing_imports = True
[mypy-pygal]
ignore_missing_imports = True
1 change: 0 additions & 1 deletion mupifDB/restLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def emit(self, record):


if __name__ == '__main__':
import restApiControl
logging.getLogger().setLevel(logging.DEBUG)
log = logging.getLogger('test')
log.setLevel(logging.DEBUG)
Expand Down
9 changes: 5 additions & 4 deletions mupifDB/table_structures.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Any

def extendRecord(record, structure):
for def_key in structure.keys():
Expand All @@ -6,13 +7,13 @@ def extendRecord(record, structure):
return record


tableUseCase = {
tableUseCase: dict[str,Any] = {
'ucid': None,
'Description': None,
}


tableWorkflow = {
tableWorkflow: dict[str,Any] = {
'wid': None,
'Description': None,
'UseCase': None,
Expand All @@ -26,7 +27,7 @@ def extendRecord(record, structure):
}


tableExecution = {
tableExecution: dict[str,Any] = {
'WorkflowID': None,
'WorkflowVersion': None,
'Status': "Created",
Expand All @@ -46,7 +47,7 @@ def extendRecord(record, structure):
}


tableUser = {
tableUser: dict[str,Any] = {
'IP': None,
'Name': None,
'Organization': None,
Expand Down
6 changes: 3 additions & 3 deletions mupifDB/workflowmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import pydantic
from typing import Literal

import table_structures
from . import table_structures

from mupifDB.api.client_util import api_type

Expand All @@ -43,7 +43,7 @@ def insertWorkflowDefinition(*, wid, description, source, useCase, workflowInput
@param modulename
@param classname
"""
insertWorkflowDefinition_real(
insertWorkflowDefinition_model(
source=source,
rec=models.Workflow_Model(
wid=wid,
Expand All @@ -61,7 +61,7 @@ def insertWorkflowDefinition(*, wid, description, source, useCase, workflowInput
)

@pydantic.validate_call
def insertWorkflowDefinition_real(source: pydantic.FilePath, rec: models.Workflow_Model):
def insertWorkflowDefinition_model(source: pydantic.FilePath, rec: models.Workflow_Model):
with open(source, 'rb') as f:
rec.GridFSID=restApiControl.uploadBinaryFile(f)
f.close()
Expand Down
3 changes: 1 addition & 2 deletions mupifDB/workflowscheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# try to import schedulerconfig.py
authToken = None
try:
import schedulerConfig
import schedulerConfig # type: ignore
authKey = schedulerConfig.authToken
except ImportError:
log.info("schedulerConfig import failed")
Expand Down Expand Up @@ -126,7 +126,6 @@ def historyUpdateFailed(data, epoch):
processedTasks = 0
finishedTasks = 0 # with success
failedTasks = 0
lastJobs = {} # dict, we-id key


schedulerStatFile = "/var/lib/mupif/persistent/scheduler-stat.json"
Expand Down

0 comments on commit d8e8795

Please sign in to comment.