示例#1
0
文件: qa.py 项目: ferwitt/sak
def autoflake() -> None:
    if SAK_GLOBAL is None:
        raise Exception("No SAK_GLOBAL defined")

    paths = []
    paths += [str(SAK_GLOBAL / "saklib")]
    for plugin in plm.getPluginList():
        if plugin.plugin_path is None:
            continue
        paths += [str(plugin.plugin_path)]

    for path in paths:
        cmd = [
            "autoflake",
            "-i",
            "-r",
            "--expand-star-imports",
            "--remove-all-unused-imports",
            "--remove-duplicate-keys",
            "--remove-unused-variables",
            "--verbose",
            path,
        ]

        cwd = path
        subprocess.run(cmd, check=True, cwd=cwd)
示例#2
0
文件: qa.py 项目: ferwitt/sak
def test(coverage: bool = False, pdb: bool = False) -> None:
    if SAK_GLOBAL is None:
        raise Exception("No SAK_GLOBAL defined")

    cmd = ["pytest"]

    if pdb:
        cmd += ["--pdb"]

    if coverage:
        cmd += ["--cov-report=html", "--cov=saklib", "--cov=plugins"]

    test_files = []

    test_files += [str(x) for x in (SAK_GLOBAL / "saklib").rglob("*_test.py")]
    for plugin in plm.getPluginList():
        if plugin.plugin_path is None:
            continue
        test_files += [
            str(x) for x in Path(plugin.plugin_path).rglob("*_test.py")
        ]

    cmd += test_files

    cwd = SAK_GLOBAL

    normalize_file_path = False
    if normalize_file_path:
        p = subprocess.Popen(cmd,
                             cwd=cwd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        if (p.stdout is None) or (p.stderr is None):
            raise Exception('Failed to execute "%s" ' % (" ".join(cmd)))

        def convertPythonTracebackFileToNormalizeFile(line: str) -> str:
            return re.sub(r'^ *File "(.*?)", line (\d+),', r"\1:\2:", line,
                          re.M)

        for data in p.stdout:
            sys.stdout.write(
                convertPythonTracebackFileToNormalizeFile(
                    data.decode("utf-8")))
            sys.stdout.flush()
        for data in p.stderr:
            sys.stderr.write(
                convertPythonTracebackFileToNormalizeFile(
                    data.decode("utf-8")))
            sys.stderr.flush()
        p.communicate()
        if p.returncode != 0:
            raise Exception('Failed to execute "%s" ret core: %d' %
                            (" ".join(cmd), p.returncode))
    else:
        subprocess.run(cmd, check=True, cwd=cwd)
示例#3
0
文件: qa.py 项目: ferwitt/sak
def flake8() -> None:
    if SAK_GLOBAL is None:
        raise Exception("No SAK_GLOBAL defined")

    paths = []
    paths += [str(SAK_GLOBAL / "saklib")]
    for plugin in plm.getPluginList():
        if plugin.plugin_path is None:
            continue
        paths += [str(plugin.plugin_path)]

    cmd = ["flake8"]
    cmd += paths

    cwd = SAK_GLOBAL
    subprocess.run(cmd, check=True, cwd=cwd)
示例#4
0
文件: qa.py 项目: ferwitt/sak
def mypy() -> None:
    if SAK_GLOBAL is None:
        raise Exception("No SAK_GLOBAL defined")

    paths = []
    paths += [str(SAK_GLOBAL / "saklib")]
    for plugin in plm.getPluginList():
        if plugin.plugin_path is None:
            continue
        paths += [str(plugin.plugin_path)]

    cmd = [
        "mypy",
        "--exclude",
        "python",
        "--ignore-missing-imports",
        "--show-absolute-path",
        "--pretty",
    ]

    # Instead of adding --strict directly, I will add the optional flags manually.
    strict_options = [
        "--warn-unused-configs",
        "--disallow-any-generics",
        "--disallow-subclassing-any",
        # "--disallow-untyped-calls",
        "--disallow-untyped-defs",
        "--disallow-incomplete-defs",
        "--check-untyped-defs",
        "--disallow-untyped-decorators",
        "--no-implicit-optional",
        "--warn-redundant-casts",
        "--warn-unused-ignores",
        "--warn-return-any",
        "--no-implicit-reexport",
        "--strict-equality",
    ]
    cmd += strict_options

    # Add paths to check.
    cmd += paths

    cwd = SAK_GLOBAL
    subprocess.run(cmd, check=True, cwd=cwd)
示例#5
0
文件: qa.py 项目: ferwitt/sak
def black(check: bool = False) -> None:
    if SAK_GLOBAL is None:
        raise Exception("No SAK_GLOBAL defined")

    paths = []
    paths += [str(SAK_GLOBAL / "saklib")]
    for plugin in plm.getPluginList():
        if plugin.plugin_path is None:
            continue
        paths += [str(plugin.plugin_path)]

    for path in paths:
        cmd = ["black"]

        if check:
            cmd += ["--check", "--diff"]

        cmd += [path]

        cwd = path
        subprocess.run(cmd, check=True, cwd=cwd)