Beispiel #1
0
def sphinx(session: nox.Session) -> None:
    """Build the HTML documentation and report warnings as errors.

    The `sphinx` session is more about building than testing.  However, it also checks
    for completeness, substitutions' correctness, and things like that.  Hence, we
    leave it here until we find a strong reason for moving it somewhere else.

    This session passes session-specific arguments to `sphinx-build`.  For example,
    when building the official documentation on Travis-CI, we want to ensure that
    everything is correct, so we pass the `-W` flag to convert warnings into errors:

    nox -s sphinx -- -W
    """
    _install_hydpy(session)
    session.install(
        "docutils",
        "sphinx",
        "sphinxcontrib-fulltoc",
        "sphinxprettysearchresults",
        "sphinxcontrib.bibtex<2",
    )
    session.chdir(_get_sitepackagepath(session))
    with _clean_environment(session):
        session.run("python", "hydpy/tests/run_doctests.py",
                    "--python-mode=false")
    session.run("python", "hydpy/docs/enable_autodoc.py")
    session.run("python", "hydpy/docs/prepare.py")
    session.run("sphinx-build", "hydpy/docs/auto", "hydpy/docs/auto/build",
                *session.posargs)
    session.run("python", "hydpy/docs/modify_html.py")
Beispiel #2
0
def doctest(session: nox.Session) -> None:
    """Execute script `run_doctests.py` and measure code coverage.

    You can define arguments specific to the doctest session.  The `doctest` session
    passes them to the `run_doctests.py` script.  For example, to restrict testing to
    module `armatools.py` in Cython mode, write:

    nox -s doctest -- --file_doctests=armatools.py --python-mode=false

    Or shorter:

    nox -s doctest -- -f armatools.py -p f

    The `doctest` session only measures code coverage when no session-specific
    arguments are given, due to the mentioned restrictions inevitably resulting in
    incomplete code coverage measurements.
    """
    _install_hydpy(session)
    session.install("coverage")
    session.chdir(_get_sitepackagepath(session))
    session.run("python", "hydpy/docs/enable_autodoc.py")
    if not session.posargs:
        shutil.copy("hydpy/tests/hydpydoctestcustomize.py",
                    "hydpydoctestcustomize.py")
        shutil.copy("hydpy/tests/hydpydoctestcustomize.pth",
                    "hydpydoctestcustomize.pth")
    with _clean_environment(session):
        session.run("python", "hydpy/tests/run_doctests.py", *session.posargs)
    if not session.posargs:
        session.run("coverage", "combine")
        session.run("coverage", "report", "-m", "--skip-covered",
                    "--fail-under=100")
Beispiel #3
0
def check_wheel(session: nox.Session) -> None:
    """Check the wheel, should not be used directly."""
    session.install("wheel", "twine")
    session.chdir(f"{session.cache_dir}/dist")
    session.run("twine", "check", "*", external=True)
    session.install(glob.glob("*.whl")[0])
    session.run("python", "-m", "gcovr", "--help", external=True)
Beispiel #4
0
def do_release(session: nox.Session) -> None:
    """Do a release to PyPI."""
    # TODO: maybe add version validation
    if modified_files_in_git() or modified_files_in_git("--staged"):
        session.error(
            "Repository not clean, please remove, unstage, or commit your changes"
        )

    if not len(session.posargs):
        session.error("Usage: nox -s publish -- <version> [publish-args]")
    else:
        version = session.posargs[0]

    update_version(session, version, MAIN_MODULE)
    update_changelog(session, version, CHANGELOG)
    commit_files(session, [MAIN_MODULE, CHANGELOG],
                 message=f"Prepare for release {version}")
    create_git_tag(session, version, message=f"Release {version}")

    with isolated_temporary_checkout(session) as workdir:
        session.chdir(workdir)
        session.install("flit")
        session.run("flit", "publish", *session.posargs[1:])

    session.chdir(THIS_DIR)
    update_version(session, next_development_version(version), MAIN_MODULE)
    update_changelog(session, "<unreleased>", CHANGELOG)
    commit_files(session, [MAIN_MODULE, CHANGELOG],
                 message="Let's get back to development")
    session.log(
        "Alright, just do a push to GitHub and everything should be done")
    session.log("If you're paranoid, go ahead, verify that things are fine")
    session.log("If not, sit back and relax, you just did a release 🎉")
Beispiel #5
0
def tests_pipenv(session: nox.Session):
    """
    Run test suite with pipenv sync.
    """
    tmp_dir = session.create_tmp()
    for to_copy in (package_name, tests_name, pipfile_lock, notebooks_name):
        if Path(to_copy).is_dir():
            copytree(to_copy, Path(tmp_dir) / to_copy)
        elif Path(to_copy).is_file():
            copy2(to_copy, tmp_dir)
        elif Path(to_copy).exists():
            ValueError("File not dir or file.")
        else:
            logging.error(f"Expected {to_copy} to exist.")
    session.chdir(tmp_dir)
    session.install("pipenv")
    session.run("pipenv", "--rm", success_codes=[0, 1])
    session.run(
        "pipenv",
        "sync",
        "--python",
        f"{session.python}",
        "--dev",
        "--bare",
    )
    session.run(
        "pipenv",
        "run",
        "pytest",
    )
Beispiel #6
0
def docs(session: Session, pandas: str) -> None:
    """Build the documentation."""
    if _invalid_python_pandas_versions(session, pandas):
        return
    python_version = version.parse(cast(str, session.python))
    install_extras(
        session,
        pandas,
        extra="all",
        # this is a hack until typed-ast conda package starts working again,
        # basically this issue comes up:
        # https://github.com/python/mypy/pull/2906
        force_pip=python_version == version.parse("3.7"),
    )
    session.chdir("docs")

    shutil.rmtree(os.path.join("_build"), ignore_errors=True)
    args = session.posargs or ["-W", "-E", "-b=doctest", "source", "_build"]
    session.run("sphinx-build", *args)

    # build html docs
    if not CI_RUN and not session.posargs:
        shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
        session.run(
            "sphinx-build",
            "-W",
            "-T",
            "-b=html",
            "-d",
            os.path.join("_build", "doctrees", ""),
            "source",
            os.path.join("_build", "html", ""),
        )
Beispiel #7
0
def docs(session: nox.Session) -> None:
    session.install("-r", "docs/requirements.txt")
    session.install(".[socks,secure,brotli]")

    session.chdir("docs")
    if os.path.exists("_build"):
        shutil.rmtree("_build")
    session.run("sphinx-build", "-b", "html", "-W", ".", "_build/html")
Beispiel #8
0
def doc(session: nox.Session) -> None:
    """Generate the documentation."""
    session.install("-r", "doc/requirements.txt", "docutils")
    session.install("-e", ".")

    # Build the Sphinx documentation
    session.chdir("doc")
    session.run("make", "html", "O=-W", external=True)
    session.chdir("..")

    # Ensure that the README builds fine as a standalone document.
    readme_html = session.create_tmp() + "/README.html"
    session.run("rst2html5.py", "--strict", "README.rst", readme_html)
Beispiel #9
0
def docs(session: nox.Session) -> None:
    """
    Build the docs. Pass "serve" to serve.
    """

    session.install(".[docs]")
    session.chdir("docs")
    session.run("sphinx-build", "-M", "html", ".", "_build")

    if session.posargs:
        if "serve" in session.posargs:
            print("Launching docs at http://localhost:8000/ - use Ctrl-C to quit")
            session.run("python", "-m", "http.server", "8000", "-d", "_build/html")
        else:
            print("Unsupported argument to docs")
Beispiel #10
0
def downstream_botocore(session: nox.Session) -> None:
    root = os.getcwd()
    tmp_dir = session.create_tmp()

    session.cd(tmp_dir)
    git_clone(session, "https://github.com/boto/botocore")
    session.chdir("botocore")
    session.run("git", "rev-parse", "HEAD", external=True)
    session.run("python", "scripts/ci/install")

    session.cd(root)
    session.install(".", silent=False)
    session.cd(f"{tmp_dir}/botocore")

    session.run("python", "-c", "import urllib3; print(urllib3.__version__)")
    session.run("python", "scripts/ci/run-tests")
Beispiel #11
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",
        "pytest-timeout",
        "cmake",
        "yaxmldiff",
    )
    if platform.system() == "Windows":
        session.install("pywin32")
    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 += ["--"] + DEFAULT_TEST_DIRECTORIES
    session.run("python", *args)
Beispiel #12
0
def downstream_requests(session: nox.Session) -> None:
    root = os.getcwd()
    tmp_dir = session.create_tmp()

    session.cd(tmp_dir)
    git_clone(session, "https://github.com/psf/requests")
    session.chdir("requests")
    session.run("git", "apply", f"{root}/ci/requests.patch", external=True)
    session.run("git", "rev-parse", "HEAD", external=True)
    session.install(".[socks]", silent=False)
    session.install("-r", "requirements-dev.txt", silent=False)

    session.cd(root)
    session.install(".", silent=False)
    session.cd(f"{tmp_dir}/requests")

    session.run("python", "-c", "import urllib3; print(urllib3.__version__)")
    session.run("pytest", "tests")
Beispiel #13
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")
Beispiel #14
0
def docs(session: nox.Session) -> str:
    """
    Build the docs.
    """

    wheel = build(session)
    session.install("-r", "requirements-docs.txt")
    session.install(f"./dist/{wheel}")

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

    if session.posargs:
        if "serve" in session.posargs:
            print(
                "Launching docs at http://localhost:8000/ - use Ctrl-C to quit"
            )
            session.run("python", "-m", "http.server", "8000", "-d",
                        "_build/html")
        else:
            print("Unsupported argument to docs")
Beispiel #15
0
def hist(session: nox.Session) -> None:
    """
    Run Hist's test suite
    """
    shutil.rmtree("build", ignore_errors=True)
    session.install(".")
    tmpdir = session.create_tmp()
    session.chdir(tmpdir)
    session.run("git",
                "clone",
                "https://github.com/scikit-hep/hist",
                external=True)
    session.chdir("hist")
    with open("setup.cfg", encoding="utf-8") as f:
        lines = f.readlines()
    with open("setup.cfg", "w", encoding="utf-8") as f:
        for line in lines:
            if "boost-histogram" not in line:
                f.write(line)

    session.install(".[test,plot]")
    session.run("pytest", *session.posargs)
Beispiel #16
0
def docs(session: Session) -> None:
    """Build the documentation."""
    # this is needed until ray and geopandas are supported on python 3.10
    if session.python == "3.10":
        session.skip()

    install_extras(session, extra="all", force_pip=True)
    session.chdir("docs")

    # build html docs
    if not CI_RUN and not session.posargs:
        shutil.rmtree("_build", ignore_errors=True)
        shutil.rmtree(
            os.path.join("source", "reference", "generated"),
            ignore_errors=True,
        )
        for builder in ["doctest", "html"]:
            session.run(
                "sphinx-build",
                "-W",
                "-T",
                f"-b={builder}",
                "-d",
                os.path.join("_build", "doctrees", ""),
                "source",
                os.path.join("_build", builder, ""),
            )
    else:
        shutil.rmtree(os.path.join("_build"), ignore_errors=True)
        args = session.posargs or [
            "-v",
            "-W",
            "-E",
            "-b=doctest",
            "source",
            "_build",
        ]
        session.run("sphinx-build", *args)
Beispiel #17
0
def docs(session: Session, pandas: str) -> None:
    """Build the documentation."""
    if _invalid_python_pandas_versions(session, pandas):
        return
    install_extras(session, pandas, extra="all")
    session.chdir("docs")

    args = session.posargs or ["-W", "-E", "-b=doctest", "source", "_build"]
    session.run("sphinx-build", *args)

    # build html docs
    if not CI_RUN and not session.posargs:
        shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
        session.run(
            "sphinx-build",
            "-W",
            "-T",
            "-b=html",
            "-d",
            os.path.join("_build", "doctrees", ""),
            "source",
            os.path.join("_build", "html", ""),
        )
Beispiel #18
0
def docs(session: nox.Session):
    session.run("poetry", "shell")
    session.chdir("docs")
    shutil.rmtree("_build", ignore_errors=True)
    session.run("sphinx-build", "-b", "html", "-W", ".", "_build/html")
Beispiel #19
0
def doc(session: nox.Session) -> None:
    """Generate the documentation."""
    session.install("-r", "doc/requirements.txt")
    session.install("-e", ".")
    session.chdir("doc")
    session.run("make", "html", "O=-W", external=True)