diff --git a/scripts/fileless_audit.py b/scripts/fileless_audit.py index 05c430ef2..ae340ea39 100644 --- a/scripts/fileless_audit.py +++ b/scripts/fileless_audit.py @@ -26,7 +26,8 @@ sys.path.insert(0, os.path.dirname(__file__)) from core import upstream from core.cli import require_directory, suggest_names -from profile_sync import collect_citations, ref_role, select_views, split_source_ref +from profile_sync import collect_citations, select_views +from model.sourceref import ref_role, split_source_ref from model.safeparse import yaml_load # Ways a program asks for somewhere to read from. diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index a9cd17d6d..a4a9b3303 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -43,35 +43,17 @@ from resolve.cores import resolve_platform_cores from core.cli import suggest_names from core.hashing import parse_hash_list from model.sourceref import ( - _ANNOTATION_RE as _ANNOTATION_RE, - _BARE_RANGE_RE as _BARE_RANGE_RE, - _LOCATED_RE as _LOCATED_RE, - _PROJECT_WORD_RE as _PROJECT_WORD_RE, - _PROSE_LIST_DELIMITERS as _PROSE_LIST_DELIMITERS, - _REF_RE as _REF_RE, - _SPLIT_RE as _SPLIT_RE, - _BINARY_SUFFIXES as _BINARY_SUFFIXES, - _HEX_ADDRESS_RE as _HEX_ADDRESS_RE, - PROSE_CITE_RE as PROSE_CITE_RE, - PROSE_CONT_RE as PROSE_CONT_RE, - PROSE_CONT_SPACED_RE as PROSE_CONT_SPACED_RE, - PROSE_EXTENSIONLESS as PROSE_EXTENSIONLESS, - PROSE_LINKING_WORDS as PROSE_LINKING_WORDS, - PROSE_LIST_ITEM_RE as PROSE_LIST_ITEM_RE, - PROSE_WRAPPED_RANGE_RE as PROSE_WRAPPED_RANGE_RE, - REPO_ROLES as REPO_ROLES, - RefPart as RefPart, - _prose_external as _prose_external, - _prose_runs as _prose_runs, - _trim_prose as _trim_prose, - is_binary_citation as is_binary_citation, - parse_source_ref as parse_source_ref, - ref_prose_text as ref_prose_text, - ref_role as ref_role, - resolve_project_word as resolve_project_word, - source_ref_values as source_ref_values, - split_outside_parentheses as split_outside_parentheses, - split_source_ref as split_source_ref, + _ANNOTATION_RE, + RefPart, + _prose_runs, + _trim_prose, + is_binary_citation, + ref_prose_text, + ref_role, + resolve_project_word, + source_ref_values, + split_outside_parentheses, + split_source_ref, ) from core.upstream import CompareResult, find_renamed diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index f2e110a61..570cf2f5d 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -4188,7 +4188,7 @@ class ACitationInsideASourceRefIsTracked(unittest.TestCase): [("prose", "src/pce_fast/huc.cpp:284-304")]) def test_offsets_match_the_scalar(self): - from scripts.profile_sync import ref_prose_text + from scripts.model.sourceref import ref_prose_text ref = "a.c:1-2, 5 (see b.c:7)" masked = ref_prose_text(ref) diff --git a/tests/test_profile_sync.py b/tests/test_profile_sync.py index 716a21a22..09c7efba1 100644 --- a/tests/test_profile_sync.py +++ b/tests/test_profile_sync.py @@ -19,11 +19,11 @@ from unittest import mock import yaml import profile_sync +from model import sourceref from profile_sync import ( EntryReport, PartResult, ProfileReport, - RefPart, VersionReport, YamlWriteError, anchor_block, @@ -45,20 +45,19 @@ from profile_sync import ( format_markdown, format_report, insert_after_line, - parse_source_ref, rebase_refs, replace_field_line, report_to_dict, resolve_rename, select_profiles, select_repo, - split_source_ref, tree_diff, unified_for_path, version_warning, watch_hashes, worst_status, ) +from model.sourceref import RefPart, parse_source_ref, split_source_ref from core import upstream from profiling import version_basis from core.upstream import CompareResult, FileChange @@ -694,7 +693,7 @@ class TestExternalCitation(unittest.TestCase): for text in ("Makefile:36-37", "src/Makefile:36", "README:27", "configure:120"): with self.subTest(text=text): - match = profile_sync.PROSE_CITE_RE.search(text) + match = sourceref.PROSE_CITE_RE.search(text) self.assertIsNotNone(match, text) self.assertEqual(match.group("path"), text.split(":")[0]) @@ -702,7 +701,7 @@ class TestExternalCitation(unittest.TestCase): """Widening the pattern to any dotless word swallows these.""" for text in ("ALTERNATEROMS:23", "F000:12", "C000:4"): with self.subTest(text=text): - self.assertIsNone(profile_sync.PROSE_CITE_RE.search(text), text) + self.assertIsNone(sourceref.PROSE_CITE_RE.search(text), text) def test_plain_paths_are_not_citations(self): for path in ("src/midi/mt32.cpp", "libretro.c", "a/b/c.h"): @@ -730,24 +729,24 @@ class TestBinaryCitation(unittest.TestCase): """A ref read by disassembly has no source path to anchor.""" def test_hex_address_is_binary(self): - self.assertTrue(profile_sync.is_binary_citation( + self.assertTrue(sourceref.is_binary_citation( "BAM.dll 1.5-408 .text:0x100c3960-0x100c3a97" )) - self.assertTrue(profile_sync.is_binary_citation("libmain.so LoadNES 0x3bb49")) + self.assertTrue(sourceref.is_binary_citation("libmain.so LoadNES 0x3bb49")) def test_binary_suffix_followed_by_words_is_binary(self): - self.assertTrue(profile_sync.is_binary_citation("BAM-Tracker.exe import directory")) + self.assertTrue(sourceref.is_binary_citation("BAM-Tracker.exe import directory")) def test_section_name_is_binary(self): - self.assertTrue(profile_sync.is_binary_citation(".rdata dialog filter")) + self.assertTrue(sourceref.is_binary_citation(".rdata dialog filter")) def test_bare_library_name_is_binary(self): - self.assertTrue(profile_sync.is_binary_citation("DesktopKinect.dll")) - self.assertFalse(profile_sync.is_binary_citation("Makefile")) + self.assertTrue(sourceref.is_binary_citation("DesktopKinect.dll")) + self.assertFalse(sourceref.is_binary_citation("Makefile")) def test_a_source_path_is_not_binary(self): for path in ("src/foo.c", "libs/libCg.so", "Source/Core/hook.c", "resources/font.h"): - self.assertFalse(profile_sync.is_binary_citation(path), path) + self.assertFalse(sourceref.is_binary_citation(path), path) def test_binary_part_is_reported_not_reviewed(self): result = anchor_part( @@ -3995,9 +3994,9 @@ class TestCollectCitations(unittest.TestCase): ): with self.subTest(line=line): start = line.index("src/lynx/system.cpp:86") - self.assertTrue(profile_sync._prose_external(line, start)) + self.assertTrue(sourceref._prose_external(line, start)) line = "boot; then src/lynx/system.cpp:86" - self.assertFalse(profile_sync._prose_external(line, line.index("src/"))) + self.assertFalse(sourceref._prose_external(line, line.index("src/"))) def test_spans_locate_the_tokens_on_the_line(self): document = {"notes": "See main.c:112,1624-1633 for the boot path.\n"} @@ -4117,7 +4116,7 @@ class TestCollectCitations(unittest.TestCase): "mupen64plus-video-gln64/src/Config.cpp", "mupen64plus-core/upstream/src/device/pif/bootrom_hle.c", ] - resolve = profile_sync.resolve_project_word + resolve = sourceref.resolve_project_word self.assertEqual( resolve("rice Config.cpp", [tree]), "mupen64plus-video-rice/upstream/src/Config.cpp", @@ -5580,7 +5579,7 @@ class RealignReadsThePathAsWritten(unittest.TestCase): def fetch(repo, sha, path, *a, **k): return ["line"] * 40 if path in trees.get((repo, sha), set()) else None - part = profile_sync.RefPart("hatari/src/tos.c", 10, 10, "10") + part = sourceref.RefPart("hatari/src/tos.c", 10, 10, "10") with mock.patch.object(profile_sync.upstream, "fetch_file", side_effect=fetch), \ mock.patch.object(profile_sync, "_resolve_at", return_value=("found", ("src/tos.c", ["x"] * 40))): @@ -5600,7 +5599,7 @@ class RealignGivesASharedPathToTheFirstRepository(unittest.TestCase): fork = profile_sync.upstream.make_repo("github.com", "t", "freej2me-plus") up = profile_sync.upstream.make_repo("github.com", "hex007", "freej2me") - part = profile_sync.RefPart("src/libretro/freej2me_libretro.c", 39, 46, "39-46") + part = sourceref.RefPart("src/libretro/freej2me_libretro.c", 39, 46, "39-46") with mock.patch.object( profile_sync.upstream, "fetch_file", return_value=["line"] * 99 ), mock.patch.object( @@ -5865,7 +5864,7 @@ class ARecaleKeepsTheRepositoryWord(unittest.TestCase): ): with self.subTest(raw=raw): p = split_source_ref(raw)[0] - part = profile_sync.RefPart( + part = sourceref.RefPart( profile_sync.strip_repo_word(p.path, {"stella"}), p.start, p.end, p.raw) result = profile_sync.PartResult(part, "SHIFTED", None, 140, 150, [], "") self.assertEqual(profile_sync._rendered_part(result), expected) @@ -5957,7 +5956,7 @@ class ARoleIsReadPerPart(unittest.TestCase): ) profile_sync.upstream.compare = ( lambda repo, base, head, cache_dir, offline=False: - profile_sync.CompareResult([], False) + upstream.CompareResult([], False) ) text = ( 'emulator: T\n'