mirror of
https://github.com/StockSharp/StockSharp.git
synced 2026-12-05 09:02:09 +00:00
The connector README check prints the titles of the localized sections, and
Python encodes stdout with the locale code page: on the English Windows runner
that is cp1252, which has no glyph for Cyrillic or Chinese, so the step died
with UnicodeEncodeError and every later step of the validate job never ran. A
Cyrillic or Chinese locale hides this locally. Script output now goes through
UTF-8 via the shared console_utf8 helper, with stderr keeping a forgiving error
handler so that reporting a failure cannot fail in turn, and the tests
reproduce the runner by forcing cp1252 on a child process.
With the job running again, the READMEs turned out to list 292 connectors out
of the 393 that exist, plus 26 that exist nowhere in the code. Nothing checked
that: the only guard that looked past the READMEs, the --metadata-since mode,
matched commit subjects, so it saw only connectors added by a commit worded
that way, and CI never passed the flag. It is replaced by a check that reads
the connector sources and pairs a connector with its row through the
documentation page - a connector declares
[Doc("topics/api/connectors/<group>/<page>.html")] and the row links the same
path behind a language prefix, which identifies it without relying on the
display name or the logo, both of which are shared between connectors. Ten
connectors live in the applications repository, which the validate job does not
check out, so the pages they document are named in the check rather than
discovered.
The missing rows are generated from the connector itself: the logo from
[MediaIcon], the link from [Doc], the name from the localization resource named
by [Display]. The English name is used in all three files, as the common tables
have never translated connector names; only the Russian-market section, which
no other file mirrors, keeps its localized names and is also the only place the
connectors of that market are listed. Crypto connectors join the table that has
received every recent crypto connector, and the connectors documented under
europe/ and common/ join the stock table for want of a section of their own.
The rows of the withdrawn connectors are gone: sixteen crypto exchanges that
shut down years ago, eight data feeds and brokers dropped since, and two of the
Russian market. All of them kept their documentation pages and so looked
healthy to the link checker while promising connectors that cannot be used.
Also ignore __pycache__, which running the repository's own tests leaves behind.
121 lines
3.4 KiB
Python
121 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
import xml.etree.ElementTree as ET
|
|
from collections import Counter
|
|
from pathlib import Path
|
|
|
|
from console_utf8 import force_utf8_stdio
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
def normalize_solution_path(path: str) -> str:
|
|
return path.replace("\\", "/")
|
|
|
|
|
|
def discover_connector_projects(connectors_root: Path) -> list[str]:
|
|
if not connectors_root.is_dir():
|
|
raise ValueError(f"connector repository not found: {connectors_root}")
|
|
|
|
projects: list[str] = []
|
|
solution_root = f"../{connectors_root.name}"
|
|
|
|
for directory in connectors_root.iterdir():
|
|
if not directory.is_dir() or directory.name == "Tests":
|
|
continue
|
|
|
|
for project in directory.glob("*.csproj"):
|
|
projects.append(f"{solution_root}/{directory.name}/{project.name}")
|
|
|
|
return sorted(projects, key=str.casefold)
|
|
|
|
|
|
def read_solution_connector_projects(solution: Path, connectors_root: Path) -> list[str]:
|
|
if not solution.is_file():
|
|
raise ValueError(f"solution not found: {solution}")
|
|
|
|
try:
|
|
root = ET.parse(solution).getroot()
|
|
except ET.ParseError as error:
|
|
raise ValueError(f"invalid solution XML: {solution}: {error}") from error
|
|
|
|
prefix = f"../{connectors_root.name}/"
|
|
projects: list[str] = []
|
|
|
|
for element in root.iter("Project"):
|
|
path = normalize_solution_path(element.get("Path", ""))
|
|
if path.startswith(prefix):
|
|
projects.append(path)
|
|
|
|
return projects
|
|
|
|
|
|
def main() -> int:
|
|
force_utf8_stdio()
|
|
|
|
parser = argparse.ArgumentParser(
|
|
description="Check that StockSharp.slnx contains every connector project from the sibling repository.",
|
|
)
|
|
parser.add_argument(
|
|
"--solution",
|
|
type=Path,
|
|
default=ROOT / "StockSharp.slnx",
|
|
help="Solution to validate (default: StockSharp.slnx in the repository root).",
|
|
)
|
|
parser.add_argument(
|
|
"--connectors-root",
|
|
type=Path,
|
|
default=ROOT.parent / "Connectors",
|
|
help="Connector repository root (default: ../Connectors).",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
solution = args.solution.expanduser().resolve()
|
|
connectors_root = args.connectors_root.expanduser().resolve()
|
|
|
|
try:
|
|
expected = discover_connector_projects(connectors_root)
|
|
actual = read_solution_connector_projects(solution, connectors_root)
|
|
except ValueError as error:
|
|
print(f"ERROR {error}")
|
|
return 2
|
|
|
|
expected_set = set(expected)
|
|
actual_set = set(actual)
|
|
counts = Counter(actual)
|
|
|
|
missing = sorted(expected_set - actual_set, key=str.casefold)
|
|
stale = sorted(actual_set - expected_set, key=str.casefold)
|
|
duplicates = sorted(
|
|
(project for project, count in counts.items() if count > 1),
|
|
key=str.casefold,
|
|
)
|
|
|
|
for project in missing:
|
|
print(f"MISSING {project}")
|
|
|
|
for project in stale:
|
|
print(f"STALE {project}")
|
|
|
|
for project in duplicates:
|
|
print(f"DUPLICATE {project}")
|
|
|
|
if missing or stale or duplicates:
|
|
print(
|
|
"DIFF solution connectors: "
|
|
f"expected={len(expected)}, actual={len(actual)}, "
|
|
f"missing={len(missing)}, stale={len(stale)}, duplicates={len(duplicates)}"
|
|
)
|
|
return 1
|
|
|
|
print(f"OK solution connectors: projects={len(expected)}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|