Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
2101c78
1
Parent(s): e2a36a0
Ensure old settings access still works
Browse files
src/fastmcp/settings.py
CHANGED
|
@@ -73,6 +73,8 @@ class Settings(BaseSettings):
|
|
| 73 |
dotenv_settings: PydanticBaseSettingsSource,
|
| 74 |
file_secret_settings: PydanticBaseSettingsSource,
|
| 75 |
) -> tuple[PydanticBaseSettingsSource, ...]:
|
|
|
|
|
|
|
| 76 |
return (
|
| 77 |
init_settings,
|
| 78 |
ExtendedEnvSettingsSource(settings_cls),
|
|
@@ -80,6 +82,20 @@ class Settings(BaseSettings):
|
|
| 80 |
file_secret_settings,
|
| 81 |
)
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
home: Path = Path.home() / ".fastmcp"
|
| 84 |
|
| 85 |
test_mode: bool = False
|
|
|
|
| 73 |
dotenv_settings: PydanticBaseSettingsSource,
|
| 74 |
file_secret_settings: PydanticBaseSettingsSource,
|
| 75 |
) -> tuple[PydanticBaseSettingsSource, ...]:
|
| 76 |
+
# can remove this classmethod after deprecated FASTMCP_SERVER_ prefix is
|
| 77 |
+
# removed
|
| 78 |
return (
|
| 79 |
init_settings,
|
| 80 |
ExtendedEnvSettingsSource(settings_cls),
|
|
|
|
| 82 |
file_secret_settings,
|
| 83 |
)
|
| 84 |
|
| 85 |
+
@property
|
| 86 |
+
def settings(self) -> Self:
|
| 87 |
+
"""
|
| 88 |
+
This property is for backwards compatibility with FastMCP < 2.8.0,
|
| 89 |
+
which accessed fastmcp.settings.settings
|
| 90 |
+
"""
|
| 91 |
+
# Deprecated in 2.8.0
|
| 92 |
+
warnings.warn(
|
| 93 |
+
"Using fastmcp.settings.settings is deprecated. Use fastmcp.settings instead.",
|
| 94 |
+
DeprecationWarning,
|
| 95 |
+
stacklevel=2,
|
| 96 |
+
)
|
| 97 |
+
return self
|
| 98 |
+
|
| 99 |
home: Path = Path.home() / ".fastmcp"
|
| 100 |
|
| 101 |
test_mode: bool = False
|
tests/deprecated/{test_server_init_kwargs.py → test_settings.py}
RENAMED
|
@@ -330,3 +330,22 @@ class TestDeprecatedEnvironmentVariables:
|
|
| 330 |
os.environ[env_var_name] = original_value
|
| 331 |
else:
|
| 332 |
os.environ.pop(env_var_name, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
os.environ[env_var_name] = original_value
|
| 331 |
else:
|
| 332 |
os.environ.pop(env_var_name, None)
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
class TestDeprecatedSettingsProperty:
|
| 336 |
+
"""Test deprecated settings property access."""
|
| 337 |
+
|
| 338 |
+
def test_settings_property_deprecation_warning(self):
|
| 339 |
+
"""Test that accessing fastmcp.settings.settings raises a deprecation warning."""
|
| 340 |
+
from fastmcp import settings
|
| 341 |
+
|
| 342 |
+
with pytest.warns(
|
| 343 |
+
DeprecationWarning,
|
| 344 |
+
match=r"Using fastmcp\.settings\.settings is deprecated\. Use fastmcp\.settings instead\.",
|
| 345 |
+
):
|
| 346 |
+
# Access the deprecated property
|
| 347 |
+
deprecated_settings = settings.settings
|
| 348 |
+
|
| 349 |
+
# Verify it still returns the same settings object
|
| 350 |
+
assert deprecated_settings is settings
|
| 351 |
+
assert isinstance(deprecated_settings, Settings)
|