Skip to content

Commit

Permalink
Apply automatic formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci-lite[bot] authored Nov 7, 2024
1 parent f2f04b1 commit b6bd79e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
9 changes: 3 additions & 6 deletions src/scicat_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def extract_variables_values(
"ingestor_run_id": str(uuid.uuid4()),
"data_file_path": pathlib.Path(config.nexus_file),
"now": datetime.datetime.now(tz=datetime.UTC).isoformat(),
"ingestor_files_directory": config.ingestion.file_handling.ingestor_files_directory
"ingestor_files_directory": config.ingestion.file_handling.ingestor_files_directory,
}
for variable_name, variable_recipe in variables.items():
source = variable_recipe.source
Expand Down Expand Up @@ -265,6 +265,7 @@ class ScicatDataset:
runNumber: str | None = None
keywords: list[str] | None = None


@dataclass(kw_only=True)
class DataFileListItem:
path: str
Expand Down Expand Up @@ -457,11 +458,7 @@ def _filter_by_field_type(
return [field for field in schemas if field.field_type == field_type]


def _render_variable_as_type(
value: Any,
variable_map: dict,
dtype: str
) -> Any:
def _render_variable_as_type(value: Any, variable_map: dict, dtype: str) -> Any:
return convert_to_type(render_variable_value(value, variable_map), dtype)


Expand Down
19 changes: 11 additions & 8 deletions src/scicat_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,29 @@ def from_file(cls, schema_file_name: pathlib.Path) -> "MetadataSchema":
return cls.from_dict(_load_json_schema(schema_file_name))


def render_variable_value(
var_value: Any,
variable_registry: dict
) -> str:
def render_variable_value(var_value: Any, variable_registry: dict) -> str:
# if input is not a string it converts it to string
output_value = var_value if isinstance(var_value,str) else json.dumps(var_value)
output_value = var_value if isinstance(var_value, str) else json.dumps(var_value)

# If it is only one variable, then it is a simple replacement
if (var_key := output_value.removesuffix(">").removeprefix("<")) in variable_registry:
if (
var_key := output_value.removesuffix(">").removeprefix("<")
) in variable_registry:
return variable_registry[var_key]

# If it is a complex variable, then it is a combination of variables
# similar to f-string in python
for reg_var_name, reg_var_value in variable_registry.items():
output_value = output_value.replace("<" + reg_var_name + ">", str(reg_var_value))
output_value = output_value.replace(
"<" + reg_var_name + ">", str(reg_var_value)
)

if "<" in var_value and ">" in var_value:
raise Exception(f"Unresolved variable: {var_value}")

output_value = output_value if isinstance(var_value,str) else json.loads(output_value)
output_value = (
output_value if isinstance(var_value, str) else json.loads(output_value)
)
return output_value


Expand Down
6 changes: 5 additions & 1 deletion src/scicat_offline_ingestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ def main() -> None:
with h5py.File(nexus_file_path) as h5file:
# load instrument metadata configuration
metadata_schema = select_applicable_schema(nexus_file_path, schemas)
logger.info("Metadata Schema selected : %s (Id: %s)", metadata_schema.name, metadata_schema.id)
logger.info(
"Metadata Schema selected : %s (Id: %s)",
metadata_schema.name,
metadata_schema.id,
)

# define variables values
variable_map = extract_variables_values(
Expand Down

0 comments on commit b6bd79e

Please sign in to comment.