Skip to content

Commit 3069faa

Browse files
committed
fix: satisfy copilot warnings regarding py version syntax and import paths
1 parent 8ba576b commit 3069faa

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

mkconcore.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,12 @@ def _resolve_concore_path():
151151
_tmp_graphml_file = None # keep reference so the temp file isn't deleted early
152152
if os.path.splitext(GRAPHML_FILE)[1].lower() in _IMAGE_EXTS:
153153
try:
154-
_tool_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tools")
155-
sys.path.insert(0, _tool_dir)
156-
from extract_graphml import extract_graphml as _extract_graphml
154+
import importlib.util
155+
_tool_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tools", "extract_graphml.py")
156+
_spec = importlib.util.spec_from_file_location("extract_graphml", _tool_path)
157+
_extract_graphml_module = importlib.util.module_from_spec(_spec)
158+
_spec.loader.exec_module(_extract_graphml_module)
159+
_extract_graphml = _extract_graphml_module.extract_graphml
157160
_graphml_str = _extract_graphml(GRAPHML_FILE)
158161
if _graphml_str is None:
159162
print(f"No embedded GraphML found in '{GRAPHML_FILE}'.")

tools/extract_graphml.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
import struct
23
import zlib
34
import sys
@@ -11,7 +12,7 @@
1112
_PNG_SIGNATURE = b"\x89PNG\r\n\x1a\n"
1213

1314

14-
def _extract_from_png(data: bytes) -> str | None:
15+
def _extract_from_png(data: bytes) -> Optional[str]:
1516
#Return the GraphML string embedded in a PNG file, or None
1617
if data[:8] != _PNG_SIGNATURE:
1718
return None
@@ -87,7 +88,7 @@ def _extract_from_png(data: bytes) -> str | None:
8788
_JPEG_SOI = b"\xff\xd8"
8889

8990

90-
def _extract_from_jpeg(data: bytes) -> str | None:
91+
def _extract_from_jpeg(data: bytes) -> Optional[str]:
9192
#Return the GraphML string embedded in a JPEG file, or None.
9293
if data[:2] != _JPEG_SOI:
9394
return None
@@ -119,7 +120,7 @@ def _extract_from_jpeg(data: bytes) -> str | None:
119120
# ---------------------------------------------------------------------------
120121

121122

122-
def extract_graphml(image_path: str) -> str | None:
123+
def extract_graphml(image_path: str) -> Optional[str]:
123124
try:
124125
with open(image_path, "rb") as fh:
125126
data = fh.read()
@@ -141,7 +142,7 @@ def extract_graphml(image_path: str) -> str | None:
141142
return None
142143

143144

144-
def extract_graphml_to_file(image_path: str, output_path: str | None = None) -> str | None:
145+
def extract_graphml_to_file(image_path: str, output_path: Optional[str] = None) -> Optional[str]:
145146
graphml = extract_graphml(image_path)
146147
if graphml is None:
147148
print(

0 commit comments

Comments
 (0)