mypy and pre commit

This commit is contained in:
mike cullerton 2022-09-26 13:54:26 -04:00
parent d268e85e1f
commit 35e26e89fa
5 changed files with 31 additions and 10 deletions

View File

@ -161,7 +161,7 @@ class ProcessInstanceModelSchema(Schema):
"updated_at_in_seconds",
"created_at_in_seconds",
"status",
"bpmn_version_control_identifier"
"bpmn_version_control_identifier",
]
status = marshmallow.fields.Method("get_status", dump_only=True)

View File

@ -614,7 +614,10 @@ def process_instance_show(
process_model = get_process_model(process_model_id, process_group_id)
if process_model.primary_file_name:
if process_instance.bpmn_version_control_identifier == current_version_control_revision:
if (
process_instance.bpmn_version_control_identifier
== current_version_control_revision
):
bpmn_xml_file_contents = SpecFileService.get_data(
process_model, process_model.primary_file_name
)
@ -622,6 +625,9 @@ def process_instance_show(
bpmn_xml_file_contents = GitService.get_instance_file_contents_for_revision(
process_model, process_instance.bpmn_version_control_identifier
)
# dummy_var = GitService.get_instance_file_contents_for_revision(
# process_model, process_instance.bpmn_version_control_identifier
# )
process_instance.bpmn_xml_file_contents = bpmn_xml_file_contents
return make_response(jsonify(process_instance), 200)

View File

@ -1,4 +1,6 @@
"""Git_service."""
import os
from flask import current_app
from spiffworkflow_backend.models.process_model import ProcessModelInfo
@ -6,19 +8,33 @@ from spiffworkflow_backend.services.file_system_service import FileSystemService
class GitService:
"""GitService."""
@staticmethod
def get_current_revision() -> str:
"""Get_current_revision."""
bpmn_spec_absolute_dir = current_app.config["BPMN_SPEC_ABSOLUTE_DIR"]
# The value includes a carriage return character at the end, so we don't grab the last character
current_git_revision = os.popen(f"cd {bpmn_spec_absolute_dir} && git rev-parse --short HEAD").read()[:-1]
current_git_revision = os.popen( # noqa: S605
f"cd {bpmn_spec_absolute_dir} && git rev-parse --short HEAD"
).read()[
:-1
] # noqa: S605
return current_git_revision
@staticmethod
def get_instance_file_contents_for_revision(process_model: ProcessModelInfo, revision: str) -> str:
def get_instance_file_contents_for_revision(
process_model: ProcessModelInfo, revision: str
) -> str:
"""Get_instance_file_contents_for_revision."""
bpmn_spec_absolute_dir = current_app.config["BPMN_SPEC_ABSOLUTE_DIR"]
process_model_relative_path = FileSystemService.process_model_relative_path(process_model)
shell_command = f"cd {bpmn_spec_absolute_dir} && git show {revision}:{process_model_relative_path}/{process_model.primary_file_name}"
process_model_relative_path = FileSystemService.process_model_relative_path(
process_model
)
shell_cd_command = f"cd {bpmn_spec_absolute_dir}"
shell_git_command = f"git show {revision}:{process_model_relative_path}/{process_model.primary_file_name}"
shell_command = f"{shell_cd_command} && {shell_git_command}"
# git show 78ae5eb:category_number_one/script-task/script-task.bpmn
file_contents = os.popen(shell_command).read()[:-1]
file_contents: str = os.popen(shell_command).read()[:-1] # noqa: S605
assert file_contents # noqa: S101
return file_contents

View File

@ -1,5 +1,4 @@
"""Process_instance_service."""
import os
import time
from typing import Any
from typing import Dict
@ -56,7 +55,7 @@ class ProcessInstanceService:
process_model_identifier=process_model_identifier,
process_group_identifier=process_group_identifier,
start_in_seconds=round(time.time()),
bpmn_version_control_type='git',
bpmn_version_control_type="git",
bpmn_version_control_identifier=current_git_revision,
)
db.session.add(process_instance_model)

View File

@ -25,11 +25,11 @@ from spiffworkflow_backend.models.process_model import NotificationType
from spiffworkflow_backend.models.process_model import ProcessModelInfoSchema
from spiffworkflow_backend.models.task_event import TaskEventModel
from spiffworkflow_backend.models.user import UserModel
from spiffworkflow_backend.services.git_service import GitService
from spiffworkflow_backend.services.process_instance_processor import (
ProcessInstanceProcessor,
)
from spiffworkflow_backend.services.process_model_service import ProcessModelService
# from spiffworkflow_backend.services.git_service import GitService
class TestProcessApi(BaseTest):