Exemple #1
0
def _run_pyright(session: nox.Session, *args: str) -> None:
    if _try_find_option(session, "--force-env", when_empty="True"):
        session.env["PYRIGHT_PYTHON_GLOBAL_NODE"] = "off"

    if version := _try_find_option(session, "--pyright-version"):
        session.env["PYRIGHT_PYTHON_FORCE_VERSION"] = version
Exemple #2
0
def docs(session: nox.Session) -> None:
    """
    Build the docs. Pass "serve" to serve.
    """

    session.install("-r", "docs/requirements.txt")
    session.chdir("docs")

    if "pdf" in session.posargs:
        session.run("sphinx-build", "-M", "latexpdf", ".", "_build")
        return

    session.run("sphinx-build", "-M", "html", ".", "_build")

    if "serve" in session.posargs:
        session.log(
            "Launching docs at http://localhost:8000/ - use Ctrl-C to quit")
        session.run("python", "-m", "http.server", "8000", "-d", "_build/html")
    elif session.posargs:
        session.error("Unsupported argument to docs")
Exemple #3
0
def test(session: nox.Session) -> None:
    """Run this project's tests using pytest."""
    install_requirements(session, ".[tanjun]", *_dev_dep("tests"))
    # TODO: can import-mode be specified in the config.
    session.run("pytest", "-n", "auto", "--import-mode", "importlib")
Exemple #4
0
def docker_qa(session: nox.Session) -> None:
    """Build and run the docker container for the default GCC version."""
    session_id = f"docker_qa_compiler({GCC_VERSION2USE})"
    session.log(f"Notify session {session_id}")
    session.notify(session_id)
Exemple #5
0
def qa(session: nox.Session) -> None:
    """Run the quality tests."""
    session_id = "lint"
    session.log(f"Notify session {session_id}")
    session.notify(session_id, [])
    session_id = "doc"
    session.log(f"Notify session {session_id}")
    session.notify(session_id, [])
    session_id = f"tests_compiler({GCC_VERSION2USE})"
    session.log(f"Notify session {session_id}")
    session.notify(session_id)
Exemple #6
0
def tests(session: nox.Session) -> None:
    """Run the tests with the default GCC version."""
    session_id = f"tests_compiler({GCC_VERSION2USE})"
    session.log(f"Notify session {session_id}")
    session.notify(session_id)
Exemple #7
0
def tests_compiler(session: nox.Session, version: str) -> None:
    """Run the test with a specifiv GCC version."""
    session.install(
        "jinja2",
        "lxml",
        "pygments==2.7.4",
        "pytest",
        "cmake",
        "yaxmldiff",
    )
    coverage_args = []
    if os.environ.get("USE_COVERAGE") == "true":
        session.install("pytest-cov")
        coverage_args = ["--cov=gcovr", "--cov-branch"]
    session.install("-e", ".")
    set_environment(session, version)
    session.log("Print tool versions")
    session.run("python", "--version")
    # Use full path to executable
    session.env["CC"] = shutil.which(session.env["CC"]).replace(
        os.path.sep, "/")
    session.run(session.env["CC"], "--version", external=True)
    session.env["CXX"] = shutil.which(session.env["CXX"]).replace(
        os.path.sep, "/")
    session.run(session.env["CXX"], "--version", external=True)
    session.env["GCOV"] = shutil.which(session.env["CC"].replace(
        "clang", "llvm-cov").replace("gcc", "gcov")).replace(os.path.sep, "/")
    session.run(session.env["GCOV"], "--version", external=True)
    if "llvm-cov" in session.env["GCOV"]:
        session.env["GCOV"] += " gcov"

    session.chdir("gcovr/tests")
    session.run("make", "--silent", "clean", external=True)
    session.chdir("../..")
    args = ["-m", "pytest"]
    args += coverage_args
    args += session.posargs
    # For docker tests
    if "NOX_POSARGS" in os.environ:
        args += shlex.split(os.environ["NOX_POSARGS"])
    if "--" not in args:
        args += ["--", "gcovr", "doc/examples"]
    session.run("python", *args)
Exemple #8
0
def prepare_release(session: nox.Session) -> None:
    version = release.get_version_from_arguments(session)
    if not version:
        session.error("Usage: nox -s prepare-release -- <version>")

    session.log("# Ensure nothing is staged")
    if release.modified_files_in_git("--staged"):
        session.error("There are files staged in git")

    session.log(f"# Updating {AUTHORS_FILE}")
    release.generate_authors(AUTHORS_FILE)
    if release.modified_files_in_git():
        release.commit_file(session,
                            AUTHORS_FILE,
                            message=f"Update {AUTHORS_FILE}")
    else:
        session.log(f"# No changes to {AUTHORS_FILE}")

    session.log("# Generating NEWS")
    release.generate_news(session, version)

    session.log(f"# Bumping for release {version}")
    release.update_version_file(version, VERSION_FILE)
    release.commit_file(session, VERSION_FILE, message="Bump for release")

    session.log("# Tagging release")
    release.create_git_tag(session, version, message=f"Release {version}")

    session.log("# Bumping for development")
    next_dev_version = release.get_next_development_version(version)
    release.update_version_file(next_dev_version, VERSION_FILE)
    release.commit_file(session, VERSION_FILE, message="Bump for development")
Exemple #9
0
def build_release(session: nox.Session) -> None:
    version = release.get_version_from_arguments(session)
    if not version:
        session.error("Usage: nox -s build-release -- YY.N[.P]")

    session.log("# Ensure no files in dist/")
    if release.have_files_in_folder("dist"):
        session.error(
            "There are files in dist/. Remove them and try again. "
            "You can use `git clean -fxdi -- dist` command to do this")

    session.log("# Install dependencies")
    session.install("setuptools", "wheel", "twine")

    with release.isolated_temporary_checkout(session, version) as build_dir:
        session.log(
            "# Start the build in an isolated, "
            f"temporary Git checkout at {build_dir!s}", )
        with release.workdir(session, build_dir):
            tmp_dists = build_dists(session)

        tmp_dist_paths = (build_dir / p for p in tmp_dists)
        session.log(f"# Copying dists from {build_dir}")
        os.makedirs("dist", exist_ok=True)
        for dist, final in zip(tmp_dist_paths, tmp_dists):
            session.log(f"# Copying {dist} to {final}")
            shutil.copy(dist, final)
Exemple #10
0
def mypy(session: Session) -> None:
    """Type-check using mypy."""
    install_extras(session, extra="all", pandas_stubs=False)
    args = session.posargs or SOURCE_PATHS
    session.run("mypy", "--follow-imports=silent", *args, silent=True)
Exemple #11
0
def doctests(session: Session) -> None:
    """Build the documentation."""
    install_extras(session, extra="all", force_pip=True)
    session.run("xdoctest", PACKAGE, "--quiet")
Exemple #12
0
def _generate_pip_deps_from_conda(session: Session,
                                  compare: bool = False) -> None:
    args = ["scripts/generate_pip_deps_from_conda.py"]
    if compare:
        args.append("--compare")
    session.run("python", *args)
Exemple #13
0
def lint(session: nox.Session) -> None:
    """
    Lint the codebase (except for clang-format/tidy).
    """
    session.install("pre-commit")
    session.run("pre-commit", "run", "-a")
Exemple #14
0
def make_changelog(session: nox.Session) -> None:
    """
    Inspect the closed issues and make entries for a changelog.
    """
    session.install("ghapi", "rich")
    session.run("python", "tools/make_changelog.py")
Exemple #15
0
def lint(session: nox.Session) -> str:
    """
    Run linters on the codebase.
    """
    session.install("pre-commit")
    session.run("pre-commit", "run", "-a")
Exemple #16
0
def build_dists(session: nox.Session) -> List[str]:
    """Return dists with valid metadata."""
    session.log(
        "# Check if there's any Git-untracked files before building the wheel",
    )

    has_forbidden_git_untracked_files = any(
        # Don't report the environment this session is running in
        not untracked_file.startswith(".nox/build-release/")
        for untracked_file in release.get_git_untracked_files())
    if has_forbidden_git_untracked_files:
        session.error(
            "There are untracked files in the working directory. "
            "Remove them and try again", )

    session.log("# Build distributions")
    session.run("python", "setup.py", "sdist", "bdist_wheel", silent=True)
    produced_dists = glob.glob("dist/*")

    session.log(f"# Verify distributions: {', '.join(produced_dists)}")
    session.run("twine", "check", *produced_dists, silent=True)

    return produced_dists
Exemple #17
0
def bump(session: nox.Session) -> None:
    """
    Set to a new version, use -- <version>, otherwise will use the latest version.
    """
    parser = argparse.ArgumentParser(description="Process some integers.")
    parser.add_argument(
        "--upstream-repository",
        metavar="UPSTREAM_REPOSITORY",
        choices=["Kitware/ninja", "ninja-build/ninja"],
        default="Kitware/ninja",
        help="Ninja upstream repository",
    )
    parser.add_argument("--commit",
                        action="store_true",
                        help="Make a branch and commit.")
    parser.add_argument("version",
                        nargs="?",
                        help="The version to process - leave off for latest.")
    args = parser.parse_args(session.posargs)

    if args.version is None:
        session.install("lastversion")
        version = session.run("lastversion",
                              "--format",
                              "tag",
                              args.upstream_repository,
                              log=False,
                              silent=True).strip()
        if version.startswith("v"):
            version = version[1:]
    else:
        version = args.version

    session.install("requests")

    extra = ["--quiet"] if args.commit else []
    session.run("python", "scripts/update_ninja_version.py",
                "--upstream-repository", args.upstream_repository, version,
                *extra)

    if args.commit:
        session.run("git",
                    "switch",
                    "-c",
                    f"update-to-ninja-{version}",
                    external=True)
        files = (
            "NinjaUrls.cmake",
            "README.rst",
            "tests/test_distribution.py",
            "docs/update_ninja_version.rst",
        )
        session.run(
            "git",
            "add",
            "-u",
            *files,
            external=True,
        )
        session.run("git",
                    "commit",
                    "-m",
                    f"Update to Ninja {version}",
                    external=True)
        session.log(
            'Complete! Now run: gh pr create --fill --body "Created by running `nox -s bump -- --commit`"'
        )
Exemple #18
0
def upload_release(session: nox.Session) -> None:
    version = release.get_version_from_arguments(session)
    if not version:
        session.error("Usage: nox -s upload-release -- YY.N[.P]")

    session.log("# Install dependencies")
    session.install("twine")

    distribution_files = glob.glob("dist/*")
    session.log(f"# Distribution files: {distribution_files}")

    # Sanity check: Make sure there's 2 distribution files.
    count = len(distribution_files)
    if count != 2:
        session.error(
            f"Expected 2 distribution files for upload, got {count}. "
            f"Remove dist/ and run 'nox -s build-release -- {version}'")
    # Sanity check: Make sure the files are correctly named.
    distfile_names = (os.path.basename(fn) for fn in distribution_files)
    expected_distribution_files = [
        f"pip-{version}-py3-none-any.whl",
        f"pip-{version}.tar.gz",
    ]
    if sorted(distfile_names) != sorted(expected_distribution_files):
        session.error(
            f"Distribution files do not seem to be for {version} release.")

    session.log("# Upload distributions")
    session.run("twine", "upload", *distribution_files)
Exemple #19
0
def tests_all_compiler(session: nox.Session) -> None:
    """Run the tests with all GCC versions."""
    for version in GCC_VERSIONS:
        session_id = f"tests_compiler({version})"
        session.log(f"Notify session {session_id}")
        session.notify(session_id)
Exemple #20
0
def flake8(session: nox.Session) -> None:
    """Run this project's modules against the pre-defined flake8 linters."""
    install_requirements(session, *_dev_dep("flake8"))
    session.run("flake8", *GENERAL_TARGETS)
Exemple #21
0
def upload_wheel(session: nox.Session) -> None:
    """Upload the wheel."""
    session.install("twine")
    session.run("twine", "upload", "dist/*", external=True)
Exemple #22
0
def slot_check(session: nox.Session) -> None:
    """Check this project's slotted classes for common mistakes."""
    install_requirements(session, ".[tanjun]", *_dev_dep("lint"))
    session.run("slotscheck", "-m", "sake")
Exemple #23
0
def docker_qa_all_compiler(session: nox.Session) -> None:
    """Build and run the docker container for the all GCC versions."""
    for version in GCC_VERSIONS:
        session_id = f"docker_qa_compiler({version})"
        session.log(f"Notify session {session_id}")
        session.notify(session_id)
Exemple #24
0
def build(session: nox.Session) -> None:
    """Build this project using flit."""
    install_requirements(session, *_dev_dep("publish"))
    session.log("Starting build")
    session.run("flit", "build")
Exemple #25
0
def lint(session: nox.Session) -> None:
    """Run the lint (flake8 and black)."""
    session.install("flake8")
    # Black installs under Pypy but doesn't necessarily run (cf psf/black#2559).
    if platform.python_implementation() == "CPython":
        session.install(BLACK_PINNED_VERSION)
    if session.posargs:
        args = session.posargs
    else:
        args = DEFAULT_LINT_DIRECTORIES
    session.run("flake8", *args)

    if platform.python_implementation() == "CPython":
        if not session.posargs:
            session.run("python", "-m", "black", "--diff", "--check",
                        *BLACK_CONFORM_FILES)
        session.run("python", "-m", "black", "--diff", *args)
    else:
        session.log(
            f"Skip black because of platform {platform.python_implementation()}."
        )
Exemple #26
0
def tests(session: nox.Session) -> None:
    """
    Run the tests (requires a compiler).
    """
    tmpdir = session.create_tmp()
    session.install("cmake")
    session.install("-r", "tests/requirements.txt")
    session.run("cmake", "-S", ".", "-B", tmpdir, "-DPYBIND11_WERROR=ON",
                "-DDOWNLOAD_CATCH=ON", "-DDOWNLOAD_EIGEN=ON", *session.posargs)
    session.run("cmake", "--build", tmpdir)
    session.run("cmake", "--build", tmpdir, "--config=Release", "--target",
                "check")