Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ensaremirerol committed Dec 4, 2024
1 parent b3b603d commit 937c13a
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 192 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.12
3.11
17 changes: 10 additions & 7 deletions app/src/lib/api/workspaces_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class WorkspacesApi {

public static async getWorkspaces(): Promise<WorkspaceMetadata[]> {
const result = await this.getApiClient().callApi<WorkspaceMetadata[]>(
'/workspaces',
'/workspaces_metadata/',
{
method: 'GET',
parser: data => data as WorkspaceMetadata[],
Expand All @@ -27,11 +27,14 @@ class WorkspacesApi {
public static async createWorkspace(
workspace: CreateWorkspaceMetadata,
): Promise<boolean> {
const result = await this.getApiClient().callApi<boolean>('/workspaces', {
method: 'POST',
body: workspace,
parser: () => true,
});
const result = await this.getApiClient().callApi<boolean>(
'/workspaces_metadata/',
{
method: 'POST',
body: workspace,
parser: () => true,
},
);

if (result.type === 'success') {
return result.data;
Expand All @@ -44,7 +47,7 @@ class WorkspacesApi {

public static async deleteWorkspace(uuid: string): Promise<boolean> {
const result = await this.getApiClient().callApi<boolean>(
`/workspaces/${uuid}`,
`/workspaces_metadata/${uuid}`,
{
method: 'DELETE',
parser: () => true,
Expand Down
11 changes: 6 additions & 5 deletions app/src/lib/services/api_service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import axios, { AxiosInstance } from 'axios';
import { ApiCallOptions, ApiCallResult } from './types';

class ApiService {
private baseUrl: string;
private client: AxiosInstance;
// @ts-expect-error - private
private readonly _baseUrl: string;
private readonly _client: AxiosInstance;

private static instances: Record<string, ApiService> = {};

private constructor(baseUrl: string) {
this.baseUrl = baseUrl;
this.client = axios.create({
this._baseUrl = baseUrl;
this._client = axios.create({
baseURL: baseUrl,
});
}
Expand All @@ -35,7 +36,7 @@ class ApiService {
options: ApiCallOptions<T>,
): Promise<ApiCallResult<T>> {
try {
const response = await this.client.request({
const response = await this._client.request({
url: endpoint,
method: options.method,
data: options.body,
Expand Down
7 changes: 1 addition & 6 deletions app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import './index.scss';
import App from './app';
import ApiService from './lib/services/api_service';

// If development mode is enabled

if (import.meta.env.MODE === 'development') {
// Enable React strict mode
ApiService.registerWithNamespace('default', 'http://localhost:8000/api/');
}
ApiService.registerWithNamespace('default', 'http://localhost:8000/api/');

createRoot(document.getElementById('root')!).render(<App />);
23 changes: 23 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
install-dev:
@echo "Creating virtual environment..."
uv sync --all-extras --dev

install:
@echo "Creating virtual environment..."
uv sync

test: install-dev
@echo "Running tests..."
uv run coverage run -m unittest discover -v -s ./test -p "*_test.py"

package-mac: install-dev
@echo "Packaging for macOS..."
rm -rf build dist public
npm run frontend:prod
uv run nuitka \
--standalone \
--output-dir=dist \
--include-data-dir=public=public \
--macos-create-app-bundle \
--enable-console \
main.py
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def start_fastapi():
def on_closing():
global thread
if thread:
thread.join(timeout=10)
thread.join(timeout=0)
os._exit(0)


Expand All @@ -58,6 +58,6 @@ def on_closing():
resizable=True,
)
window.events.closing += on_closing
webview._settings["debug"] = True
webview.start()
# Send kill signal to server thread
thread.join()

10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "A Python project for RDF crafting"
authors = [
{ name = "Ensar Emir EROL", email = "[email protected]" }
]
requires-python = "==3.12.7"
requires-python = "==3.11.10"

dependencies = [
"annotated-types==0.7.0",
Expand Down Expand Up @@ -34,6 +34,7 @@ dependencies = [
"markdown-it-py==3.0.0",
"MarkupSafe==3.0.2",
"mdurl==0.1.2",
"nuitka>=2.5.4",
"numpy==2.1.2",
"opentelemetry-api==1.28.0",
"packaging==24.2",
Expand All @@ -42,7 +43,7 @@ dependencies = [
"proxy_tools==0.1.0",
"pydantic==2.9.2",
"pydantic_core==2.23.4",
"Pygments==2.18.0",
"pygments==2.18.0",
"pyobjc-core==10.3.1; sys_platform == 'darwin'",
"pyobjc-framework-Cocoa==10.3.1; sys_platform == 'darwin'",
"pyobjc-framework-Quartz==10.3.1; sys_platform == 'darwin'",
Expand All @@ -57,6 +58,7 @@ dependencies = [
"PyYAML==6.0.2",
"rdflib==7.1.0",
"rich==13.9.2",
"setuptools==70.3.0",
"shellingham==1.5.4",
"six==1.16.0",
"sniffio==1.3.1",
Expand All @@ -72,7 +74,7 @@ dependencies = [
"websockets==13.1",
"wrapt==1.16.0",
"xmltodict==0.14.2",
"zipp==3.20.2"
"zipp==3.20.2",
]

[dependency-groups]
Expand All @@ -96,4 +98,4 @@ exclude_also = [
"from .* import .*",
"import .*",
"return self.__repr__\\(\\)",
]
]
8 changes: 4 additions & 4 deletions server/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def handle_exception(
)
return

root_logger.error(
"Uncaught exception",
exc_info=(exc_type, exc_value, exc_traceback),
)
# root_logger.error(
# "Uncaught exception",
# exc_info=(exc_type, exc_value, exc_traceback),
# )

sys.excepthook = handle_exception
38 changes: 16 additions & 22 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,23 @@ async def get_data():
return {"message": "Hello from FastAPI!"}


if DEBUG:
logger.info(
"Debug mode enabled, skipping window creation"
)
logger.info("Disabling CORS")
from fastapi.middleware.cors import CORSMiddleware

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
logger.info("CORS disabled")
from fastapi.middleware.cors import CORSMiddleware

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
logger.info("CORS disabled")


app.include_router(
workspaces_router,
prefix="/api/workspaces_metadata",
tags=["workspaces_metadata"],
)

if not DEBUG:
# Serve the React app
Expand All @@ -153,10 +154,3 @@ async def get_data():
StaticFiles(directory=build_dir, html=True),
name="static",
)


app.include_router(
workspaces_router,
prefix="/api/workspaces_metadata",
tags=["workspaces_metadata"],
)
2 changes: 1 addition & 1 deletion server/services/core/sqlite_db_service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(
self,
APP_DIR: Path,
):
self._db_path = f"sqlite:///{(APP_DIR / "db.sqlite").absolute()}"
self._db_path = f"sqlite:///{(APP_DIR / 'db.sqlite').absolute()}"
if not APP_DIR.exists():
APP_DIR.mkdir()
self._engine = create_engine(
Expand Down
Loading

0 comments on commit 937c13a

Please sign in to comment.