From 8792f15df88ef10bb9ab405909dcda318b6aad7a Mon Sep 17 00:00:00 2001 From: falamarcao Date: Sat, 9 Aug 2025 05:13:21 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20fix:=20I=20think=20I=20finally?= =?UTF-8?q?=20found=20the=20pyproject.toml=20file.=20Hopefully.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- src/app/common/toml.py | 31 +++++++++++++++++++++++-------- uv.lock | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bd07a6b..3d408a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ [project] name = "mcp-selenium-grid" -version = "0.1.0.dev3" +version = "0.1.0.dev4" description = "MCP Server for managing Selenium Grid" readme = "README.md" license = { file = "LICENSE" } diff --git a/src/app/common/toml.py b/src/app/common/toml.py index 9f78e9f..77ff3e3 100644 --- a/src/app/common/toml.py +++ b/src/app/common/toml.py @@ -1,14 +1,27 @@ -from os import getcwd from pathlib import Path from tomllib import load from typing import Any -ROOT_DIR = Path(getcwd()).resolve() +def find_pyproject_toml() -> Path: + """ + Walks up the directory tree to find the project root + by looking for a pyproject.toml file. + """ + project_root = None + + current_dir = Path(__file__).resolve() + for parent in current_dir.parents: + if (parent / "pyproject.toml").is_file(follow_symlinks=False): + project_root = parent + break + + if project_root: + return project_root / "pyproject.toml" + return Path() -def load_value_from_toml( - keys: list[str], file_path: Path = ROOT_DIR / "pyproject.toml", default: Any = None -) -> Any: + +def load_value_from_toml(keys: list[str], default: str = "") -> Any: """ Load a nested value from a TOML file. @@ -24,10 +37,12 @@ def load_value_from_toml( FileNotFoundError: If the file doesn't exist and no default is provided. ValueError: If the keys are missing and no default is provided. """ - if not file_path.exists(): - if default is not None: + file_path = find_pyproject_toml() + + if not file_path.is_file(follow_symlinks=False): + if default: return default - raise FileNotFoundError(f"{file_path} not found") + raise FileNotFoundError("File pyproject.toml not found") try: with file_path.open("rb") as f: diff --git a/uv.lock b/uv.lock index ab3e614..66ae1a6 100644 --- a/uv.lock +++ b/uv.lock @@ -583,7 +583,7 @@ wheels = [ [[package]] name = "mcp-selenium-grid" -version = "0.1.0.dev3" +version = "0.1.0.dev4" source = { editable = "." } dependencies = [ { name = "docker" },