Files
nearology 56c5ee23d3
Verify / test (push) Failing after 2m54s
first commit
2026-11-05 17:31:17 +03:30

35 خطوط
1.6 KiB
Python

"""Parser subprocess: no network/storage credentials are inherited by the worker."""
import json
import resource
import sys
from pathlib import Path
# Bound CPU, virtual memory, output size and file descriptors before parsing.
resource.setrlimit(resource.RLIMIT_AS, (768 * 1024**2, 768 * 1024**2))
resource.setrlimit(resource.RLIMIT_CPU, (60, 60))
resource.setrlimit(resource.RLIMIT_FSIZE, (128 * 1024**2, 128 * 1024**2))
resource.setrlimit(resource.RLIMIT_NOFILE, (64, 64))
from .documents import parse_document
from .parser.record_decoder import ParseError
from .render import svg_document
def run():
source, destination, filename, identifier = sys.argv[1:]
dest = Path(destination)
try:
doc = parse_document(Path(source).read_bytes(), filename, identifier)
(dest / 'data.json').write_text(doc.model_dump_json(), encoding='utf-8')
(dest / 'drawing.svg').write_bytes(svg_document(doc))
result = {'ok': True, 'summary': {'schema_version': doc.schema_version,
'compatibility': doc.metadata['compatibility'],
'record_count': doc.metadata['record_count'], 'primitive_count': len(doc.primitives),
'component_count': len(doc.components),
'diagnostics': [d.model_dump() for d in doc.diagnostics]}}
except (ParseError, ValueError) as exc:
result = {'ok': False, 'code': 'invalid_schematic', 'message': str(exc)[:500]}
except Exception:
result = {'ok': False, 'code': 'parser_error', 'message': 'The parser could not process this schematic'}
(dest / 'result.json').write_text(json.dumps(result), encoding='utf-8')
if __name__ == '__main__': run()