Skip to content

Commit

Permalink
Use code for property type definitions (#60)
Browse files Browse the repository at this point in the history
* Added code_to_class_name utils function and testing

* Generated new properties with class naming corrected
  • Loading branch information
JosePizarro3 authored Jan 27, 2025
1 parent 6d634f7 commit c3d541a
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 240 deletions.
19 changes: 3 additions & 16 deletions bam_masterdata/cli/fill_masterdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import click

from bam_masterdata.openbis import OpenbisEntities
from bam_masterdata.utils import code_to_class_name


class MasterdataCodeGenerator:
Expand All @@ -24,20 +25,6 @@ def __init__(self, url: str = ""):
f"Loaded OpenBIS entities in `MasterdataCodeGenerator` initialization {elapsed_time:.2f} seconds\n"
)

def _format_class_name(self, code: str) -> str:
"""
Format the class name based on the `code` of the entity to follow Python snake case conventions.
Args:
code (str): The code of the entity.
Returns:
str: The formatted class name.
"""
if "." in code:
code = code.split(".")[-1]
return code.title().replace("_", "").replace("$", "")

def determine_parent_class(
self, code: str, class_names: dict, default: str, lines: list
) -> tuple:
Expand All @@ -63,7 +50,7 @@ class will inherit from `parent_class`.
parent_class = class_names.get(parent_code, default)

# Format class name
class_name = self._format_class_name(code)
class_name = code_to_class_name(code)
class_names[code] = class_name

# If the parent class does not exist but the `code` shows some inheritance, we add a note for debugging
Expand Down Expand Up @@ -152,7 +139,7 @@ def generate_property_types(self) -> str:
continue

# Format class name
class_name = self._format_class_name(code)
class_name = code_to_class_name(code, entity_type="property")

# Add class definition
lines.append(f"{class_name} = PropertyTypeDef(")
Expand Down
Loading

2 comments on commit c3d541a

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
bam_masterdata
   logger.py80100% 
bam_masterdata/cli
   cli.py643737 42%
   entities_to_excel.py5433 94%
   entities_to_json.py3655 86%
   fill_masterdata.py185172172 7%
bam_masterdata/datamodel
   collection_types.py370100% 
   dataset_types.py184184184 0%
   object_types.py15150100% 
   property_types.py8000100% 
   vocabulary_types.py137210100% 
bam_masterdata/metadata
   definitions.py780100% 
   entities.py5433 94%
bam_masterdata/openbis
   get_entities.py534343 19%
   login.py633 50%
bam_masterdata/utils
   utils.py4677 85%
TOTAL1684145797% 

Tests Skipped Failures Errors Time
72 1 💤 0 ❌ 0 🔥 18.366s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
bam_masterdata
   logger.py80100% 
bam_masterdata/cli
   cli.py643737 42%
   entities_to_excel.py5433 94%
   entities_to_json.py3655 86%
   fill_masterdata.py185172172 7%
bam_masterdata/datamodel
   collection_types.py370100% 
   dataset_types.py184184184 0%
   object_types.py15150100% 
   property_types.py8000100% 
   vocabulary_types.py137210100% 
bam_masterdata/metadata
   definitions.py780100% 
   entities.py5433 94%
bam_masterdata/openbis
   get_entities.py534343 19%
   login.py633 50%
bam_masterdata/utils
   utils.py4677 85%
TOTAL1684145797% 

Tests Skipped Failures Errors Time
72 1 💤 0 ❌ 0 🔥 18.716s ⏱️

Please sign in to comment.