Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/tests-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
fail-fast: true
matrix:
include:
- os: ubuntu-latest
python-version: "3.11"
- os: ubuntu-latest
python-version: "3.12"
- os: ubuntu-latest
Expand Down
15 changes: 0 additions & 15 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,7 @@
"tests"
],
"workbench.colorCustomizations": {
// Colors Based on MesoWest colors
// https://mesowest.utah.edu/
// Synoptic Blue: #2180AF
// Synoptic Green: #43A047
// Synoptic Yellow: #FADE2A
// MesoWest Red: #990000
// New Synoptic Blue: #1D4795
// New Synoptic Blue 2 : #74C1E3
// "activityBar.background": "#990000",
// "activityBarBadge.background": "#FADE2A",
// "activityBarBadge.foreground":"#2180AF",
"titleBar.activeBackground": "#1D4795"
// "titleBar.activeForeground": "#ffffff",
// "statusBar.background": "#43A047",
// "statusBarItem.remoteBackground": "#465A9B",
// "button.background": "#2180AF",
},
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import synoptic
synoptic.configure(token="yourToken123456789")
```

This creates a new file `~/.config/SynopticPy/config.toml` file with your token. Restart your Python instance, and the next time you `import synoptic` it will use the token value stored in the `config.toml` file.
This creates or updates `~/.config/SynopticPy/config.toml` and reloads the default token immediately; you do not need to restart Python.

### 3. Provide the token as an argument

Expand Down
18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
name = "SynopticPy"
description = "Retrieve mesonet weather data as Polars DataFrames from Synoptic's Weather API."
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.12"
license = { file = "LICENSE" }
authors = [{ name = "Brian K. Blaylock", email = "blaylockbk@gmail.com" }]
maintainers = [{ name = "Brian K. Blaylock", email = "blaylockbk@gmail.com" }]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
Expand All @@ -21,8 +21,8 @@ classifiers = [
]
keywords = ["weather", "meteorology", "mesonet", "atmosphere"]
dependencies = [
"numpy>=2.4.6",
"polars[plot,style,timezone]>=1.41.2",
"numpy>=2.5.3",
"polars[plot,style,timezone]>=2.0.0",
"requests>=2.34.2",
"toml>=0.10.2",
]
Expand All @@ -38,14 +38,14 @@ dynamic = ["version"]
[project.optional-dependencies]
plot = [
"altair>=5.5.0",
"cartopy>=0.25.0",
"herbie-data>=2026.3.0",
"matplotlib>=3.10.9",
"cartopy>=0.26.0",
"herbie-data>=2026.9.0",
"matplotlib>=3.11.2",
"seaborn>=0.13.2",
]
pandas = [
"pandas>=2.3.2",
"pyarrow>=24.0.0",
"pandas>=3.0.6",
"pyarrow>=25.0.1",
]

[build-system]
Expand Down
4 changes: 1 addition & 3 deletions src/synoptic/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
parse_stations_precipitation,
parse_stations_timeseries,
)
from synoptic.token import ANSI, Token, configure
from synoptic.token import ANSI, TOKEN, Token, configure
from synoptic.params import validate_params

# Initialize Token to get any environment or configured value
TOKEN = Token()
if TOKEN.token:
TOKEN.is_valid()

Expand Down
12 changes: 12 additions & 0 deletions src/synoptic/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ def _retrieve_token(self):
# or self._prompt_user_for_token()
)

def reload(self):
"""Reload the token from the environment or config file."""
self.source = "user"
self.token = self._retrieve_token()
return self

def _get_token_from_env(self):
"""Retrieve token from environment variable, if available."""
value = os.getenv("SYNOPTIC_TOKEN")
Expand Down Expand Up @@ -221,6 +227,9 @@ def is_valid(self, *, verbose=False) -> bool:
return False


TOKEN = Token()


def configure(
token: str | None = None,
hide_token: bool | None = None,
Expand Down Expand Up @@ -271,7 +280,10 @@ def configure(

# =========================
# Write new content to file
CONFIG_FILE.parent.mkdir(parents=True, exist_ok=True)
with open(CONFIG_FILE, "w") as file:
file.write(content)

TOKEN.reload()

print(f"📝 Config file updated; {ANSI.text(CONFIG_FILE, ANSI.BLUE)}.")
27 changes: 27 additions & 0 deletions tests/test_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Tests for API token configuration."""

import tomllib

import synoptic
import synoptic.services as services
import synoptic.token as token_module


def test_configure_creates_missing_config_directory(tmp_path, monkeypatch):
"""Create the config directory when saving the initial configuration."""
config_file = tmp_path / "config" / "SynopticPy" / "config.toml"
monkeypatch.setattr(token_module, "CONFIG_FILE", config_file)
monkeypatch.setattr(token_module.Token, "is_valid", lambda self: True)
monkeypatch.delenv("SYNOPTIC_TOKEN", raising=False)
existing_token = services.TOKEN

token_module.configure(token="test-token", verbose=False)

with config_file.open("rb") as file:
config = tomllib.load(file)

assert config["token"] == "test-token"
assert services.TOKEN is existing_token
assert synoptic.TOKEN is existing_token
assert services.TOKEN.token == "test-token"
assert services.TOKEN.source == "config file"
Loading
Loading