Skip to content

Commit 2cc83d6

Browse files
Nathan ParkerNathan Parker
authored andcommitted
fixed linting
1 parent b11f7e1 commit 2cc83d6

File tree

21 files changed

+1481
-1020
lines changed

21 files changed

+1481
-1020
lines changed

.github/workflows/ci-cd.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,29 @@ jobs:
4242
flake8 src/ deploy/ --count --select=E9,F63,F7,F82 --show-source --statistics
4343
flake8 src/ deploy/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4444
45-
- name: Check code formatting with black
46-
run: black --check src/ deploy/
45+
- name: Format code with black
46+
run: |
47+
echo "Formatting code with black..."
48+
black src/ deploy/
49+
50+
echo "Checking if formatting changed any files..."
51+
if ! git diff --quiet src/ deploy/; then
52+
echo "❌ Code formatting issues found!"
53+
echo ""
54+
echo "The following files were reformatted:"
55+
git diff --name-only src/ deploy/
56+
echo ""
57+
echo "Please run the following command locally and commit the changes:"
58+
echo " black src/ deploy/"
59+
echo " git add src/ deploy/"
60+
echo " git commit -m 'chore: format code with black'"
61+
echo ""
62+
echo "Diff:"
63+
git diff src/ deploy/ | head -100
64+
exit 1
65+
else
66+
echo "✅ All code is properly formatted"
67+
fi
4768
4869
- name: Check import sorting with isort
4970
run: isort --profile black --check-only src/ deploy/

src/cli/base.py

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,25 @@ async def cleanup(self):
384384

385385
# Clean up all singleton services that might have been created
386386
services_to_cleanup = []
387-
387+
388388
# PackageService - may have FileResolver with aiohttp sessions
389389
try:
390390
from ..core.services.package_service import PackageService
391+
391392
package_service = PackageService._instance
392393
if package_service:
393394
if self.verbose:
394-
self.log(f"Found PackageService instance: {package_service}", "debug")
395+
self.log(
396+
f"Found PackageService instance: {package_service}", "debug"
397+
)
395398
if hasattr(package_service, "cleanup"):
396399
services_to_cleanup.append(("PackageService", package_service))
397400
else:
398401
if self.verbose:
399-
self.log("PackageService found but has no cleanup method", "warning")
402+
self.log(
403+
"PackageService found but has no cleanup method",
404+
"warning",
405+
)
400406
else:
401407
if self.verbose:
402408
self.log("No PackageService instance found", "debug")
@@ -408,27 +414,34 @@ async def cleanup(self):
408414
# OKHService - may have dependencies with aiohttp sessions
409415
try:
410416
from ..core.services.okh_service import OKHService
417+
411418
# OKHService uses BaseService which tracks instances
412419
if hasattr(OKHService, "_instances"):
413420
for service_name, service_instance in OKHService._instances.items():
414421
if hasattr(service_instance, "cleanup"):
415-
services_to_cleanup.append((f"OKHService({service_name})", service_instance))
422+
services_to_cleanup.append(
423+
(f"OKHService({service_name})", service_instance)
424+
)
416425
except Exception:
417426
pass
418427

419428
# OKWService - may have dependencies
420429
try:
421430
from ..core.services.okw_service import OKWService
431+
422432
if hasattr(OKWService, "_instances"):
423433
for service_name, service_instance in OKWService._instances.items():
424434
if hasattr(service_instance, "cleanup"):
425-
services_to_cleanup.append((f"OKWService({service_name})", service_instance))
435+
services_to_cleanup.append(
436+
(f"OKWService({service_name})", service_instance)
437+
)
426438
except Exception:
427439
pass
428440

429441
# MatchingService - singleton
430442
try:
431443
from ..core.services.matching_service import MatchingService
444+
432445
matching_service = MatchingService._instance
433446
if matching_service and hasattr(matching_service, "cleanup"):
434447
services_to_cleanup.append(("MatchingService", matching_service))
@@ -438,15 +451,22 @@ async def cleanup(self):
438451
# StorageService - singleton
439452
try:
440453
from ..core.services.storage_service import StorageService
454+
441455
storage_service = StorageService._instance
442456
if storage_service:
443457
if self.verbose:
444-
self.log(f"Found StorageService instance (configured={storage_service._configured})", "debug")
458+
self.log(
459+
f"Found StorageService instance (configured={storage_service._configured})",
460+
"debug",
461+
)
445462
if hasattr(storage_service, "cleanup"):
446463
services_to_cleanup.append(("StorageService", storage_service))
447464
else:
448465
if self.verbose:
449-
self.log("StorageService found but has no cleanup method", "warning")
466+
self.log(
467+
"StorageService found but has no cleanup method",
468+
"warning",
469+
)
450470
else:
451471
if self.verbose:
452472
self.log("No StorageService instance found", "debug")
@@ -462,8 +482,12 @@ async def cleanup(self):
462482
):
463483
package_service = self.service_fallback._services["package_service"]
464484
if package_service and hasattr(package_service, "cleanup"):
465-
if ("PackageService", package_service) not in [(n, s) for n, s in services_to_cleanup]:
466-
services_to_cleanup.append(("PackageService (fallback)", package_service))
485+
if ("PackageService", package_service) not in [
486+
(n, s) for n, s in services_to_cleanup
487+
]:
488+
services_to_cleanup.append(
489+
("PackageService (fallback)", package_service)
490+
)
467491

468492
# Clean up all services
469493
for service_name, service in services_to_cleanup:
@@ -474,20 +498,25 @@ async def cleanup(self):
474498
await service.cleanup()
475499
# Small delay to let cleanup operations complete
476500
import asyncio
501+
477502
await asyncio.sleep(0.05)
478503
except Exception as e:
479504
if self.verbose:
480-
self.log(f"Warning: Error cleaning up {service_name}: {e}", "warning")
505+
self.log(
506+
f"Warning: Error cleaning up {service_name}: {e}", "warning"
507+
)
481508

482509
# Give a delay to allow any pending operations to complete
483510
# This is important for aiohttp sessions to close properly
484511
# Azure storage provider needs extra time for aiohttp sessions to close
485512
import asyncio
513+
486514
await asyncio.sleep(0.5) # Increased wait time
487-
515+
488516
# Force garbage collection to find any unreferenced sessions
489517
try:
490518
import gc
519+
491520
gc.collect()
492521
# Small additional delay to let GC'd sessions close
493522
await asyncio.sleep(0.2)

src/cli/match.py

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,16 @@ async def requirements(
274274
"max_depth": max_depth,
275275
"auto_detect_depth": auto_detect_depth,
276276
}
277-
277+
278278
# Add solution storage parameters if requested
279279
if save_solution:
280280
nested_params["save_solution"] = True
281281
if solution_ttl_days:
282282
nested_params["solution_ttl_days"] = solution_ttl_days
283283
if solution_tags:
284-
nested_params["solution_tags"] = [tag.strip() for tag in solution_tags.split(",")]
284+
nested_params["solution_tags"] = [
285+
tag.strip() for tag in solution_tags.split(",")
286+
]
285287

286288
# Create request data based on domain and input type
287289
if detected_domain == "manufacturing":
@@ -346,15 +348,18 @@ async def http_match():
346348
import httpx
347349

348350
raise httpx.ConnectError("Use fallback for local facility file")
349-
351+
350352
# If nested matching with local file, use fallback (BOM file resolution needs manifest path)
351353
if max_depth > 0 and not is_url:
352354
cli_ctx.log(
353355
"Nested matching with local file - using fallback for BOM file resolution",
354356
"info",
355357
)
356358
import httpx
357-
raise httpx.ConnectError("Use fallback for nested matching with local file")
359+
360+
raise httpx.ConnectError(
361+
"Use fallback for nested matching with local file"
362+
)
358363

359364
cli_ctx.log("Attempting HTTP API matching...", "info")
360365
try:
@@ -440,40 +445,57 @@ async def fallback_match():
440445
okh_service=okh_service,
441446
manifest_path=manifest_path,
442447
)
443-
448+
444449
# Save solution if requested
445450
solution_id = None
446451
if save_solution:
447452
try:
448453
from ..core.services.storage_service import StorageService
449-
from ..config.storage_config import get_default_storage_config
450-
454+
from ..config.storage_config import (
455+
get_default_storage_config,
456+
)
457+
451458
storage_service = await StorageService.get_instance()
452-
await storage_service.configure(get_default_storage_config())
453-
459+
await storage_service.configure(
460+
get_default_storage_config()
461+
)
462+
454463
# Parse tags if provided
455464
tags_list = None
456465
if solution_tags:
457-
tags_list = [tag.strip() for tag in solution_tags.split(",")]
458-
466+
tags_list = [
467+
tag.strip() for tag in solution_tags.split(",")
468+
]
469+
459470
# Use default TTL of 30 days if not provided
460-
ttl_days = solution_ttl_days if solution_ttl_days is not None else 30
461-
solution_id = await storage_service.save_supply_tree_solution(
462-
solution,
463-
ttl_days=ttl_days,
464-
tags=tags_list,
471+
ttl_days = (
472+
solution_ttl_days
473+
if solution_ttl_days is not None
474+
else 30
475+
)
476+
solution_id = (
477+
await storage_service.save_supply_tree_solution(
478+
solution,
479+
ttl_days=ttl_days,
480+
tags=tags_list,
481+
)
482+
)
483+
cli_ctx.log(
484+
f"Solution saved to storage with ID: {solution_id}",
485+
"info",
465486
)
466-
cli_ctx.log(f"Solution saved to storage with ID: {solution_id}", "info")
467487
except Exception as e:
468488
cli_ctx.log(f"Failed to save solution: {str(e)}", "warning")
469489
# Continue without failing the match
470-
490+
471491
# Convert to response format matching API
472492
# For nested solutions, count trees, not solutions
473493
solution_dict = solution.to_dict()
474494
num_trees = len(solution.all_trees) if solution.all_trees else 0
475495
result = {
476-
"solutions": [solution_dict], # Wrap in array for consistency with display logic
496+
"solutions": [
497+
solution_dict
498+
], # Wrap in array for consistency with display logic
477499
"solution": solution_dict, # Also include singular for API compatibility
478500
"total_solutions": num_trees, # Count trees found, not solution count
479501
"matching_mode": "nested",
@@ -511,42 +533,64 @@ async def fallback_match():
511533
if save_solution and results_list:
512534
try:
513535
from ..core.services.storage_service import StorageService
514-
from ..core.models.supply_trees import SupplyTree, SupplyTreeSolution
515-
from ..config.storage_config import get_default_storage_config
516-
536+
from ..core.models.supply_trees import (
537+
SupplyTree,
538+
SupplyTreeSolution,
539+
)
540+
from ..config.storage_config import (
541+
get_default_storage_config,
542+
)
543+
517544
storage_service = await StorageService.get_instance()
518-
await storage_service.configure(get_default_storage_config())
519-
545+
await storage_service.configure(
546+
get_default_storage_config()
547+
)
548+
520549
# Convert best result to SupplyTreeSolution
521550
best_result = results_list[0] # Already sorted by score
522551
tree = SupplyTree.from_dict(best_result.to_dict())
523-
552+
524553
solution = SupplyTreeSolution(
525554
all_trees=[tree],
526555
score=best_result.score,
527556
metadata={
528-
"okh_id": str(manifest.id) if hasattr(manifest, 'id') else None,
557+
"okh_id": (
558+
str(manifest.id)
559+
if hasattr(manifest, "id")
560+
else None
561+
),
529562
"matching_mode": "single-level",
530-
}
563+
},
531564
)
532-
565+
533566
# Parse tags if provided
534567
tags_list = None
535568
if solution_tags:
536-
tags_list = [tag.strip() for tag in solution_tags.split(",")]
537-
569+
tags_list = [
570+
tag.strip() for tag in solution_tags.split(",")
571+
]
572+
538573
# Use default TTL of 30 days if not provided
539-
ttl_days = solution_ttl_days if solution_ttl_days is not None else 30
540-
solution_id = await storage_service.save_supply_tree_solution(
541-
solution,
542-
ttl_days=ttl_days,
543-
tags=tags_list,
574+
ttl_days = (
575+
solution_ttl_days
576+
if solution_ttl_days is not None
577+
else 30
578+
)
579+
solution_id = (
580+
await storage_service.save_supply_tree_solution(
581+
solution,
582+
ttl_days=ttl_days,
583+
tags=tags_list,
584+
)
585+
)
586+
cli_ctx.log(
587+
f"Solution saved to storage with ID: {solution_id}",
588+
"info",
544589
)
545-
cli_ctx.log(f"Solution saved to storage with ID: {solution_id}", "info")
546590
except Exception as e:
547591
cli_ctx.log(f"Failed to save solution: {str(e)}", "warning")
548592
# Continue without failing the match
549-
593+
550594
if results_list:
551595
result = {
552596
"solutions": [r.to_dict() for r in results_list],
@@ -1181,7 +1225,7 @@ async def _display_match_results(
11811225
# Handle both old format (matches) and new format (solutions)
11821226
solutions = result.get("solutions", result.get("matches", []))
11831227
total_solutions = result.get("total_solutions", len(solutions))
1184-
1228+
11851229
# Check if solution was saved (from API response or fallback)
11861230
solution_id = result.get("solution_id")
11871231
if solution_id:

0 commit comments

Comments
 (0)