Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.10
rev: v0.12.11
hooks:
- id: ruff
- id: ruff-format
Expand Down
6 changes: 5 additions & 1 deletion python/populse_db/engine/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def close(self, rollback=False):
else:
self.sqlite.commit()
if self.echo_sql:
print(f"Disconnect from database (rollback={rollback})", file=self.echo_sql, flush=True)
print(
f"Disconnect from database (rollback={rollback})",
file=self.echo_sql,
flush=True,
)
self.sqlite.close()

def has_collection(self, name):
Expand Down
10 changes: 6 additions & 4 deletions python/populse_db/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ def create_server():
storage_api = StorageFileAPI(database_file, create=create, secret=secret)
lock = threading.Lock()


@asynccontextmanager
async def lifespan(app: FastAPI):
cnx = sqlite3.connect(database_file, isolation_level="EXCLUSIVE")
try:
if verbose:
print("Storing external URL:", url)
rows = cnx.execute(f"SELECT _json FROM [{populse_db_table}] WHERE category='server' AND key='url'").fetchall()
rows = cnx.execute(
f"SELECT _json FROM [{populse_db_table}] WHERE category='server' AND key='url'"
).fetchall()
if rows:
existing_url = rows[0][0]
if existing_url != url:
raise RuntimeError(f"Cannot start server with URL {url} because another server already exists with URL {existing_url}")
raise RuntimeError(
f"Cannot start server with URL {url} because another server already exists with URL {existing_url}"
)
else:
cnx.execute(
f"INSERT INTO [{populse_db_table}] (category, key, _json) VALUES ('server','url',?)",
Expand Down Expand Up @@ -116,7 +119,6 @@ async def catch_exceptions_middleware(request: Request, call_next):

@app.get("/access_token")
def access_token(write: query_bool, challenge: query_str):

access_token = storage_api.access_token(write=write, challenge=challenge)
return access_token

Expand Down
4 changes: 3 additions & 1 deletion python/populse_db/test/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,9 @@ def test_storage_server():
tmp_path = tmp.name
tmp.close()
cmd = [sys.executable, "-m", "populse_db.server", "-v", tmp_path]
server = subprocess.Popen(cmd, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
server = subprocess.Popen(
cmd, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL
)

try:
store = Storage(f"server:{tmp_path}", echo_sql=sys.stdout)
Expand Down