Commit e0608713 authored by Luke Mewburn's avatar Luke Mewburn Committed by Luke Mewburn
Browse files

asn_process: python import style

Don't use 'from MODULE import NAME' unnecessarily,
especially "import *", as it's hard to review where types come from.
parent f9b43698
Loading
Loading
Loading
Loading
+16 −9
Changes for testing/asn/asn_process.py: 16 added lines, 9 removed lines.
Original line number Diff line number Diff line
import logging
import json
import logging
import shutil
import subprocess

from pathlib import Path
from subprocess import run
from shutil import which

# Luke has fixed the updstream issue with multiple imports in pycrate
# https://github.com/pycrate-org/pycrate/pull/57
# but it isn't yet included in the distribution (still at 0.7.11 , Jul 2025)
# When this gets updated we may be able to use only pycrate, and drop the use of asn1c

from pycrate_asn1c.asnproc import *
import pycrate_asn1c.asnproc


def reconstrainInteger(filename):
@@ -52,10 +53,16 @@ def syntaxCheckASN(fileList):
        try:
            if file.as_posix() in filesWithBigInts:
                newFile = reconstrainInteger(str(file))
                p = run([asn1c_path, "-E", fix_path(newFile)], capture_output=True)
                p = subprocess.run(
                    [asn1c_path, "-E", fix_path(newFile)],
                    capture_output=True,
                )
                Path(newFile).unlink()
            else:
                p = run([asn1c_path, "-E", fix_path(str(file))], capture_output=True)
                p = subprocess.run(
                    [asn1c_path, "-E", fix_path(str(file))],
                    capture_output=True,
                )
            if p.returncode != 0:
                errorMessage = p.stderr.decode().splitlines()[0]
                if errorMessage.startswith('   Value "18446744073709551615" at line'):
@@ -118,7 +125,7 @@ def compileAllTargets(compileTargets):
        try:
            fileTexts = []
            fileNames = []
            GLOBAL.clear()
            pycrate_asn1c.asnproc.GLOBAL.clear()
            for filename in target:
                pFile = Path(filename)
                if pFile.as_posix() in duplicateObjects:
@@ -129,7 +136,7 @@ def compileAllTargets(compileTargets):
                    fileTexts.append(pFile.read_text())
                fileNames.append(filename)
                logging.debug(f"  Loading {filename}")
            compile_text(fileTexts, filenames=fileNames)
            pycrate_asn1c.asnproc.compile_text(fileTexts, filenames=fileNames)
            results[str(firstTarget)] = {
                "ok": True,
            }
@@ -172,7 +179,7 @@ def processResults(results, stageName):

if __name__ == "__main__":
    logging.info("Searching for ASN1C")
    asn1c_path = which("asn1c")
    asn1c_path = shutil.which("asn1c")
    if asn1c_path is None:
        raise Exception("No asn1c executable found. Please install asn1c")
    logging.info(f"asn1c found at {asn1c_path}")