mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
ci: replace broken default workflows with compile/unit/integration CI
The two scaffold workflows (Python application / Python package) failed on
every PR: they installed deps from a non-existent requirements.txt, ran
flake8/pytest over the vendored yt_dlp fork (new syntax under the 3.8/3.9
matrix), and collected ad-hoc root scripts — notably test_ai.py, which is
an invalid pasted object dump (not Python).
- Remove python-app.yml / python-package.yml and the junk root scripts
(test.py, test_ai.py, test_time.py)
- Add .github/workflows/ci.yml with three PR-check jobs:
* compile — py_compile every first-party .py (no deps)
* unit — pytest on pure logic (conanjurer_functions, constants)
* integration — boot the Flask services and assert the X-Conjurer-Api-Key
auth contract (communication_subroutine + conjurer_musician)
- Add tests/ suite, pytest.ini (testpaths=tests) and conftest.py (sys.path)
Fixes surfaced by the compile gate / needed for the integration job:
- conjurer_librarian/search_bot.py + search_bot2.py: f-string reused the
same quote ({item["exists"]}) -> SyntaxError on Python < 3.12
- conjurer_musician/media_search_functions.py: made import-safe
(env-overridable paths, lazy DB load / mkdir) so the service can be
imported and tested off the Pi
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,24 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
"""Share-list search/publish helpers for the musician service.
|
||||
|
||||
Paths are environment-overridable and the share database / directory are
|
||||
accessed lazily, so importing this module has no side effects (the previous
|
||||
version ran ``SHARE_DIR.mkdir()`` and read the JSON DB at import time, which
|
||||
crashed on any host without the Pi's ``/var/www`` / ``/var/log`` layout — and
|
||||
made the service untestable).
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
# CONFIGURATION
|
||||
JSON_DB = '/var/log/share_scan.json'
|
||||
SHARE_DIR = Path('/var/www/html/share')
|
||||
BASE_URL = 'https://czernobog.pl/share'
|
||||
# CONFIGURATION (env-overridable)
|
||||
JSON_DB = os.getenv("CONJURER_SHARE_DB", "/var/log/share_scan.json")
|
||||
SHARE_DIR = Path(os.getenv("CONJURER_SHARE_DIR", "/var/www/html/share"))
|
||||
BASE_URL = os.getenv("CONJURER_SHARE_BASE_URL", "https://czernobog.pl/share")
|
||||
|
||||
_entries_cache = None
|
||||
|
||||
|
||||
def _ensure_share_dir():
|
||||
SHARE_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Ensure share directory exists
|
||||
SHARE_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def load_db():
|
||||
with open(JSON_DB) as f:
|
||||
return json.load(f)['entries']
|
||||
"""Load share entries, returning [] when the DB is missing/corrupt."""
|
||||
try:
|
||||
with open(JSON_DB) as handle:
|
||||
return json.load(handle).get("entries", [])
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
return []
|
||||
|
||||
|
||||
def _entries():
|
||||
global _entries_cache
|
||||
if _entries_cache is None:
|
||||
_entries_cache = load_db()
|
||||
return _entries_cache
|
||||
|
||||
ENTRIES = load_db()
|
||||
|
||||
def relevancy(path, keywords):
|
||||
score = 0
|
||||
@@ -28,17 +48,20 @@ def relevancy(path, keywords):
|
||||
score += low.count(kw.lower())
|
||||
return score
|
||||
|
||||
|
||||
def find_matches(count, keywords):
|
||||
scored = []
|
||||
for e in ENTRIES:
|
||||
score = relevancy(e['path'], keywords)
|
||||
for entry in _entries():
|
||||
score = relevancy(entry["path"], keywords)
|
||||
if score > 0:
|
||||
scored.append((score, e['path']))
|
||||
scored.append((score, entry["path"]))
|
||||
scored.sort(reverse=True, key=lambda x: x[0])
|
||||
result = [p for _, p in scored]
|
||||
return result[:count]
|
||||
|
||||
|
||||
def publish(paths):
|
||||
_ensure_share_dir()
|
||||
urls = []
|
||||
for path in paths:
|
||||
token = uuid.uuid4().hex
|
||||
@@ -49,4 +72,3 @@ def publish(paths):
|
||||
pass
|
||||
urls.append(f"{BASE_URL}/{token}")
|
||||
return urls
|
||||
|
||||
|
||||
Reference in New Issue
Block a user