From 4fb06191cfc566e0a84f1999ade36825c0578f5c Mon Sep 17 00:00:00 2001 From: Wolf Date: Tue, 29 Sep 2026 19:44:03 +0200 Subject: [PATCH] Load the host modules when the registry reads ats.py by path without the repo root on sys.path Co-Authored-By: Claude Opus 5.5 --- app/models.py | 2 +- plugins/__init__.py | 12 +++++++----- plugins/ats.py | 13 ++++++++++++- tests/test_atshosts.py | 18 ++++++++++++++++++ 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/models.py b/app/models.py index f398496..3378751 100644 --- a/app/models.py +++ b/app/models.py @@ -651,7 +651,7 @@ AFFINITY = range(-1, 3) #: read as when a role was posted, checked against live boards on #: 2026-09-29: #: -#: - `greenhouse`: `plugins.ats._parse_greenhouse` already prefers +#: - `greenhouse`: `plugins.atshosts.greenhouse.parse` already prefers #: `first_published` over `updated_at`. A live board (adyen) showed a job #: with `first_published` five months before `updated_at`, proving the #: first stays fixed while the second moves on an edit — the resettable diff --git a/plugins/__init__.py b/plugins/__init__.py index 5433535..94ff7ff 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -1,8 +1,10 @@ """Drop-in plugins, discovered by `plugin_paths` in `config.yaml`. -A plugin file imports `desk` only — see `tests/test_architecture.py`. This -`__init__.py` makes the directory importable as `plugins.` for the rest -of roledesk (`jobs/pull.py`, `cli.py`, the tests), which the plugin contract -itself never relies on: `desk.sources.registry` finds `ats.py` by path, not -by this package. +A plugin file imports `desk` only — see `tests/test_architecture.py` — and +its own helpers in this directory. This `__init__.py` makes the directory +importable as `plugins.`, for the rest of roledesk (`jobs/pull.py`, +`cli.py`, the tests) and for `ats.py`, whose hosts are the modules of the +package `plugins/atshosts/`. `desk.sources.registry` still finds `ats.py` by +path, not by this package; `ats.py` puts the repo root on `sys.path` itself +when the app has not, so that `plugins.atshosts` imports either way. """ diff --git a/plugins/ats.py b/plugins/ats.py index 422570e..14bfd7e 100644 --- a/plugins/ats.py +++ b/plugins/ats.py @@ -33,10 +33,12 @@ import ipaddress import json import logging import re +import sys import time from collections.abc import Callable, Iterator, MutableMapping from datetime import UTC, datetime, timedelta from typing import Any +from pathlib import Path from urllib.parse import unquote import httpx @@ -46,7 +48,16 @@ from desk.sources import ( SummaryPolicy, TaggingPolicy, TargetSpec, Tasks, USER_AGENT, ) -from plugins import atshosts +try: + from plugins import atshosts +except ModuleNotFoundError: + # `desk.sources.registry` loads this file by its path, under a name of its + # own, and the app puts the repo root on `sys.path` before it does; a + # registry run without the app (a script, another working directory) + # does not, and the host modules are found as the package beside this + # file. So the root goes on the path then, and only then. + sys.path.insert(0, str(Path(__file__).resolve().parents[1])) + from plugins import atshosts from plugins.atshosts._shared import Get, Row # The names the parsers had here before they moved to their host modules, diff --git a/tests/test_atshosts.py b/tests/test_atshosts.py index b5dd9dc..92e5bb4 100644 --- a/tests/test_atshosts.py +++ b/tests/test_atshosts.py @@ -6,6 +6,8 @@ a fake host stands in where a behaviour belongs to no real host yet.""" from __future__ import annotations import json +import os +import subprocess import sys import types from collections.abc import Callable @@ -63,6 +65,22 @@ def parse(body, slug): return [] """ +def test_the_registry_loads_ats_by_path_without_the_repo_root_on_the_path( + tmp_path: Path) -> None: + """As `desk.sources.registry` does in a process the app did not set up: + another working directory, and `plugins` not importable at first.""" + code = ( + "import importlib.util, sys\n" + "assert importlib.util.find_spec('plugins') is None, 'plugins is importable'\n" + "from desk.sources import registry\n" + f"print(sorted(registry.available([{str(ROOT / 'plugins')!r}])))\n") + env = {k: v for k, v in os.environ.items() if k != "PYTHONPATH"} + done = subprocess.run([sys.executable, "-c", code], cwd=tmp_path, env=env, + capture_output=True, text=True, timeout=60, check=False) + assert done.returncode == 0, done.stderr + assert "'ats'" in done.stdout and "'search'" in done.stdout + + def test_the_registry_loads_a_package_by_name_and_skips_private_modules( tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: path = _package(tmp_path, monkeypatch, "hostsok", {