-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added duplicated_property_types function in CLI
- Loading branch information
1 parent
66cd1b4
commit c6f078d
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import inspect | ||
import re | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from structlog._config import BoundLoggerLazyProxy | ||
|
||
from bam_masterdata.utils import import_module | ||
|
||
|
||
def duplicated_property_types(module_path: str, logger: "BoundLoggerLazyProxy") -> dict: | ||
duplicated_props: dict = {} | ||
module = import_module(module_path=module_path) | ||
source_code = inspect.getsource(module) | ||
for name, _ in inspect.getmembers(module): | ||
if name.startswith("_") or name == "PropertyTypeDef": | ||
continue | ||
|
||
pattern = rf"^\s*{name} *= *PropertyTypeDef" | ||
|
||
# Find all matching line numbers | ||
matches = [ | ||
i + 1 # Convert to 1-based index | ||
for i, line in enumerate(source_code.splitlines()) | ||
if re.match(pattern, line) | ||
] | ||
if len(matches) > 1: | ||
duplicated_props[name] = matches | ||
if duplicated_props: | ||
logger.critical( | ||
f"Found {len(duplicated_props)} duplicated property types. These are stored in a dictionary " | ||
f"where the keys are the names of the variables in property_types.py and the values are the lines in the module: {duplicated_props}" | ||
) | ||
return duplicated_props |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c6f078d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report