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)
def lint(session: nox.Session): session.install("pytest", "hypothesis", "pytz", "black", "mypy", "isort") session.run("isort", "--check", "--diff", "iso8601") session.run("black", "--check", "--diff", "iso8601") session.run("mypy", "--strict", "iso8601")
def make_pickle(session: nox.Session) -> None: """ Make a pickle file for this version """ session.install(".[dev]") session.run("python", "tests/pickles/make_pickle.py", *session.posargs)
def test(session: nox.Session): session.install(SETUPTOOLS_RUST, "pytest") session.install("--no-build-isolation", ".") session.run("pytest", *session.posargs)
def docs(session: nox.Session): session.install(".", "Sphinx") session.run("sphinx-build", "docs", "docs/_build")
def lint(session: nox.Session) -> None: """ Lint the codebase (except for clang-format/tidy). """ session.install("pre-commit") session.run("pre-commit", "run", "-a")
def pre_commit(session: nox.Session): """ Run pre-commit on all files. """ session.run("pre-commit", "run", "--files", "noxfile.py", external=True)
def lint(session: nox.Session) -> None: """ Run linters on the codebase. """ session.install("pre-commit") session.run("pre-commit", "run", "--all-files")
def update_constraints(session: nox.Session) -> None: """ Update the dependencies inplace. """ session.install("requests", "pip-tools") session.run("python", "bin/update_dependencies.py")
def _test_dist(session: nox.Session, path: str, pattern: str) -> None: (dist_path,) = Path(path).glob(pattern) session.install(f"{str(dist_path)}[test]") session.run("pytest", "tests/unit")
def develop(session: nox.Session) -> None: session.run("python", "-m", "pip", "install", "--upgrade", "pip", "setuptools") session.install("-e", ".[develop]")
def mypy(session: Session) -> None: """Type-check using mypy.""" install_extras(session, extra="all") args = session.posargs or SOURCE_PATHS session.run("mypy", "--follow-imports=silent", *args, silent=True)
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)
def upload_wheel(session: nox.Session) -> None: """Upload the wheel.""" session.install("twine") session.run("twine", "upload", "dist/*", external=True)
def tests_impl( session: nox.Session, extras: str = "socks,secure,brotli", byte_string_comparisons: bool = True, ) -> None: # Install deps and the package itself. session.install("-r", "dev-requirements.txt") session.install(f".[{extras}]") # Show the pip version. session.run("pip", "--version") # Print the Python version and bytesize. session.run("python", "--version") session.run("python", "-c", "import struct; print(struct.calcsize('P') * 8)") # Print OpenSSL information. session.run("python", "-m", "OpenSSL.debug") # Inspired from https://github.com/pyca/cryptography # We use parallel mode and then combine here so that coverage.py will take # the paths like .tox/pyXY/lib/pythonX.Y/site-packages/urllib3/__init__.py # and collapse them into src/urllib3/__init__.py. session.run( "python", *(("-bb", ) if byte_string_comparisons else ()), "-m", "coverage", "run", "--parallel-mode", "-m", "pytest", "-r", "a", "--tb=native", "--no-success-flaky-report", *(session.posargs or ("test/", )), env={"PYTHONWARNINGS": "always::DeprecationWarning"}, ) session.run("coverage", "combine") session.run("coverage", "report", "-m") session.run("coverage", "xml")
def tests(session: Session): """Run unit tests.""" session.install("-e", ".", *PYTEST_PACKAGES) session.run("pytest")
def git_clone(session: nox.Session, git_url: str) -> None: session.run("git", "clone", "--depth", "1", git_url, external=True)
def black(session: Session): """Check black formatting.""" session.install("black") session.run("black", "--check", *LINT_PATHS)
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")
def isort(session: Session): """Check imports sorting""" session.install("isort") session.run("isort", "--check", *LINT_PATHS)
def test(session: nox.Session): session.install(SETUPTOOLS_RUST, "pytest", "pytest-benchmark", "beautifulsoup4") session.install("--no-build-isolation", ".") session.run("pytest", *session.posargs)
def mypy(session: Session): """Run Mypy""" session.install("mypy", "types-PyYAML") session.run("mypy", *LINT_PATHS)
def check_example(session: nox.Session): session.install(".", "mypy") session.run("mypy", "--strict", "docs/example.py") session.run("python", "docs/example.py")
def pylint(session: Session): """Run pylint""" session.install("pylint", "-e", ".", *PYTEST_PACKAGES) session.run("pylint", "--rcfile=pyproject.toml", *LINT_PATHS)
def test(session: nox.Session): session.install(".") session.install("pytest", "hypothesis", "pytz") session.run("pytest", "-vv", "--tb=short", "--log-level=INFO")
def tests(session: nox.Session) -> None: """ Run the unit and regular tests. """ session.install(".[test]") session.run("pytest", *session.posargs)
def lint(session: nox.Session) -> None: """ Run the linter. """ session.install("pre-commit") session.run("pre-commit", "run", "--all-files", *session.posargs)
def lint(session: nox.Session) -> None: session.install("pre-commit") session.run("pre-commit", "run", "--all-files") mypy(session)
def tests(session: nox.Session): session.install("-e", ".[tests]") session.run("pytest", "-ra", "tests")
def format(session: nox.Session) -> None: session.install("black", "isort") session.run("isort", ".") session.run("black", ".")