HamidOmarov commited on
Commit
2690221
·
1 Parent(s): 1171cba

fix(runtime): strip U+FEFF (BOM/ZWNBSP) from Python sources

Browse files
app.py CHANGED
@@ -1,3 +1,3 @@
1
- # app.py (repo kГ¶kГјndЙ™)
2
  from app.api import app # FastAPI instance
3
 
 
1
+ # app.py (repo kГ¶kГјndЙ™)
2
  from app.api import app # FastAPI instance
3
 
app/__init__.py CHANGED
@@ -1 +0,0 @@
1
- 
 
 
app/api.py CHANGED
@@ -1,6 +1,6 @@
1
  from app.storage import DATA_DIR, INDEX_DIR, HISTORY_JSON
2
 
3
- from app.storage import DATA_DIR, INDEX_DIR, HISTORY_JSON
4
 
5
 
6
 
 
1
  from app.storage import DATA_DIR, INDEX_DIR, HISTORY_JSON
2
 
3
+ from app.storage import DATA_DIR, INDEX_DIR, HISTORY_JSON
4
 
5
 
6
 
app/metrics.py CHANGED
@@ -1,4 +1,4 @@
1
- from collections import deque, defaultdict
2
  from datetime import datetime, timedelta, timezone
3
 
4
  class StatsTracker:
 
1
+ from collections import deque, defaultdict
2
  from datetime import datetime, timedelta, timezone
3
 
4
  class StatsTracker:
app/paths.py CHANGED
@@ -1,4 +1,4 @@
1
- import os
2
  from pathlib import Path
3
  DATA_DIR = Path(os.getenv("DATA_DIR", str(DATA_DIR)))
4
  DATA_DIR.mkdir(parents=True, exist_ok=True)
 
1
+ import os
2
  from pathlib import Path
3
  DATA_DIR = Path(os.getenv("DATA_DIR", str(DATA_DIR)))
4
  DATA_DIR.mkdir(parents=True, exist_ok=True)
app/rag/__init__.py CHANGED
@@ -1 +0,0 @@
1
- 
 
 
app/rag_system.py CHANGED
@@ -1,4 +1,4 @@
1
- # app/rag_system.py
2
  from __future__ import annotations
3
 
4
  import os
 
1
+ # app/rag_system.py
2
  from __future__ import annotations
3
 
4
  import os
app/routes_stats.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import APIRouter
2
  from .metrics import tracker
3
 
4
  router = APIRouter()
 
1
+ from fastapi import APIRouter
2
  from .metrics import tracker
3
 
4
  router = APIRouter()
app/schemas.py CHANGED
@@ -1,4 +1,4 @@
1
- # app/schemas.py
2
  from pydantic import BaseModel, Field
3
  from typing import Optional, List
4
 
 
1
+ # app/schemas.py
2
  from pydantic import BaseModel, Field
3
  from typing import Optional, List
4
 
app/store.py CHANGED
@@ -1,4 +1,4 @@
1
- # app/store.py
2
  from collections import defaultdict
3
  from typing import List, Dict
4
 
 
1
+ # app/store.py
2
  from collections import defaultdict
3
  from typing import List, Dict
4
 
app/utils.py CHANGED
@@ -1,4 +1,4 @@
1
- # app/utils.py
2
  import uuid
3
  from fastapi import HTTPException
4
 
 
1
+ # app/utils.py
2
  import uuid
3
  from fastapi import HTTPException
4
 
boot.py CHANGED
@@ -1,4 +1,4 @@
1
- import os, sys, importlib
2
  import uvicorn
3
 
4
  candidates = [
 
1
+ import os, sys, importlib
2
  import uvicorn
3
 
4
  candidates = [
fix_api_imports.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re, pathlib
2
+
3
+ p = pathlib.Path("app/api.py")
4
+ s = p.read_text(encoding="utf-8")
5
+ lines = s.splitlines()
6
+
7
+ n = len(lines)
8
+ i = 0
9
+
10
+ # --- Shebang / encoding sətirlərini saxla
11
+ header = []
12
+ while i < n and (lines[i].startswith("#!") or re.search(r"coding[:=]\s*[-\w.]+", lines[i])):
13
+ header.append(lines[i]); i += 1
14
+
15
+ # --- Docstring varsa götür (yalnız faylın əvvəlində olanda)
16
+ doc_block = []
17
+ if i < n and re.match(r'^\s*(?P<q>"""|\'\'\')', lines[i]):
18
+ q = '"""' if lines[i].strip().startswith('"""') else "'''"
19
+ doc_block.append(lines[i]); i += 1
20
+ while i < n:
21
+ doc_block.append(lines[i])
22
+ if q in lines[i]:
23
+ i += 1
24
+ break
25
+ i += 1
26
+
27
+ # --- Qalan hissədən __future__ importlarını çək
28
+ future_re = re.compile(r'^\s*from __future__ import ')
29
+ futures, rest = [], []
30
+ for ln in lines[i:]:
31
+ if future_re.match(ln):
32
+ futures.append(ln.rstrip())
33
+ else:
34
+ rest.append(ln)
35
+
36
+ # unikallaşdır
37
+ seen = set(); futures = [x for x in futures if not (x in seen or seen.add(x))]
38
+
39
+ # --- Köhnə storage importlarını təmizlə
40
+ rest = [ln for ln in rest if not re.match(r'^\s*from app\.storage import ', ln)]
41
+
42
+ storage_line = 'from app.storage import DATA_DIR, INDEX_DIR, HISTORY_JSON'
43
+
44
+ out = []
45
+ out += header
46
+ if header and (doc_block or futures or storage_line): out.append('')
47
+ out += doc_block
48
+ if doc_block and (futures or storage_line): out.append('')
49
+ out += futures
50
+ if futures: out.append(storage_line)
51
+ else:
52
+ # futures yoxdursa, storage-ı docstringdən sonra qoyuruq
53
+ if doc_block: out.append(storage_line)
54
+ else: out.append(storage_line)
55
+ # importlardan sonra boş sətir
56
+ out.append('')
57
+
58
+ # qalan hissə
59
+ out += rest
60
+
61
+ txt = '\n'.join(out).rstrip() + '\n'
62
+ p.write_text(txt, encoding="utf-8")
63
+ print("OK: rearranged", p)
main.py CHANGED
@@ -1,4 +1,4 @@
1
- # --- ADD: /generate alias for compatibility ---
2
  from fastapi import Form
3
 
4
  @app.post("/generate")
 
1
+ # --- ADD: /generate alias for compatibility ---
2
  from fastapi import Form
3
 
4
  @app.post("/generate")
strip_bom.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pathlib
2
+
3
+ def clean_file(path: pathlib.Path):
4
+ b = path.read_bytes()
5
+ # BOM-u (əgər faylın əvvəlindədirsə) kənarlaşdırmaq üçün utf-8-sig ilə oxu
6
+ try:
7
+ s = b.decode("utf-8-sig")
8
+ except UnicodeDecodeError:
9
+ s = b.decode("utf-8", errors="ignore")
10
+ changed = False
11
+ if "\ufeff" in s: # sətir içi FEFF-ləri də sil
12
+ s = s.replace("\ufeff", "")
13
+ changed = True
14
+ # Əgər başlanğıcda BOM vardısa, utf-8-sig artıq onu çıxarıb; yazarkən BOMsuz yaz
15
+ if changed or b[:3] == b"\xef\xbb\xbf":
16
+ path.write_text(s, encoding="utf-8", newline="\n")
17
+ print(f"cleaned: {path}")
18
+ return 1
19
+ return 0
20
+
21
+ changed = 0
22
+ # app/ altındakı bütün .py fayllar
23
+ for p in pathlib.Path("app").rglob("*.py"):
24
+ changed += clean_file(p)
25
+
26
+ # kökdə .py varsa, onları da yoxla (opsional)
27
+ for p in pathlib.Path(".").glob("*.py"):
28
+ changed += clean_file(p)
29
+
30
+ print("total_changed:", changed)