Skip to content

Commit

Permalink
Merge pull request #13 from mvinyard/dev
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
mvinyard authored Mar 1, 2025
2 parents b0c0a8f + 81b1c25 commit c03163d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion ABCParse/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.1"
__version__ = "0.1.2"
31 changes: 17 additions & 14 deletions ABCParse/_abc_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def __call__(self, x=4, y=5, z=3, *args, **kwargs):

def _initialize_logger(self, level: str = "warning", file_path: str = logging._format.DEFAULT_LOG_FILEPATH) -> None:
# Initialize logger with class name and logging parameters
self._logger = logging.get_logger(
self._cls_logger = logging.get_logger(
name=self.__class__.__name__,
level=level,
file_path=file_path
)
self._logger.debug(f"Initializing {self.__class__.__name__}")
self._cls_logger.debug(f"Initializing {self.__class__.__name__}")

def __build__(self, level: str = "warning", file_path: str = logging._format.DEFAULT_LOG_FILEPATH) -> None:
self._PARAMS = {}
Expand All @@ -59,7 +59,7 @@ def __build__(self, level: str = "warning", file_path: str = logging._format.DEF
self._stored_public = []
self._initialize_logger(level, file_path)
self._BUILT = True
self._logger.debug("Built internal structures")
self._cls_logger.debug("Built internal structures")

def __set__(
self, key: str, val: Any, public: List = [], private: List = []
Expand All @@ -69,10 +69,10 @@ def __set__(
if (key in private) and (not key in public):
self._stored_private.append(key)
key = f"_{key}"
self._logger.debug(f"Setting private attribute: {key}")
self._cls_logger.debug(f"Setting private attribute: {key}")
else:
self._stored_public.append(key)
self._logger.debug(f"Setting public attribute: {key}")
self._cls_logger.debug(f"Setting public attribute: {key}")
setattr(self, key, val)

def __set_existing__(self, key: str, val: Any) -> None:
Expand All @@ -87,19 +87,19 @@ def __set_existing__(self, key: str, val: Any) -> None:
attr.update(val)
setattr(self, key, attr)
self._PARAMS.update(val)
self._logger.debug(f"Updated kwargs: {val}")
self._cls_logger.debug(f"Updated kwargs: {val}")

elif passed_key == "args":
attr = getattr(self, key)
attr += val
setattr(self, key, attr)
self._PARAMS[passed_key] += val
self._logger.debug(f"Updated args: {val}")
self._cls_logger.debug(f"Updated args: {val}")

else:
self._PARAMS[passed_key] = val
setattr(self, key, val)
self._logger.debug(f"Updated attribute {key}: {val}")
self._cls_logger.debug(f"Updated attribute {key}: {val}")

@property
def _STORED(self) -> List:
Expand All @@ -110,11 +110,11 @@ def __setup_inputs__(self, kwargs, public, private, ignore) -> Tuple[List]:
self.__build__()

self._IGNORE += ignore
self._logger.debug(f"Setup inputs with ignore list: {self._IGNORE}")
self._cls_logger.debug(f"Setup inputs with ignore list: {self._IGNORE}")

if len(public) > 0:
private = list(kwargs.keys())
self._logger.debug(f"Public attributes specified, setting all others as private")
self._cls_logger.debug(f"Public attributes specified, setting all others as private")

return public, private

Expand Down Expand Up @@ -142,13 +142,13 @@ def __parse__(
"""

public, private = self.__setup_inputs__(kwargs, public, private, ignore)
self._logger.debug(f"Parsing kwargs: {kwargs}")
self._cls_logger.debug(f"Parsing kwargs: {kwargs}")

for key, val in kwargs.items():
if not key in self._IGNORE:
self.__set__(key, val, public, private)

self._logger.info(f"Parsed {len(self._PARAMS)} parameters")
self._cls_logger.debug(f"Parsed {len(self._PARAMS)} parameters")

def __update__(
self,
Expand Down Expand Up @@ -179,7 +179,7 @@ def __update__(
-------
None
"""
self._logger.debug(f"Updating with kwargs: {kwargs}")
self._cls_logger.debug(f"Updating with kwargs: {kwargs}")
public, private = self.__setup_inputs__(kwargs, public, private, ignore)

updated_count = 0
Expand All @@ -194,4 +194,7 @@ def __update__(
self.__set__(key, val, public, private)
new_count += 1

self._logger.info(f"Updated {updated_count} existing parameters and added {new_count} new parameters")
self._cls_logger.debug(f"Updated {updated_count} existing parameters and added {new_count} new parameters")

def __repr__(self) -> str:
return "ABCParse.ABCParse"
4 changes: 2 additions & 2 deletions ABCParse/_as_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __call__(

if not self._target_type is None:
assert self.validated_target_types, "Not all values match the target type"
self._logger.info(f"Validated {len(self.list_values)} values against target type(s)")
self._logger.debug(f"Validated {len(self.list_values)} values against target type(s)")

return self.list_values

Expand Down Expand Up @@ -116,5 +116,5 @@ def as_list(
_logger.debug(f"as_list called with input: {input}, target_type: {target_type}")
_as_list = AsList()
result = _as_list(input=input, target_type=target_type, *args, **kwargs)
_logger.info(f"Converted to list with {len(result)} elements")
_logger.debug(f"Converted to list with {len(result)} elements")
return result
2 changes: 1 addition & 1 deletion tests/test_ABCParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_build(self) -> None:
self.assertIn("__class__", self.parser._IGNORE)
self.assertEqual(self.parser._stored_private, [])
self.assertEqual(self.parser._stored_public, [])
self.assertIsInstance(self.parser._logger, ABCParse.logging.ABCLogger)
self.assertIsInstance(self.parser._cls_logger, ABCParse.logging.ABCLogger)

def test_set(self) -> None:
"""Test the __set__ method for setting attributes."""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def test_abc_parse_logging(self) -> None:
parser.__build__()
try:
# Test that the parser logs correctly
parser._logger.info("Test message from ABCParse")
parser._cls_logger.info("Test message from ABCParse")

# Ensure logger is closed to flush buffers
parser._logger.close()
parser._cls_logger.close()

# Verify the message was logged to file

Expand All @@ -146,7 +146,7 @@ def test_abc_parse_logging(self) -> None:
finally:
# Ensure logger is closed even if assertions fail
if hasattr(parser, '_logger'):
parser._logger.close()
parser._cls_logger.close()
finally:
# Clean up the temporary file
try:
Expand Down

0 comments on commit c03163d

Please sign in to comment.