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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies = [
"matplotlib>=3.9",
"numpy>=2.0",
"pandas>=2.2",
"pyproj>=3.6",
"pyyaml>=6.0",
"rebound>=4.6,<5.0",
"reboundx>=4.6,<5.0",
Expand Down
35 changes: 35 additions & 0 deletions tests/test_declared_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Guard that third-party imports used by the package are declared dependencies.

``chained_eclipse.search`` and ``chained_eclipse.sensitivity`` both do
``from pyproj import Geod``. Before this test, ``pyproj`` was installed only as a
transitive dependency of ``cartopy``; if cartopy ever dropped or vendored it,
these imports would fail at runtime with no declared-dependency safety net.
"""

from __future__ import annotations

import importlib
import tomllib
from pathlib import Path

import pytest

PYPROJECT = Path(__file__).resolve().parents[1] / "pyproject.toml"


@pytest.mark.parametrize(
"module_name",
["chained_eclipse.search", "chained_eclipse.sensitivity"],
)
def test_pyproj_dependent_modules_import(module_name: str) -> None:
assert importlib.import_module(module_name) is not None


@pytest.mark.skipif(not PYPROJECT.exists(), reason="running from an installed wheel")
def test_pyproj_is_a_declared_runtime_dependency() -> None:
metadata = tomllib.loads(PYPROJECT.read_text(encoding="utf-8"))
declared = metadata["project"]["dependencies"]
assert any(spec.split(">")[0].split("=")[0].strip() == "pyproj" for spec in declared), (
"pyproj is imported by chained_eclipse.search and chained_eclipse.sensitivity "
"and must be declared in [project] dependencies, not relied on transitively."
)