Order the hosts by a RANK per module, which restores the select's and the probes' order from before the modules

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-29 19:38:18 +02:00
1 parent 75a389d725
commit a9fb4397ac
11 files changed
+71 -8

No files matched your search

+14 -6
View File
@@ -53,6 +53,10 @@ import re
from collections.abc import Iterable
from types import ModuleType
#: The rank of a module that states none: after the eight first hosts, whose
#: ranks (10 to 80) keep the order they had before there were modules.
DEFAULT_RANK = 100
#: What every host module defines.
REQUIRED = ("NAME", "LABEL", "PATTERNS", "slug_ok", "allowed", "careers_url")
@@ -72,6 +76,9 @@ def problems(module: ModuleType, name: str | None = None) -> list[str]:
out.append("LABEL is not a non-empty string")
if not isinstance(getattr(module, "KEEP_CASE", False), bool):
out.append("KEEP_CASE is not a bool")
rank = getattr(module, "RANK", DEFAULT_RANK)
if not isinstance(rank, int) or isinstance(rank, bool):
out.append("RANK is not an int")
patterns = getattr(module, "PATTERNS", ())
if isinstance(patterns, str) or not isinstance(patterns, Iterable):
out.append("PATTERNS is not a tuple of strings")
@@ -97,9 +104,9 @@ def problems(module: ModuleType, name: str | None = None) -> list[str]:
def load(path: Iterable[str], package: str) -> dict[str, ModuleType]:
"""`NAME -> module` for every module of `package` (found on `path`) whose
name does not start with `_`, sorted by name. Raises ImportError naming
the first module that breaks the contract."""
hosts: dict[str, ModuleType] = {}
name does not start with `_`, in order of `(RANK, NAME)`. Raises
ImportError naming the first module that breaks the contract."""
modules: list[ModuleType] = []
for info in sorted(pkgutil.iter_modules(path), key=lambda info: info.name):
if info.name.startswith("_"):
continue
@@ -107,9 +114,10 @@ def load(path: Iterable[str], package: str) -> dict[str, ModuleType]:
if found := problems(module, info.name):
raise ImportError(f"{package}.{info.name} breaks the host contract: "
+ "; ".join(found))
hosts[module.NAME] = module
return hosts
modules.append(module)
modules.sort(key=lambda module: (getattr(module, "RANK", DEFAULT_RANK), module.NAME))
return {module.NAME: module for module in modules}
#: host -> its module, in order of name.
#: host -> its module, in order of `(RANK, NAME)`.
HOSTS: dict[str, ModuleType] = load(__path__, __name__)
+1
View File
@@ -17,6 +17,7 @@ from ._shared import Row, is_web_url, num, only, parse_dt, path_slug_ok, pay_lin
NAME = "ashby"
LABEL = "Ashby"
RANK = 30
PATTERNS = (
r"jobs\.ashbyhq\.com/([A-Za-z0-9_.-]+)",
r"api\.ashbyhq\.com/posting-api/job-board/([A-Za-z0-9_.-]+)",
+1
View File
@@ -17,6 +17,7 @@ from ._shared import Row, is_web_url, num, only, parse_dt, path_slug_ok, pay_lin
NAME = "greenhouse"
LABEL = "Greenhouse"
RANK = 10
PATTERNS = (
r"(?:boards|job-boards|api)\.(?:eu\.)?greenhouse\.io/(?:v1/boards/|embed/job_board\?[^\"'\s]*for=)?([A-Za-z0-9_-]+)",
r"greenhouse\.io/embed/job_board/js\?for=([A-Za-z0-9_-]+)",
+1
View File
@@ -25,6 +25,7 @@ from ._shared import Row, is_web_url, num, only, parse_dt, path_slug_ok, pay_lin
NAME = "lever"
LABEL = "Lever"
RANK = 20
#: Two groups on the EU hosts, `eu` and the site, which discovery joins into
#: the slug `eu/<site>`.
PATTERNS = (
+1
View File
@@ -16,6 +16,7 @@ from ._shared import Row, label_slug_ok, num, only, parse_dt, pay_line, yearly_a
NAME = "personio"
LABEL = "Personio"
RANK = 70
PATTERNS = (r"https?://([a-z0-9-]+)\.jobs\.personio\.(?:de|com)",)
#: Personio's `salaryInformation/type` spellings, to the plain period word
+1
View File
@@ -17,6 +17,7 @@ from ._shared import Row, is_web_url, label_slug_ok, num, only, parse_dt, pay_li
NAME = "recruitee"
LABEL = "Recruitee"
RANK = 60
PATTERNS = (r"https?://([a-z0-9-]+)\.recruitee\.com",)
+1
View File
@@ -15,6 +15,7 @@ from ._shared import Get, Page, Row, only, parse_dt, path_slug_ok
NAME = "smartrecruiters"
LABEL = "SmartRecruiters"
RANK = 50
PATTERNS = (
r"(?:jobs|careers|api)\.smartrecruiters\.com/(?:v1/companies/)?([A-Za-z0-9_-]+)",
)
+1
View File
@@ -20,6 +20,7 @@ from ._shared import Get, Page, Row, is_web_url, only, parse_dt
NAME = "teamtailor"
LABEL = "Teamtailor"
RANK = 80
PATTERNS = (
r"https?://([a-z0-9-]+)\.teamtailor\.com",
# No slug: a career site on the company's own domain, which only loads
+1
View File
@@ -15,6 +15,7 @@ from ._shared import Get, Page, Row, only, parse_dt, path_slug_ok
NAME = "workable"
LABEL = "Workable"
RANK = 40
PATTERNS = (
r"apply\.workable\.com/(?:api/v\d/accounts/)?([A-Za-z0-9_-]+)",
r"https?://(?!apply\.|www\.)([a-z0-9-]+)\.workable\.com",
+26 -2
View File
@@ -28,10 +28,10 @@ FIXTURES = ROOT / "tests" / "fixtures" / "ats"
# --------------------------------------------------------------- registry
def test_the_registry_finds_every_module_in_order_of_name() -> None:
def test_the_registry_finds_every_module() -> None:
names = sorted(p.stem for p in (ROOT / "plugins" / "atshosts").glob("*.py")
if not p.stem.startswith("_"))
assert list(atshosts.HOSTS) == names
assert sorted(atshosts.HOSTS) == names
assert set(names) >= {"greenhouse", "lever", "ashby", "workable", "smartrecruiters",
"recruitee", "personio", "teamtailor"}
assert all(not atshosts.problems(module, name) for name, module in atshosts.HOSTS.items())
@@ -71,6 +71,28 @@ def test_the_registry_loads_a_package_by_name_and_skips_private_modules(
assert list(atshosts.load(path, "hostsok")) == ["alpha", "zeta"]
def test_the_registry_orders_by_rank_then_name(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
path = _package(tmp_path, monkeypatch, "hostsranked", {
"alpha": _GOOD.format(name="alpha"), # the default, 100
"beta": _GOOD.format(name="beta") + "RANK = 5\n",
"gamma": _GOOD.format(name="gamma") + "RANK = 100\n"})
assert list(atshosts.load(path, "hostsranked")) == ["beta", "alpha", "gamma"]
def test_the_eight_first_hosts_keep_the_order_they_had_before_modules() -> None:
"""The Sources page's select opens on Greenhouse, which its hint names,
and a guessed slug on two hosts goes to the one probed first, as before."""
first = ["greenhouse", "lever", "ashby", "workable", "smartrecruiters", "recruitee",
"personio", "teamtailor"]
assert list(ats.HOSTS)[:8] == first
assert ats.ATSSource.description.startswith(
"Company job boards: Greenhouse, Lever, Ashby, Workable, SmartRecruiters, "
"Recruitee, Personio, Teamtailor")
assert all(module.RANK < atshosts.DEFAULT_RANK
for name, module in atshosts.HOSTS.items() if name in first)
def test_the_registry_refuses_a_module_missing_a_required_name(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
broken = _GOOD.format(name="broken").replace("def careers_url", "def not_careers_url")
@@ -85,12 +107,14 @@ def test_the_contract_check_names_each_problem() -> None:
module.slug_ok = module.allowed = module.careers_url = lambda slug: ""
module.page = lambda get, slug, cursor: None
module.probe_ok = lambda body: True
module.RANK, module.KEEP_CASE = "1", "yes"
found = atshosts.problems(module, "odd")
assert "NAME is 'other', not the module's name 'odd'" in found
assert "LABEL is not a non-empty string" in found
assert any(p.startswith("PATTERNS has '('") for p in found)
assert "page without rows" in found
assert "probe_ok without probe_url" in found
assert "RANK is not an int" in found and "KEEP_CASE is not a bool" in found
# ------------------------------------------------------------ the fetch
+23
View File
@@ -268,6 +268,29 @@ def test_slug_probes_find_a_board_the_pages_never_link() -> None:
assert found.evidence == "https://api.ashbyhq.com/posting-api/job-board/acme"
@pytest.mark.parametrize(("boards", "found"), [
({("greenhouse", "acme"), ("ashby", "acme")}, "greenhouse:acme"),
({("lever", "acme"), ("ashby", "acme")}, "lever:acme"),
({("smartrecruiters", "acme"), ("personio", "acme")}, "smartrecruiters:acme"),
({("lever", "eu/acme"), ("personio", "acme")}, "lever:eu/acme"),
])
def test_a_slug_on_two_hosts_goes_to_the_one_probed_first(
boards: set[tuple[str, str]], found: str) -> None:
site = Site({}, boards=boards)
assert run(site).board == found
def test_the_probe_order_is_the_one_before_modules() -> None:
assert list(mod._PROBES)[:7] == ["greenhouse", "lever", "ashby", "smartrecruiters",
"recruitee", "personio", "teamtailor"]
site = Site({})
run(site)
assert site.probed[:8] == [("greenhouse", "acme"), ("lever", "acme"), ("lever", "eu/acme"),
("ashby", "acme"), ("smartrecruiters", "acme"),
("recruitee", "acme"), ("personio", "acme"),
("teamtailor", "acme")]
def test_a_lever_eu_board_is_found_by_its_probe() -> None:
site = Site({"https://acme.com/": "<p>a script draws the jobs</p>"},
boards={("lever", "eu/acme")})