Skip to content

Commit

Permalink
fix: Linter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
antonko committed Mar 29, 2024
1 parent 2ddade6 commit 0fd2af2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
5 changes: 2 additions & 3 deletions backend/src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Settings(BaseSettings):
"""Configuration settings for the application."""

debug: bool = False

root_path: str = "/arq"
Expand All @@ -16,14 +16,13 @@ class Settings(BaseSettings):
api_prefix: str = "api"

environment: str = "production"

title: str = "Arq UI API"
version: str = "0.1.0"
summary: str = "Interface for Arq background jobs."
description: str = ""

cors_allowed_hosts: list[str] | None = ["http://localhost:5173"]


timezone: str = "UTC"

Expand Down
23 changes: 3 additions & 20 deletions backend/src/core/helpers.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
def join_paths_safely(base_path: str, relative_path: str) -> str:
"""
Joins a base path and a relative path safely, ensuring only one slash between them.
"""Joins a base path and a relative path safely, ensuring only one slash between them.
This function ensures that there's exactly one slash between the base and relative paths,
regardless of whether the base path ends with a slash or the relative path starts with one.
Parameters:
base_path (str): The base path to be joined.
relative_path (str): The relative path to append to the base path.
Returns:
str: The resulting path after safely joining the base and relative paths.
Examples:
>>> join_paths_safely('/base/path/', '/relative/path')
'/base/path/relative/path'
>>> join_paths_safely('/base/path', 'relative/path')
'/base/path/relative/path'
"""
# Remove the trailing slash from the base path if it exists, and add a leading slash to the relative path if it's missing
# Then concatenate the paths
return base_path.rstrip('/') + '/' + relative_path.lstrip('/')
return base_path.rstrip("/") + "/" + relative_path.lstrip("/")
17 changes: 11 additions & 6 deletions backend/src/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import logging
from urllib.parse import urljoin

from fastapi.staticfiles import StaticFiles

from core.config import Settings, get_app_settings
from core.exception_handler import (
Expand All @@ -15,6 +12,7 @@
from fastapi import FastAPI
from fastapi.exceptions import HTTPException, RequestValidationError
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from starlette.exceptions import HTTPException as StarletteHTTPException

logger = logging.getLogger(__name__)
Expand All @@ -29,7 +27,7 @@ def get_application() -> FastAPI:
title=settings.title,
version=settings.version,
description=settings.description,
redoc_url= join_paths_safely(settings.root_path, settings.redoc_url),
redoc_url=join_paths_safely(settings.root_path, settings.redoc_url),
docs_url=join_paths_safely(settings.root_path, settings.docs_url),
openapi_url=join_paths_safely(settings.root_path, settings.openapi_url),
summary=settings.summary,
Expand All @@ -44,14 +42,21 @@ def get_application() -> FastAPI:
allow_headers=["*"],
)

application.include_router(routers, prefix=join_paths_safely(settings.root_path, settings.api_prefix))
application.include_router(
routers,
prefix=join_paths_safely(settings.root_path, settings.api_prefix),
)

application.add_exception_handler(RequestValidationError, custom_validation_exception_handler) # type: ignore
application.add_exception_handler(HTTPException, http_exception_handler) # type: ignore
application.add_exception_handler(Exception, all_exception_handler) # type: ignore
application.add_exception_handler(StarletteHTTPException, starlette_http_exception_handler) # type: ignore

application.mount(join_paths_safely(settings.root_path, "ui"), StaticFiles(directory="static", html=True), name="static")
application.mount(
join_paths_safely(settings.root_path, "ui"),
StaticFiles(directory="static", html=True),
name="static",
)

return application

Expand Down
9 changes: 6 additions & 3 deletions frontend/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { IFetchJobsParams, IJob, IJobsInfo } from "./types";

function joinPathsSafely(basePath: string, relativePath: string): string {
const trimmedBasePath = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;
const trimmedRelativePath = relativePath.startsWith('/') ? relativePath.slice(1) : relativePath;
const trimmedBasePath = basePath.endsWith("/")
? basePath.slice(0, -1)
: basePath;
const trimmedRelativePath = relativePath.startsWith("/")
? relativePath.slice(1)
: relativePath;
return `${trimmedBasePath}/${trimmedRelativePath}`;
}

/**
* Fetches jobs from the API based on the specified parameters.
*/
export function fetchJobs(params: IFetchJobsParams = {}): Promise<IJobsInfo> {

const jobsUrl = joinPathsSafely(import.meta.env.VITE_API_HOST, "jobs");

const queryParams = new URLSearchParams();
Expand Down

0 comments on commit 0fd2af2

Please sign in to comment.