refactor: move upstream, sourceref, version_basis

upstream reads forges with the standard library alone and scrapers,
packs and the site read it: it goes to core. sourceref is the grammar
of a profile field, which the site parses without the comparison
tool: it goes to model. version_basis is read by profile_sync alone
and opens the profiling package.
This commit is contained in:
Abdessamad Derraz committed 2026-11-18 12:39:09 +01:00
1 parent 8cdda10393
commit e1f2f8685d
29 files changed
+51 -49

No files matched your search

+1 -1
View File
@@ -7804,7 +7804,7 @@ class PrboomPlusCitesFullPaths(unittest.TestCase):
def test_every_cited_file_has_its_directory(self):
import yaml
from scripts.sourceref import source_ref_values, split_source_ref
from scripts.model.sourceref import source_ref_values, split_source_ref
profile = yaml.safe_load((ROOT / "emulators" / "prboom-plus.yml").read_text(encoding="utf-8"))
refs: list[str] = []
+1 -1
View File
@@ -13,7 +13,7 @@ import re
import unittest
from pathlib import Path
import upstream
from core import upstream
from model.safeparse import yaml_load
ROOT = Path(__file__).resolve().parents[1]
+1 -1
View File
@@ -13,7 +13,7 @@ import unittest
from unittest import mock
import find_pinned_revision
import upstream
from core import upstream
class ThePinnedRevisionIsInTheHistory(unittest.TestCase):
+2 -6
View File
@@ -19,7 +19,7 @@ from pathlib import Path
SCRIPTS = Path(__file__).resolve().parent.parent / "scripts"
PACKAGE_LAYERS = {"core": 0, "model": 1, "resolve": 2, "scraper": 3, "exporter": 3}
PACKAGE_LAYERS = {"core": 0, "model": 1, "resolve": 2, "scraper": 3, "exporter": 3, "profiling": 3}
LIBRARY_LAYER = 3
COMMAND_LAYER = 4
@@ -35,8 +35,7 @@ NOT_YET_PACKAGED = frozenset({
"release_record", "romfolders", "romset_recipes", "siteagents", "sitebootstrap",
"sitecollection", "sitediagrams", "siteentries", "siteexports", "siteguides", "sitehandheld",
"siteinputs", "sitemarkup", "sitemeasurements", "siterender", "sitesources", "sitestarlight",
"sitesteps", "sitewanted", "sitewrite", "slots", "sourceref", "split_pack", "upstream",
"validate_pr", "verify", "version_basis",
"sitesteps", "sitewanted", "sitewrite", "slots", "split_pack", "validate_pr", "verify",
})
# Imports from a package module to a top-level module, left for the wave that
@@ -44,9 +43,6 @@ NOT_YET_PACKAGED = frozenset({
PENDING_TOP_LEVEL_IMPORTS = frozenset({
("exporter.doubled", "slots"),
("scraper.game_dat_importer", "region_audit"),
("scraper.mame_hash_scraper", "upstream"),
("scraper.romfolders", "upstream"),
("scraper.romfolders.__main__", "upstream"),
})
+1 -1
View File
@@ -18,7 +18,7 @@ from pathlib import Path
import yaml
import upstream
from core import upstream
from profile_sync import declared_repositories
REPO_ROOT = Path(__file__).resolve().parent.parent
+7 -7
View File
@@ -59,9 +59,9 @@ from profile_sync import (
watch_hashes,
worst_status,
)
import upstream
import version_basis
from upstream import CompareResult, FileChange
from core import upstream
from profiling import version_basis
from core.upstream import CompareResult, FileChange
def _version_read_as_written(profile, cache_dir, offline, profiles=None, recompute=False):
@@ -5856,7 +5856,7 @@ class ARecaleKeepsTheRepositoryWord(unittest.TestCase):
path is read without the word, and a recale wrote it back without it."""
def test_the_word_stays_in_front_of_the_new_span(self):
from sourceref import split_source_ref
from model.sourceref import split_source_ref
for raw, expected in (
("stella src/a.c:120-130", "stella src/a.c:140-150"),
@@ -6014,7 +6014,7 @@ class ARoleIsReadPerPart(unittest.TestCase):
self.assertEqual(prose[0].parts[0].repo, "alek/x")
def test_the_prose_grammar_keeps_the_role(self):
from sourceref import _prose_runs
from model.sourceref import _prose_runs
runs = list(_prose_runs(
"# ref: source src/a.cpp:1656-1685, 1709-1738, upstream b.c:5"
@@ -6027,7 +6027,7 @@ class ARoleIsReadPerPart(unittest.TestCase):
def test_an_abbreviated_location_reads_in_the_file_named_last(self):
"""devilutionx writes `Source/engine/assets.cpp:` then `(:507)` for
each loader, and its pin moved under five uncollected numbers."""
from sourceref import _prose_runs
from model.sourceref import _prose_runs
text = (
"Load order is defined in Source/engine/assets.cpp:\n"
@@ -6053,7 +6053,7 @@ class ARoleIsReadPerPart(unittest.TestCase):
])
def test_an_abbreviated_location_needs_a_file_before_it(self):
from sourceref import _prose_runs
from model.sourceref import _prose_runs
self.assertEqual(list(_prose_runs("read at boot (:507), devilutionx.mpq")), [])
+1 -1
View File
@@ -286,7 +286,7 @@ class CachedDirectory(unittest.TestCase):
def test_file_missing_from_the_archive_is_absent(self) -> None:
from unittest import mock
import upstream
from core import upstream
fetcher = Fetcher({"os": {"repo": "https://gitlab.com/g/p", "commit": "0" * 40}})
with mock.patch.object(upstream, "cache_gitlab_directory", return_value={"sys/a/system.ini"}):
+2 -2
View File
@@ -63,7 +63,7 @@ from sitesources import launcher_ref_markdown, list_source
import check_platform_folder
import sitesources
import release_record
import upstream
from core import upstream
REPO_ROOT = Path(__file__).resolve().parents[1]
@@ -924,7 +924,7 @@ class SourceLinksGoWhereTheFileIs(unittest.TestCase):
continue
for slug, pin, path in link.findall(
sitesources._source_ref_markdown(profile, entry["source_ref"])):
import upstream
from core import upstream
repo = upstream.parse_repo(f"https://github.com/{slug}")
held = sitesources.tree_holds(repo, pin, urllib.parse.unquote(path))
+1 -1
View File
@@ -280,7 +280,7 @@ class CitationsKeepTheirAnnotations(unittest.TestCase):
self.assertTrue(texts[4].endswith(")"), texts[4])
def test_the_annotation_is_what_follows_the_location(self):
from sourceref import ref_annotation
from model.sourceref import ref_annotation
self.assertEqual(ref_annotation("munt ROMInfo.cpp:206-213"), "")
self.assertEqual(ref_annotation("source atari800/src/sysrom.c:91"), "")
+2 -2
View File
@@ -19,9 +19,9 @@ from pathlib import Path
from unittest import mock
import sitesources
import upstream
from core import upstream
from model.profiles import load_emulator_profiles
from sourceref import ref_role, source_ref_values, split_source_ref
from model.sourceref import ref_role, source_ref_values, split_source_ref
REPO_ROOT = Path(__file__).resolve().parents[1]
+2 -2
View File
@@ -871,7 +871,7 @@ class TheGitHubTokenComesFromGh(unittest.TestCase):
def test_every_api_caller_reads_it(self):
import profile_sync
import upstream
from core import upstream
from scraper import base_scraper
with self._gh():
@@ -888,7 +888,7 @@ class TheGitHubTokenComesFromGh(unittest.TestCase):
profile_sync._check_quota(606, offline=False)
def test_another_forge_never_triggers_gh(self):
import upstream
from core import upstream
with self._gh() as run:
headers = upstream._headers("https://gitlab.com/api/v4/projects/1")
+3 -3
View File
@@ -15,8 +15,8 @@ import urllib.error
import urllib.request
from pathlib import Path
import upstream
from upstream import make_repo, parse_repo, raw_url
from core import upstream
from core.upstream import make_repo, parse_repo, raw_url
def _no_network(url: str):
@@ -127,7 +127,7 @@ class TestRawUrl(unittest.TestCase):
def test_forgejo_fetches_through_the_api(self):
# git.ngram.ca serves an HTML proof-of-work page on /raw/commit,
# which fetch_file would have cached as the file's lines.
import upstream
from core import upstream
repo = parse_repo("https://git.ngram.ca/mirrors/Ryujinx")
self.assertEqual(
+2 -2
View File
@@ -24,8 +24,8 @@ from unittest import mock
import yaml
import profile_sync
import upstream
import version_basis
from core import upstream
from profiling import version_basis
from model.profiles import load_emulator_profiles
from profile_sync import ProfileReport, bump_commit
+1 -1
View File
@@ -104,7 +104,7 @@ class DeploySiteTriggers(unittest.TestCase):
"""sitesources imported two parsing functions from profile_sync, so
every change to the comparison tool rebuilt an unchanged site."""
self.assertNotIn("scripts/profile_sync.py", closure(["generate_site.py"]))
self.assertIn("scripts/sourceref.py", closure(["generate_site.py"]))
self.assertIn("scripts/model/sourceref.py", closure(["generate_site.py"]))
class ThePullRequestBuildsTheSite(unittest.TestCase):