Skip to content

Commit 01a49f1

Browse files
committed
move to match/case and path
1 parent 97adf06 commit 01a49f1

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

layoutlens/analyzer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ def analyze_screenshot(
197197

198198
def _encode_image(self, image_path: str) -> str:
199199
"""Encode image to base64 string."""
200-
with open(image_path, "rb") as image_file:
200+
image_file_path = Path(image_path)
201+
with image_file_path.open("rb") as image_file:
201202
return base64.b64encode(image_file.read()).decode("utf-8")
202203

203204
def _get_prompt_template(self, instructions: Instructions | None = None) -> PromptTemplate:

layoutlens/api/core.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -833,16 +833,18 @@ def __init__(self, *args, **kwargs):
833833
super().__init__(*args, directory=str(html_file_path.parent), **kwargs)
834834

835835
def do_GET(self):
836-
# If requesting root, serve our HTML file
837-
if self.path == "/" or self.path == "":
838-
self.send_response(200)
839-
self.send_header("Content-type", "text/html")
840-
self.end_headers()
841-
with open(html_file_path, "rb") as f:
842-
self.wfile.write(f.read())
843-
else:
844-
# Serve other files normally (CSS, JS, images)
845-
super().do_GET()
836+
# Route based on path
837+
match self.path:
838+
case "/" | "":
839+
# Serve our HTML file
840+
self.send_response(200)
841+
self.send_header("Content-type", "text/html")
842+
self.end_headers()
843+
with open(html_file_path, "rb") as f:
844+
self.wfile.write(f.read())
845+
case _:
846+
# Serve other files normally (CSS, JS, images)
847+
super().do_GET()
846848

847849
def log_message(self, format, *args):
848850
# Suppress server logs
@@ -1301,12 +1303,13 @@ async def capture_batch(
13011303

13021304
# Validate existing files
13031305
for file_path in existing_files:
1304-
if Path(file_path).exists():
1305-
results[str(file_path)] = str(file_path)
1306+
file_path_obj = Path(file_path)
1307+
if file_path_obj.exists():
1308+
results[file_path] = file_path
13061309
self.logger.debug(f"Using existing file: {file_path}")
13071310
else:
13081311
failed_count += 1
1309-
results[str(file_path)] = f"Error: File not found"
1312+
results[file_path] = f"Error: File not found"
13101313
self.logger.warning(f"File not found: {file_path}")
13111314

13121315
# Capture URLs using BatchCapture for efficiency
@@ -1388,11 +1391,12 @@ async def capture_batch_async(
13881391

13891392
# Validate existing files
13901393
for file_path in existing_files:
1391-
if Path(file_path).exists():
1392-
results[str(file_path)] = str(file_path)
1394+
file_path_obj = Path(file_path)
1395+
if file_path_obj.exists():
1396+
results[file_path] = file_path
13931397
self.logger.debug(f"Using existing file: {file_path}")
13941398
else:
1395-
results[str(file_path)] = f"Error: File not found"
1399+
results[file_path] = f"Error: File not found"
13961400
self.logger.warning(f"File not found: {file_path}")
13971401

13981402
# Capture sources concurrently

layoutlens/logger.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ def setup_logging(
8484
root_logger.removeHandler(handler)
8585

8686
# Choose formatter
87-
if format_type == "debug":
88-
formatter = logging.Formatter(DEBUG_FORMAT)
89-
elif format_type == "console":
90-
formatter = logging.Formatter(CONSOLE_FORMAT)
91-
else:
92-
formatter = logging.Formatter(DEFAULT_FORMAT)
87+
match format_type:
88+
case "debug":
89+
formatter = logging.Formatter(DEBUG_FORMAT)
90+
case "console":
91+
formatter = logging.Formatter(CONSOLE_FORMAT)
92+
case _:
93+
formatter = logging.Formatter(DEFAULT_FORMAT)
9394

9495
# Console handler
9596
if console:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ keywords = ["ui testing", "visual regression", "ai", "computer vision", "web tes
1818
classifiers = [
1919
"Development Status :: 5 - Production/Stable",
2020
"Intended Audience :: Developers",
21+
"License :: OSI Approved :: MIT License",
2122
"Programming Language :: Python :: 3",
2223
"Programming Language :: Python :: 3.11",
2324
"Programming Language :: Python :: 3.12",

0 commit comments

Comments
 (0)