-
Notifications
You must be signed in to change notification settings - Fork 13
Pooria/1024 railtracks folder #1110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7275bee
01fbc93
ff00ab8
c882f04
61413a7
11c46b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
|
|
||
| cli_name = "railtracks" | ||
| cli_directory = ".railtracks" | ||
| UI_VERSION_FILE = f"{cli_directory}/.ui_version" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constant is used by the CLI to detect the user's version of the visualizer UI vs the most recently published version and warns the user to update to get new features |
||
| DEFAULT_PORT = 3030 | ||
|
|
||
| # TODO: Once we are releasing to PyPi change this to the release asset instead | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,15 +10,17 @@ | |
| from fastapi import FastAPI | ||
| from fastapi.responses import FileResponse, JSONResponse | ||
|
|
||
| from .constants import DEFAULT_PORT, cli_directory | ||
| from railtracks.paths import resolve_railtracks_home | ||
|
|
||
| from .constants import DEFAULT_PORT | ||
| from .io import print_error, print_status, print_success, print_warning | ||
|
|
||
| app = FastAPI() | ||
|
|
||
|
|
||
| def get_railtracks_dir() -> Path: | ||
| """Get the .railtracks directory path""" | ||
| return Path(cli_directory) | ||
| return resolve_railtracks_home() | ||
|
|
||
|
|
||
| def get_data_dir(subdir: str) -> Path: | ||
|
|
@@ -93,7 +95,7 @@ async def serve_ui_or_404(full_path: str): | |
| if full_path.startswith("api/"): | ||
| return JSONResponse(content={"error": "Not Found"}, status_code=404) | ||
|
|
||
| ui_dir = Path(f"{cli_directory}/ui") | ||
| ui_dir = get_railtracks_dir() / "ui" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this make it |
||
| ui_file = ui_dir / full_path | ||
| if ui_file.exists() and ui_file.is_file(): | ||
| return FileResponse(str(ui_file)) | ||
|
|
@@ -116,7 +118,7 @@ def start(self): | |
| self.running = True | ||
|
|
||
| print_success(f"🚀 railtracks server running at http://localhost:{self.port}") | ||
| print_status(f"📁 Serving files from: {cli_directory}/ui/") | ||
| print_status(f"📁 Serving files from: {get_railtracks_dir() / 'ui'}") | ||
| print_status("📋 API endpoints:") | ||
| print_status(" GET /api/evaluations - Get all evaluation JSON files") | ||
| print_status(" GET /api/sessions - Get all session JSON files") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import os | ||
| import warnings | ||
| from pathlib import Path | ||
|
|
||
| _DIRNAME = ".railtracks" | ||
|
|
||
|
|
||
| def resolve_railtracks_home() -> Path: | ||
| """Return the .railtracks directory path. | ||
|
|
||
| Resolution order: | ||
| 1. RAILTRACKS_HOME env var — .railtracks is created inside this directory. | ||
| 2. Walk up from cwd() looking for an existing .railtracks directory. | ||
| 3. Fall back to cwd()/.railtracks with a UserWarning. | ||
| """ | ||
| env = os.environ.get("RAILTRACKS_HOME") | ||
| if env: | ||
| return Path(env) / _DIRNAME | ||
|
|
||
| current = Path.cwd() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be fine in Windows too, right? (Cross-operating system file paths) |
||
| for directory in [current, *current.parents]: | ||
| candidate = directory / _DIRNAME | ||
| if candidate.is_dir(): | ||
| return candidate | ||
|
|
||
| fallback = current / _DIRNAME | ||
| warnings.warn( | ||
| f"No {_DIRNAME!r} directory found in '{current}' or any parent directory. " | ||
| f"Data will be written to '{fallback}'. " | ||
| f"Run 'railtracks init' from your project root to set a permanent location.", | ||
| UserWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return fallback | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here and below regarding UI_VERSION constant
it's a file inside
.railtracks