diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1a4ff1..c1ffdfa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,9 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt + - name: Lint + run: pip install ruff && ruff check . + - name: Run application tests run: python -m unittest discover -s tests -v diff --git a/README.md b/README.md index e8fe0de..b068261 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ to see the admin pages. The microphone needs HTTPS, except on `localhost`. ## Deployment [docs/AWS_SETUP_V2.md](docs/AWS_SETUP_V2.md) walks through SES, Rekognition, the -thumbnail Lambda and the CloudWatch alarm. [AWS_DEPLOYMENT.md](AWS_DEPLOYMENT.md) +thumbnail Lambda and the CloudWatch alarm. [docs/AWS_DEPLOYMENT.md](docs/AWS_DEPLOYMENT.md) covers the S3 bucket and its policy, the instance role's permissions, RDS and the Elastic Beanstalk environment. Set the variables above, deploy the source bundle (`git archive --format=zip -o classfind.zip HEAD`), then run the smoke @@ -226,7 +226,7 @@ Retrace, voice in each mode, every model fallback (busy, retired, timed out), and a check that the fast matching path returns exactly what a plain double loop returns. -CI runs the suite twice on every pull request: on SQLite, and on PostgreSQL 16, +CI lints the code with ruff and runs the suite twice on every pull request: on SQLite, and on PostgreSQL 16, the database the live site uses. Two more checks live in `tools/`: @@ -252,6 +252,9 @@ ClassFind/ ├── app.py config, models, routes, matching, Retrace, voice ├── campus.py place names → places on the map ├── application.py WSGI entry point for Elastic Beanstalk +├── Procfile Gunicorn command +├── requirements.txt Python dependencies +├── pyproject.toml lint settings (ruff) ├── templates/ Jinja templates ├── static/ style.css, app.js, map.js (map and Retrace), │ picker.js (map on the report form), voice.js, @@ -260,7 +263,10 @@ ClassFind/ ├── tools/ build_campus.py, smoke.py, mutate.py ├── tests/ test_app.py, test_campus.py, test_quality.py, │ test_thumbnail_lambda.py -├── docs/ AWS setup, campus map image, screenshots +├── docs/ AWS setup and deployment guides, campus map, screenshots +├── aws/ S3 bucket policy +├── .platform/ nginx settings and the HTTPS certificate hooks +├── .ebextensions/ Elastic Beanstalk port settings for HTTPS └── .github/workflows/ CI on SQLite and PostgreSQL ``` diff --git a/app.py b/app.py index b41f2ae..052a1f0 100644 --- a/app.py +++ b/app.py @@ -1511,10 +1511,11 @@ def reject_claim(claim_id): # Words that mark a Hinglish or Kanglish sentence and carry no item details. MIXED_WORDS = { "mujhe", "mera", "meri", "mere", "maine", "humne", "ek", "mein", "me", "hai", "tha", "thi", "ho", - "mil", "mila", "mili", "mile", "gaya", "gayi", "gya", "gyi", "hogaya", "hogya", "raha", "rahi", "diya", "liya", "kho", "gum", "ko", "ka", "ki", "ke", "se", "par", "pe", "aaj", + "mil", "mila", "mili", "mile", "gaya", "gayi", "gya", "gyi", "hogaya", "hogya", "raha", "rahi", "diya", + "liya", "kho", "gum", "ko", "ka", "ki", "ke", "se", "par", "pe", "aaj", "kal", "yeh", "ye", "woh", "wo", "nanna", "nange", "nanu", "ondu", "alli", "sikkitu", "sikkide", "hoyitu", "kaledu", "kalkonde", "ivattu", "ninne", "hatra", "hathra", "andar", "bahar", "paas", - "nanagai", "nannagai", "nanngai", "nanage", "nangai", "nanna", "undu", "sikkida", "sikkidu", "sikkithu", "aytu", + "nanagai", "nannagai", "nanngai", "nanage", "nangai", "undu", "sikkida", "sikkidu", "sikkithu", "aytu", # The same words in Devanagari and Kannada script. "मुझे", "मेरा", "मेरी", "मेरे", "मैंने", "एक", "में", "है", "था", "थी", "मिल", "मिला", "मिली", "मिले", "गया", "गयी", "गई", "खो", "गुम", "को", "का", "की", "के", "से", "पर", "आज", "कल", "यह", "वह", "पास", @@ -1631,7 +1632,8 @@ def parse_report_rules(text): preposition become the location. """ lowered = text.lower() - found_words = r"\b(found|picked up|someone left|left behind|mila|mili|mile|mil gaya|mil gayi|milgaya|sikkitu|sikkide|sikkid[ae])\b" + found_words = (r"\b(found|picked up|someone left|left behind|mila|mili|mile|mil gaya|mil gayi|milgaya" + r"|sikkitu|sikkide|sikkid[ae])\b") status = "Found" if re.search(found_words, lowered) else "Lost" if any(w in text for w in FOUND_SCRIPT_WORDS) and not any(w in text for w in LOST_SCRIPT_WORDS): status = "Found" @@ -2089,15 +2091,16 @@ def ai_check(): started = time.monotonic() ok = ask_provider(provider, "Found a black notebook in the library", REPORT_PROMPT) is not None model = _found_models.get(provider[0], provider[2]) - parts.append(f"Text via {key_name} ({model}): " - + (f"working, {time.monotonic() - started:.1f}s." if ok else f"failed. {LAST_MODEL_ERROR['text']}")) + result = f"working, {time.monotonic() - started:.1f}s." if ok else f"failed. {LAST_MODEL_ERROR['text']}" + parts.append(f"Text via {key_name} ({model}): {result}") text_ok = text_ok or ok LAST_MODEL_ERROR["audio"] = "" if os.getenv("GEMINI_API_KEY", "").strip(): started = time.monotonic() audio_ok = hear_with_gemini(silent_wav()) is not None - parts.append("Voice via Gemini: " - + (f"working, {time.monotonic() - started:.1f}s." if audio_ok else f"failed. {LAST_MODEL_ERROR['audio']}")) + result = (f"working, {time.monotonic() - started:.1f}s." if audio_ok + else f"failed. {LAST_MODEL_ERROR['audio']}") + parts.append(f"Voice via Gemini: {result}") else: parts.append("Voice via Gemini: GEMINI_API_KEY is not set.") if os.getenv("GROQ_API_KEY", "").strip(): @@ -2656,7 +2659,8 @@ def prepared(items): lost_prepared = prepared(lost_items) pairs = [] - for found, found_text, found_location, found_place, found_title, found_category, found_labels in prepared(found_items): + for (found, found_text, found_location, found_place, found_title, + found_category, found_labels) in prepared(found_items): # One matcher per found title: its index of that string is built once # and reused against every lost title. matcher = SequenceMatcher(None, "", found_title) diff --git a/AWS_DEPLOYMENT.md b/docs/AWS_DEPLOYMENT.md similarity index 99% rename from AWS_DEPLOYMENT.md rename to docs/AWS_DEPLOYMENT.md index 78d279f..6e4b407 100644 --- a/AWS_DEPLOYMENT.md +++ b/docs/AWS_DEPLOYMENT.md @@ -86,4 +86,4 @@ Also demonstrate My Reports, Edit, image upload, Search/Filters, Resolve, and Ad ## Cleanup -When testing is finished, review the Elastic Beanstalk environment, RDS instance and S3 bucket so unused resources do not remain active. \ No newline at end of file +When testing is finished, review the Elastic Beanstalk environment, RDS instance and S3 bucket so unused resources do not remain active. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..79287fe --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[tool.ruff] +line-length = 120 +extend-exclude = [".v", ".venv"] + +[tool.ruff.lint] +select = ["E", "F", "W", "B"] diff --git a/static/app.js b/static/app.js index f43d992..26d32c7 100644 --- a/static/app.js +++ b/static/app.js @@ -245,4 +245,4 @@ document.addEventListener("DOMContentLoaded", () => { }, 8000); }); }); -}); \ No newline at end of file +}); diff --git a/templates/400.html b/templates/400.html index 0273492..c5b964a 100644 --- a/templates/400.html +++ b/templates/400.html @@ -8,4 +8,4 @@
{{ message }}
Back to ClassFind -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/500.html b/templates/500.html index 9c997e5..6669471 100644 --- a/templates/500.html +++ b/templates/500.html @@ -8,4 +8,4 @@The page couldn't be completed right now. Your existing reports are safe; try again in a moment.
Back to ClassFind -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/admin.html b/templates/admin.html index b17c0df..f7cd226 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -163,4 +163,4 @@