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:
1 parent
75a389d725
commit
a9fb4397ac
11 files changed
+71
-8
No files matched your search
@@ -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__)
|
||||
@@ -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_.-]+)",
|
||||
|
||||
@@ -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_-]+)",
|
||||
|
||||
@@ -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 = (
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",)
|
||||
|
||||
|
||||
|
||||
@@ -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_-]+)",
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user