Files
meshcore-bot/pyproject.toml
T
agessaman 595f37a27b fix(i18n): address review findings on weather localization
- Extracted `modules/alert_format.py` as the single NWS alert formatter, replacing four copies of the event-type abbreviation table and two of the time compactor. `!wx alerts` and the proactive `WeatherService` broadcasts now localize from one code path, so a Russian bot no longer answers `!wx alerts` in English while its proactive alerts are Russian.
- Stopped leaking translation key paths into mesh broadcasts. `Translator.translate` returns the dotted key when a lookup misses in both the locale and the English fallback, which is right for development but reached the air in production: an unclassifiable NWS title rendered as `Hazardous services.weather_service.event_types.Unknown`, an unmapped WMO code as `services.weather_service.weather_descriptions.4`, and an oddly-cased `wind_speed_unit` as `services.weather_service.wind_speed_units.KMH`. `alert_format.translate_or()` carries an English default at each site, and `WeatherService` now normalizes and validates its three `[Weather]` unit settings the way `GlobalWxCommand` already did.
- Fixed alert expiry rendering in every locale. The formatter rendered a timestamp to a string and re-parsed its own output with `(\d+)(AM|PM)` against a hardcoded English month list, so translated months took the wrong branch and truncated mid-string. Times now carry parsed parts and render through a per-locale `common.alerts.time_12h` template — the space before AM/PM was correct (Russian writes "6 дня", not "6дня"); the downstream regex was the bug.
- Restored month abbreviation. `_compact_time` iterated over abbreviations and replaced them in the string instead of mapping full names, so English stopped shortening "June 28" and Russian replaced the "Jun" inside "June", leaving a stray Latin "e" (`июнe 28`). Reuses the existing `common.date_time.month_abbreviations` rather than the duplicate `services.weather_service.months` block.
- Made `!gwx` display units follow `[Weather]` config instead of the response language. Visibility switched on `base_language != 'en'`, so `language = ru` with the default `temperature_unit = fahrenheit` printed Fahrenheit beside kilometers, and `en-GB` was forced to miles. Pressure is a locale convention rather than a metric/imperial split, so each catalog names its own via `commands.gwx.pressure_unit` — previously every non-English locale inherited mmHg from the English catalog, whose `pressure_mmhg` string contained Russian text, giving German and French users Cyrillic pressure units.
- Let localized `H`/`L` labels reach a standard install. `config.ini.example` shipped the three `temperature_*_format` keys uncommented with literal `H:`/`L:`, and a config value always beats the new locale-aware default, so a Russian bot built from the documented example still rendered `H:47°C L:33°C`. The example now uses the `{high_label}`/`{low_label}` placeholders, which were documented in the docstring but not in the file.
- Routed high/low labels through the reply's translator. `_format_high_low` passed `bot.translator`, so with `auto_detect_language` on, an English-default bot answering a Russian sender localized the rest of the line but not `H:`/`L:`. Added `BaseCommand.response_translator` for this, replacing `wx_international`'s reach into the private `_response_translator` ContextVar.
- Fixed a byte-budget overrun in `!gwx`. The guard on the extra conditions block compared a character count against a byte-derived budget while the rest of the function used `_count_display_width`; Cyrillic is two bytes per character, so the block was appended after the budget was spent.
- Reverted nine `commands.gwx` English rewordings that were not localization work, including the configuration hint in `mqtt_weather_no_subscriber` — dropping it left a mis-configured operator with no pointer to the two keys they need.
- Fixed the Russian `visibility` string, which said "км" on the miles key — the same locale/config conflation as the code bug, in the data. Shortened the Russian event-type abbreviations, which were full words consuming a quarter of the 130-byte budget at two bytes per character.
- Added `commands.wx.hourly_not_available`, missing from every catalog so `!wx hourly` printed the raw key path. Predates this branch; found while auditing every translation key the weather modules reference.
- Moved alert strings to `common.alerts.*` and wind directions to `common.wind_directions.*`, since a command and a service both read them.
2026-09-07 15:13:18 -07:00

213 lines
7.4 KiB
TOML

# pyproject.toml
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "meshcore-bot"
version = "1.0.0"
description = "MeshCore Bot with commands for mesh testing, utilities, and service integration."
readme = "README.md"
# Table form rather than the SPDX string form: the string form needs
# setuptools>=77, above this project's declared build requirement.
license = { text = "MIT" }
authors = [{ name = "Adam Gessaman", email = "adam@gessaman.com" }]
requires-python = ">=3.10"
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]
dependencies = [
"pyserial>=3.5",
"bleak>=0.20.0",
"asyncio-mqtt>=0.11.0",
"configparser>=5.3.0",
"python-dateutil>=2.8.2",
"apscheduler>=3.10.0",
"colorlog>=6.7.0",
"requests>=2.31.0",
"urllib3>=2.0.0",
"pyephem>=4.1.4",
"geopy>=2.3.0",
"maidenhead>=1.4.0",
"pytz>=2023.3",
"aiohttp>=3.8.0",
# 2.3.8+ required for zero-hop neighbour discovery (see requirements.txt)
"meshcore>=2.3.8",
"openmeteo-requests>=1.7.2",
"requests-cache>=1.1.1",
"retry-requests>=1.0.0",
"flask>=2.3.0",
"flask-socketio>=5.3.0",
"flask-compress>=1.14",
# Still required: `next_cmd` backs contact and channel operations that have no
# equivalent in the meshcore library yet (see requirements.txt).
"meshcore-cli>=1.4.0",
"feedparser>=6.0.10",
"paho-mqtt>=1.6.0",
"cryptography>=41.0.0",
"pynacl>=1.5.0",
"aiosqlite>=0.19.0",
]
[project.optional-dependencies]
profanity = ["better-profanity>=0.7.0", "unidecode>=1.3.0"]
geo = ["pycountry>=23.12.0", "us>=2.0.0"]
lang = ["langdetect>=1.0.9"]
test = ["pytest>=7.0", "pytest-asyncio>=0.21", "pytest-mock>=3.10", "pytest-cov>=4.0", "pytest-timeout>=2.1.0", "types-requests>=2.31"]
docs = ["mkdocs-material>=9.0.0", "mkdocs-exclude>=1.0.0"]
[project.scripts]
meshcore-bot = "meshcore_bot:main"
meshcore-viewer = "modules.web_viewer.app:main"
[tool.setuptools]
py-modules = ["meshcore_bot"]
include-package-data = false
license-files = ["LICENSE"]
[tool.setuptools.packages.find]
where = ["."]
include = ["modules*", "translations*", "data*"]
exclude = ["tests*", "local*"]
[tool.setuptools.package-data]
modules = [
"web_viewer/templates/*.html",
"web_viewer/templates/**/*.html",
"web_viewer/static/*",
"web_viewer/static/*/*",
"web_viewer/static/*/*/*",
]
translations = ["*.json"]
"data.randomlines" = ["*.txt"]
[tool.ruff]
# Match CI/Makefile installs so lint rules do not drift on unpinned `pip install ruff`.
required-version = "==0.15.15"
line-length = 120
target-version = "py310"
exclude = [".venv", "build", "dist"]
[tool.ruff.lint]
select = ["E", "F", "W", "I", "UP", "B", "C4", "SIM"]
ignore = [
"E501", # line too long (handled by formatter)
# Legacy-code tolerances — pervasive in pre-typed source, not worth a bulk churn:
"E701", # multiple-statements-on-one-line-colon
"E702", # multiple-statements-on-one-line-semicolon
"E711", # comparison-to-none (== None common in legacy)
"E712", # comparison-to-true (== True/False common in legacy)
"E722", # bare-except (used extensively in graceful-degradation patterns)
"E741", # ambiguous-variable-name (l, O, I in legacy loops)
"E402", # module-level import not at top (conditional imports pattern)
"F601", # multi-value-repeated-key-literal (legacy dict pattern)
"B007", # unused-loop-control-variable (rename to _ is a bulk churn)
"B023", # function-uses-loop-variable (legacy closures in packet capture)
"B904", # raise-without-from-in-except (legacy raise pattern)
"C408", # unnecessary-collection-call
"C414", # unnecessary-double-cast-or-process
# pyupgrade rules that would require a bulk typing rewrite — deferred to a code-quality PR:
"UP007", # non-pep604-annotation-union (Union[X, Y] -> X | Y)
"UP035", # deprecated-import (typing.List/Dict/... remain prevalent)
"UP041", # timeout-error-alias (socket.timeout -> TimeoutError)
"UP045", # non-pep604-annotation-optional (Optional[X] -> X | None)
# Simplification suggestions — stylistic, not enforced on legacy code:
"SIM102", # collapsible-if
"SIM103", # needless-bool
"SIM105", # suppressible-exception
"SIM108", # if-else-block-instead-of-if-exp (ternary preference is subjective)
"SIM109", # compare-with-tuple
"SIM110", # reimplemented-builtin
"SIM114", # if-with-same-arms
"SIM115", # open-file-with-context-handler
"SIM117", # multiple-with-statements
"SIM210", # if-expr-with-true-false
]
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101"]
# ---------------------------------------------------------------------------
# mypy — incremental strict mode
# ---------------------------------------------------------------------------
# Global baseline: safe non-breaking options.
# Per-module overrides below tighten settings for fully-typed modules.
[tool.mypy]
python_version = "3.11"
ignore_missing_imports = true
warn_unused_ignores = true
warn_return_any = false # too noisy until all modules are annotated
warn_unused_configs = true
no_implicit_optional = true
strict_optional = true
# New modules written with full type annotations get strict treatment.
[[tool.mypy.overrides]]
module = [
"modules.alert_format",
"modules.commands.schedule_command",
"modules.service_plugins.webhook_service",
"modules.service_plugins.base_service",
"modules.message_handler",
"modules.utils",
"modules.plugin_loader",
"modules.security_utils",
"modules.commands.base_command",
"modules.commands.rain_command",
]
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true
no_implicit_optional = true
# Modules with known type errors not yet brought up to strict standard.
# Suppress all mypy errors for these modules until they are fully annotated.
[[tool.mypy.overrides]]
module = [
"modules.core",
"modules.command_manager",
"modules.feed_manager",
"modules.mesh_graph",
"modules.scheduler",
"modules.maintenance",
"modules.transmission_tracker",
"modules.commands.alert_command",
"modules.commands.announcements_command",
"modules.commands.aurora_command",
"modules.commands.channels_command",
"modules.commands.greeter_command",
"modules.commands.help_command",
"modules.commands.joke_command",
"modules.commands.multitest_command",
"modules.commands.prefix_command",
"modules.commands.wx_command",
"modules.commands.alternatives.wx_international",
"modules.commands.trace_command",
"modules.commands.solarforecast_command",
"modules.commands.roll_command",
"modules.commands.repeater_command",
"modules.commands.path_command",
"modules.commands.sports_command",
"modules.commands.aqi_command",
"modules.service_plugins.discord_bridge_service",
"modules.service_plugins.packet_capture_service",
"modules.service_plugins.weather_service",
"modules.web_viewer.app",
"modules.web_viewer.integration",
]
ignore_errors = true
# Pytest is configured in pytest.ini, not here. pytest.ini takes precedence over
# pyproject.toml, so a [tool.pytest.ini_options] block in this file would be dead
# config that silently drifts from the settings actually in effect.
[tool.coverage.run]
source = ["modules"]
omit = ["tests/*", ".venv/*"]
[tool.coverage.report]
fail_under = 50
show_missing = true