Пример #1
0
def pages(session: nox.Session) -> None:
    """Generate website pages."""
    if not os.path.exists(config.ARTIFACT_DIRECTORY):
        os.mkdir(config.ARTIFACT_DIRECTORY)

    # Static
    print("Copying static objects...")
    copy_from_in(config.PAGES_DIRECTORY, config.ARTIFACT_DIRECTORY)

    # Documentation
    session.install("-r", "requirements.txt", "-r", "dev-requirements.txt")
    session.env["PDOC3_GENERATING"] = "1"

    print("Building documentation...")
    session.run(
        "python",
        "docs/patched_pdoc.py",
        config.MAIN_PACKAGE,
        "--html",
        "--output-dir",
        config.ARTIFACT_DIRECTORY,
        "--template-dir",
        config.DOCUMENTATION_DIRECTORY,
        "--force",
    )

    # Rename `hikari` into `documentation`
    # print("Renaming output dir...")
    # print(f"{config.ARTIFACT_DIRECTORY}/{config.MAIN_PACKAGE} -> {config.ARTIFACT_DIRECTORY}/documentation")
    # shutil.rmtree(f"{config.ARTIFACT_DIRECTORY}/documentation", ignore_errors=True)
    # shutil.move(f"{config.ARTIFACT_DIRECTORY}/{config.MAIN_PACKAGE}", f"{config.ARTIFACT_DIRECTORY}/documentation")

    # Pre-generated indexes
    if shutil.which("npm") is None:
        message = "'npm' not installed, can't prebuild index"
        if "CI" in os.environ:
            session.error(message)

        session.skip(message)

    print("Prebuilding index...")
    session.run("npm", "install", "[email protected]", external=True)
    session.run(
        "node",
        "scripts/prebuild_index.js",
        f"{config.ARTIFACT_DIRECTORY}/hikari/index.json",
        f"{config.ARTIFACT_DIRECTORY}/hikari/prebuilt_index.json",
        external=True,
    )
Пример #2
0
def remove_trailing_whitespaces(session: nox.Session,
                                check_only: bool = False) -> None:
    session.log(
        f"Searching for stray trailing whitespaces in files ending in {config.REFORMATTING_FILE_EXTS}"
    )

    count = 0
    total = 0

    start = time.perf_counter()
    for path in config.FULL_REFORMATTING_PATHS:
        if os.path.isfile(path):
            total += 1
            count += remove_trailing_whitespaces_for_file(
                path, session, check_only)

        for root, dirs, files in os.walk(path, topdown=True,
                                         followlinks=False):
            for file in files:
                if file.casefold().endswith(config.REFORMATTING_FILE_EXTS):
                    total += 1
                    count += remove_trailing_whitespaces_for_file(
                        os.path.join(root, file), session, check_only)

                i = len(dirs) - 1
                while i >= 0:
                    if dirs[i] == "__pycache__":
                        del dirs[i]
                    i -= 1

    end = time.perf_counter()

    remark = "Good job! " if not count else ""
    message = "Had to fix" if not check_only else "Found issues in"
    session.log(
        f"{message} {count} file(s). "
        f"{remark}Took {1_000 * (end - start):.2f}ms to check {total} files in this project.",
    )

    if check_only and count:
        session.error(
            "Trailing whitespaces found. Try running 'nox -s reformat-code' to fix them"
        )