refactor: recipes command imports its packages

This commit is contained in:
Abdessamad Derraz committed 2026-11-18 19:49:59 +01:00
1 parent 0e4e5f450d
commit 6172cb65c0
8 files changed
+38 -49

No files matched your search

+1 -1
View File
@@ -199,7 +199,7 @@ class Capture(Fixture):
self.assertEqual(records["bios/set.zip"]["members"][0]["sha1"], "kept")
def test_zlib_ng_refuses_to_capture(self):
with mock.patch.object(recipes_build, "zlib_ng_version", lambda: "2.2.4"), \
with mock.patch.object(recipes_capture, "zlib_ng_version", lambda: "2.2.4"), \
self.assertRaises(recipes_capture.ZlibNgError):
self.capture()
+6 -7
View File
@@ -15,7 +15,6 @@ import urllib.error
from pathlib import Path
from unittest import mock
import auto_fetch
from acquire import fetch
PAYLOAD = b"keyboard mcu"
@@ -48,21 +47,21 @@ def _serving(payloads: dict[str, bytes]):
class SoftwareHeritageAnswersByContent(unittest.TestCase):
def test_the_bytes_it_serves_are_kept_when_the_hash_holds(self):
urlopen, asked = _serving({f"{fetch.SOFTWARE_HERITAGE}/sha1:{SHA1}/raw/": PAYLOAD})
with mock.patch.object(auto_fetch.urllib.request, "urlopen", urlopen):
with mock.patch.object(fetch.urllib.request, "urlopen", urlopen):
data = fetch.step3b_software_heritage({"name": "D8039HLC.rom", "sha1": SHA1})
self.assertEqual(data, PAYLOAD)
self.assertEqual(asked, [f"{fetch.SOFTWARE_HERITAGE}/sha1:{SHA1}/raw/"])
def test_other_bytes_under_the_hash_are_refused(self):
urlopen, _asked = _serving({fetch.SOFTWARE_HERITAGE: b"something else"})
with mock.patch.object(auto_fetch.urllib.request, "urlopen", urlopen):
with mock.patch.object(fetch.urllib.request, "urlopen", urlopen):
data = fetch.step3b_software_heritage({"name": "x", "sha1": SHA1})
self.assertIsNone(data)
def test_an_absent_file_is_not_counted_as_a_source_that_did_not_answer(self):
urlopen, _asked = _serving({})
fetch._UNANSWERED.clear()
with mock.patch.object(auto_fetch.urllib.request, "urlopen", urlopen):
with mock.patch.object(fetch.urllib.request, "urlopen", urlopen):
self.assertIsNone(fetch.step3b_software_heritage({"name": "x", "sha1": SHA1}))
self.assertEqual(fetch._UNANSWERED, [])
@@ -76,7 +75,7 @@ class LookupBySha1(unittest.TestCase):
def test_a_found_file_goes_to_tmp_acquire_never_to_bios(self):
urlopen, _asked = _serving({f"{fetch.SOFTWARE_HERITAGE}/sha1:{SHA1}/raw/": PAYLOAD})
with mock.patch.object(auto_fetch.urllib.request, "urlopen", urlopen), \
with mock.patch.object(fetch.urllib.request, "urlopen", urlopen), \
contextlib.redirect_stdout(io.StringIO()) as out:
code = fetch.lookup_sha1s([SHA1.upper()], {"files": {}})
self.assertEqual(code, 0)
@@ -87,7 +86,7 @@ class LookupBySha1(unittest.TestCase):
def test_a_held_file_is_named_and_not_fetched(self):
urlopen, asked = _serving({})
db = {"files": {SHA1: {"path": "bios/Commodore/Amiga/x.rom"}}}
with mock.patch.object(auto_fetch.urllib.request, "urlopen", urlopen), \
with mock.patch.object(fetch.urllib.request, "urlopen", urlopen), \
contextlib.redirect_stdout(io.StringIO()) as out:
code = fetch.lookup_sha1s([SHA1], db)
self.assertEqual((code, asked), (0, []))
@@ -95,7 +94,7 @@ class LookupBySha1(unittest.TestCase):
def test_nothing_found_and_a_malformed_hash_end_with_one(self):
urlopen, _asked = _serving({})
with mock.patch.object(auto_fetch.urllib.request, "urlopen", urlopen), \
with mock.patch.object(fetch.urllib.request, "urlopen", urlopen), \
contextlib.redirect_stdout(io.StringIO()) as out, \
contextlib.redirect_stderr(io.StringIO()) as err:
code = fetch.lookup_sha1s([SHA1, "not-a-hash"], {"files": {}})
+10 -11
View File
@@ -20,35 +20,37 @@ from pathlib import Path
SCRIPTS = Path(__file__).resolve().parent.parent / "scripts"
PACKAGE_LAYERS = {"core": 0, "model": 1, "resolve": 2, "packs": 3, "scraper": 3, "exporter": 3,
"profiling": 3, "sitegen": 3}
"profiling": 3, "sitegen": 3, "recipes": 3, "acquire": 3}
LIBRARY_LAYER = 3
COMMAND_LAYER = 4
# The other domain packages a domain package may import. A package listed
# here imports no sibling outside its set.
SIBLING_IMPORTS: dict[str, frozenset[str]] = {
# A search starts from what verify finds missing.
"acquire": frozenset({"packs"}),
"packs": frozenset(),
"profiling": frozenset(),
"sitegen": frozenset({"packs"}),
"recipes": frozenset(),
# The site prints the recipe counts and the dump-catalog coverage report
# those two packages compute.
"sitegen": frozenset({"acquire", "packs", "recipes"}),
}
# Top-level modules other modules of scripts/ import: library code that a
# later wave moves into a package.
NOT_YET_PACKAGED = frozenset({
"archive_build", "autorun", "build_port", "campaign", "campaign_profiles", "campaign_rules",
"check_buildbot_system", "check_release_assets", "commit_rules", "core_probe", "derivations",
"autorun", "build_port", "campaign", "campaign_profiles", "campaign_rules",
"check_buildbot_system", "check_release_assets", "commit_rules", "core_probe",
"generate_event_schema", "measurement_records", "pin_installer", "pr_checks",
"provenance_report", "release_record", "romfolders", "romset_recipes",
"release_record", "romfolders",
})
# Imports from a package module to a top-level module, left for the wave that
# packages the top-level side.
PENDING_TOP_LEVEL_IMPORTS = frozenset({
("sitegen.build", "archive_build"),
("sitegen.build", "provenance_report"),
("sitegen.build", "release_record"),
("sitegen.config", "release_record"),
("sitegen.dataexports", "provenance_report"),
("sitegen.decorate", "release_record"),
("sitegen.descriptions", "release_record"),
("sitegen.getpages", "release_record"),
@@ -56,14 +58,11 @@ PENDING_TOP_LEVEL_IMPORTS = frozenset({
("sitegen.handheld", "build_port"),
("sitegen.measurements", "measurement_records"),
("sitegen.platformindex", "release_record"),
("sitegen.provenance", "provenance_report"),
("sitegen.publish", "release_record"),
("sitegen.readme", "archive_build"),
("sitegen.readme", "pr_checks"),
("sitegen.readme", "release_record"),
("sitegen.validate", "release_record"),
("sitegen.versions", "release_record"),
("sitegen.wanted", "archive_build"),
("sitegen.whichpack", "release_record"),
})