Skip to content

Commit

Permalink
Changed library ignore logic
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Dec 2, 2024
1 parent 8249f8e commit 12bb273
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:


- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
rev: v0.8.1
hooks:
- id: ruff
name: ruff unused imports
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Packages for source formatting
# -----------------------------------------------------------------------------
pre-commit == 4.0.1
ruff == 0.8.0
ruff == 0.8.1
autotyping == 24.9.0
# -----------------------------------------------------------------------------
# Packages for other developement tasks
Expand Down
6 changes: 3 additions & 3 deletions requirements_setup.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiohttp == 3.11.7
pydantic == 2.10.1
aiohttp == 3.11.9
pydantic == 2.10.2
bidict == 0.23.1
watchdog == 6.0.0
ujson == 5.10.0
Expand All @@ -20,4 +20,4 @@ typing-extensions == 4.12.2

aiohttp-sse-client == 0.2.1

javaproperties == 0.8.1
javaproperties == 0.8.2
2 changes: 1 addition & 1 deletion requirements_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
# Packages to run source tests
# -----------------------------------------------------------------------------
packaging == 24.2
pytest == 8.3.3
pytest == 8.3.4
pytest-asyncio == 0.24.0
47 changes: 35 additions & 12 deletions src/HABApp/core/lib/exceptions/format_frame.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import re
import sys
from pathlib import Path
from typing import Final

from stack_data import LINE_GAP, FrameInfo

Expand All @@ -25,12 +28,33 @@
re.compile(r'[/\\]HABApp[/\\]core[/\\]connections[/\\]'),
)

SUPPRESSED_PATHS = (
# Libraries of base installation
re.compile(r'[/\\](?:python\d\.\d+|python\d{2,3})[/\\](?:lib[/\\]|site-packages[/\\]|\w+\.py.*$)', re.IGNORECASE),
# Libraries in venv
re.compile(r'[/\\]lib[/\\]site-packages[/\\]', re.IGNORECASE),
)

def __get_library_paths() -> tuple[str, ...]:
ret = []
exec_folter = Path(sys.executable).parent
ret.append(str(exec_folter))

# detect virtual environment
if exec_folter.with_name('pyvenv.cfg').is_file():
folder_names = ('bin', 'include', 'lib', 'lib64', 'scripts')
for p in exec_folter.parent.iterdir():
if p.name.lower() in folder_names and (value := str(p)) not in ret and p.is_dir():
ret.append(value)

return tuple(ret)


def _get_habapp_module_path() -> str:
this = Path(__file__)
while this.name != 'HABApp' or not this.is_dir():
this = this.parent
return str(this)


SUPPRESSED_PATHS: Final = __get_library_paths()
HABAPP_MODULE_PATH: Final = _get_habapp_module_path()
del __get_library_paths
del _get_habapp_module_path


def is_suppressed_habapp_file(name: str) -> bool:
Expand All @@ -41,12 +65,11 @@ def is_suppressed_habapp_file(name: str) -> bool:


def is_lib_file(name: str) -> bool:
for r in SUPPRESSED_PATHS:
if r.search(name):
if '/HABApp/' in name or '\\HABApp\\' in name:
continue
return True
return False
if name.startswith(HABAPP_MODULE_PATH):
return False

return bool(name.startswith(SUPPRESSED_PATHS))



def format_frame_info(tb: list[str], frame_info: FrameInfo, is_last=False) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion src/HABApp/core/lib/exceptions/format_frame_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _filter_expressions(name: str, value: Any) -> bool:
return False


SKIPPED_OBJS: Final = (
SKIPPED_OBJS: Final[tuple[str, ...]] = (
'HABApp.core.Items',
)

Expand Down
16 changes: 13 additions & 3 deletions tests/helpers/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def remove_dyn_parts_from_traceback(traceback: str) -> str:
fname = '/'.join(Path(m.group(1)).parts[-3:])
traceback = traceback.replace(m.group(0), f'File "{fname}"')

# Line nrs
traceback = re.sub(r'line\s+(\d+)', 'line x', traceback)
traceback = re.sub(r'^(-->|\s{3})\s{2}\d+ \|', '\g<1> x |', traceback, flags=re.MULTILINE)

return traceback


Expand All @@ -22,12 +26,18 @@ def test_remove_dyn_parts_from_traceback() -> None:
File "/My/Folder/HABApp/tests/test_core/test_lib/test_format_traceback.py", line 19 in exec_func
func = <function func_test_assert_none at 0x0000022A46E3C550>
File "C:\\My\\Folder\\HABApp\\tests\\test_core\\test_lib\\test_format_traceback.py", line 19, in exec_func
16 | try:
--> 17 | func()
18 | except Exception as e:
'''
processed = remove_dyn_parts_from_traceback(traceback)

assert processed == '''
File "test_core/test_lib/test_format_traceback.py", line 19 in exec_func
File "test_core/test_lib/test_format_traceback.py", line 19 in exec_func
File "test_core/test_lib/test_format_traceback.py", line x in exec_func
File "test_core/test_lib/test_format_traceback.py", line x in exec_func
func = <function func_test_assert_none at 0xAAAAAAAAAAAAAAAA>
File "test_core/test_lib/test_format_traceback.py", line 19, in exec_func
File "test_core/test_lib/test_format_traceback.py", line x, in exec_func
x | try:
--> x | func()
x | except Exception as e:
'''
Loading

0 comments on commit 12bb273

Please sign in to comment.