Commit 0043d730 authored by Luke Mewburn's avatar Luke Mewburn
Browse files

testing: python import style

Don't use 'from MODULE import NAME' unnecessarily,
especially "import *", as it's hard to review where types come from.
parent 646f88b2
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
import logging
import json
import os
import shutil
import subprocess
from pathlib import Path
from subprocess import run
from shutil import which

from pycrate_asn1c.asnproc import *
import pycrate_asn1c.asnproc

import lint_asn1

@@ -64,10 +65,14 @@ 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'):
@@ -112,12 +117,12 @@ def compileAllTargets(asnFiles):
            fileTexts = []
            fileNames = [target]
            fileNames.extend(config.get("dependencies", []))
            GLOBAL.clear()
            pycrate_asn1c.asnproc.GLOBAL.clear()
            for filename in fileNames:
                pFile = Path(filename)
                fileTexts.append(pFile.read_text())
                logging.debug(f"  Loading {filename}")
            compile_text(fileTexts, filenames=fileNames)
            pycrate_asn1c.asnproc.compile_text(fileTexts, filenames=fileNames)
            results[str(target)] = {
                "ok": True,
            }
@@ -163,7 +168,7 @@ if __name__ == "__main__":
    logging.basicConfig(level=loglevel)

    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}")
+3 −2
Original line number Diff line number Diff line
from pathlib import Path
from difflib import *

import difflib
import subprocess


@@ -16,7 +17,7 @@ def lint(file: Path):

    linted_xml = completed.stdout
    orig_xml = file.read_text()
    diff = list(unified_diff(orig_xml.splitlines(), linted_xml.splitlines()))
    diff = list(difflib.unified_diff(orig_xml.splitlines(), linted_xml.splitlines()))

    if len(diff) == 0:
        print(f"  {str(f)}: OK")