fix: preserve engineering identity in scoped runtime exclusions

This commit is contained in:
阿白叔 committed 2026-11-02 19:50:26 +08:00
1 parent 29c154d2ca
commit 3415e010ff
4 files changed
+288 -12

No files matched your search

+53 -7
View File
@@ -18,12 +18,35 @@ MANIFEST_VERSION = 1
_NONPRIMARY_DIRECTORIES = frozenset({
'log', 'logs', 'temp', 'tmp', '__pycache__', 'backup', 'backups',
'output', 'outputs', 'report', 'reports', 'gerber', 'gerbers', 'odb++',
'log files', 'logfiles',
})
_NONPRIMARY_SUFFIXES = frozenset({
'.log', '.tmp', '.temp', '.lck', '.lock', '.bak', '.backup', '.pdf',
})
def _root_runtime(directories):
"""Known runtime/history children of a library or project workspace root."""
return bool(directories and (
directories[0] in _NONPRIMARY_DIRECTORIES
or directories[0].startswith('work.before-restore-')
or directories[:2] == ('projectbackup', 'backups')))
def _native_runtime(directories, database_prefix):
runtime_prefix = database_prefix + ('cdbsvr',)
return (directories[:len(runtime_prefix)] == runtime_prefix
and len(directories) > len(runtime_prefix)
and directories[len(runtime_prefix)] in ('log', 'dbcheck', 'dbrestore'))
def _project_runtime(directories):
return (_root_runtime(directories)
or (directories[:1] == ('pcb',) and _root_runtime(directories[1:]))
or _native_runtime(directories, ('database',))
or _native_runtime(directories, ('pcb', 'database')))
@dataclass(frozen=True)
class ManifestScope:
"""Project root by default; library selects one CBB and shared dependencies."""
@@ -46,21 +69,44 @@ class ManifestScope:
def includes_directory(self, relative):
parts = tuple(part.casefold() for part in Path(relative).parts)
if any(part in _NONPRIMARY_DIRECTORIES or part.startswith('work.before-restore-')
for part in parts):
if self._runtime_path(parts, directory=True):
return False
if self.kind == 'project' or parts[0] != 'reusableblockslp':
if self.kind == 'project' or not parts or parts[0] != 'reusableblockslp':
return True
return ((len(parts) < 2 or parts[1] == self.block_name.casefold())
and (len(parts) < 3 or parts[2] in ('work', 'cert')))
def _runtime_path(self, parts, *, directory=False):
"""Recognize runtime locations only in their structural context.
Generic names such as ``Logs`` are runtime when they are a project-root
or selected Work/Cert child. The same name deeper in an engineering
partition (or in shared SymbolLibs data) remains primary.
"""
directories = parts if directory else parts[:-1]
if not directory and (Path(parts[-1]).suffix in _NONPRIMARY_SUFFIXES
or parts[-1] == 'saddress.adr' or parts[-1].startswith('~$')):
return True
if self.kind == 'project':
return _project_runtime(directories)
if directories[:1] == ('reusableblockslp',):
# Identity and Work/Cert role components never act as runtime names.
if (len(directories) >= 3 and directories[1] == self.block_name.casefold()
and directories[2] in ('work', 'cert')):
return _project_runtime(directories[3:])
return False
if _root_runtime(directories):
return True
# Shared dependency names/partitions are engineering data. Only native
# server runtime subtrees within known DB positions are excluded.
if directories[:1] == ('symbollibs',) and len(directories) >= 2:
return _native_runtime(directories, directories[:2])
return bool(directories and _native_runtime(directories, directories[:1]))
def classify(self, relative):
"""Return a semantic scope label or None; paths are relative to the root."""
parts = tuple(part.casefold() for part in Path(relative).parts)
if (any(part in _NONPRIMARY_DIRECTORIES or part.startswith('work.before-restore-')
for part in parts[:-1])
or Path(parts[-1]).suffix in _NONPRIMARY_SUFFIXES
or parts[-1] == 'saddress.adr' or parts[-1].startswith('~$')):
if self._runtime_path(parts):
return None
if self.kind == 'project':
return 'project'