2019-02-20 16:40:10 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-02-20 16:40:10 +00:00
|
|
|
noxfile
|
|
|
|
~~~~~~~
|
|
|
|
|
|
|
|
Nox configuration script
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-04-09 11:32:38 +01:00
|
|
|
# pylint: disable=resource-leakage,3rd-party-module-not-gated
|
2019-02-20 16:40:10 +00:00
|
|
|
|
|
|
|
# Import Python libs
|
2019-03-16 19:00:01 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2020-04-02 20:10:20 -05:00
|
|
|
|
2019-02-20 16:40:10 +00:00
|
|
|
import datetime
|
2019-04-12 12:02:51 +01:00
|
|
|
import glob
|
2019-03-10 20:17:48 +00:00
|
|
|
import json
|
2019-02-20 16:40:10 +00:00
|
|
|
import os
|
2019-03-15 09:53:42 +00:00
|
|
|
import pprint
|
2019-04-12 12:02:51 +01:00
|
|
|
import shutil
|
2019-06-14 13:07:49 +01:00
|
|
|
import sys
|
2019-04-13 16:24:41 +01:00
|
|
|
import tempfile
|
2019-03-16 19:00:01 +00:00
|
|
|
|
2020-04-02 20:10:20 -05:00
|
|
|
# fmt: off
|
2020-04-09 11:32:38 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.stderr.write(
|
|
|
|
"Do not execute this file directly. Use nox instead, it will know how to handle this file\n"
|
|
|
|
)
|
2019-02-20 16:40:10 +00:00
|
|
|
sys.stderr.flush()
|
|
|
|
exit(1)
|
2020-04-02 20:10:20 -05:00
|
|
|
# fmt: on
|
2019-02-20 16:40:10 +00:00
|
|
|
|
|
|
|
# Import 3rd-party libs
|
|
|
|
import nox # isort:skip
|
2019-03-22 17:27:01 +00:00
|
|
|
from nox.command import CommandFailed # isort:skip
|
2020-04-02 20:10:20 -05:00
|
|
|
|
2019-02-20 16:40:10 +00:00
|
|
|
|
2019-06-05 12:07:28 -06:00
|
|
|
IS_PY3 = sys.version_info > (2,)
|
|
|
|
|
2019-04-11 16:31:48 +01:00
|
|
|
# Be verbose when runing under a CI context
|
2020-04-17 21:37:42 +01:00
|
|
|
CI_RUN = (
|
|
|
|
os.environ.get("JENKINS_URL")
|
|
|
|
or os.environ.get("CI")
|
|
|
|
or os.environ.get("DRONE") is not None
|
|
|
|
)
|
|
|
|
PIP_INSTALL_SILENT = CI_RUN is False
|
2019-04-01 19:41:26 +01:00
|
|
|
|
2019-02-20 16:40:10 +00:00
|
|
|
# Global Path Definitions
|
|
|
|
REPO_ROOT = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
SITECUSTOMIZE_DIR = os.path.join(REPO_ROOT, "tests", "support", "coverage")
|
2019-10-28 13:55:06 +00:00
|
|
|
IS_DARWIN = sys.platform.lower().startswith("darwin")
|
2019-03-01 23:25:31 +00:00
|
|
|
IS_WINDOWS = sys.platform.lower().startswith("win")
|
2019-02-20 16:40:10 +00:00
|
|
|
# Python versions to run against
|
2020-02-07 12:44:53 +00:00
|
|
|
_PYTHON_VERSIONS = ("2", "2.7", "3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9")
|
2019-02-20 16:40:10 +00:00
|
|
|
|
|
|
|
# Nox options
|
|
|
|
# Reuse existing virtualenvs
|
|
|
|
nox.options.reuse_existing_virtualenvs = True
|
|
|
|
# Don't fail on missing interpreters
|
|
|
|
nox.options.error_on_missing_interpreters = False
|
|
|
|
|
2019-10-31 10:14:36 +00:00
|
|
|
# Change current directory to REPO_ROOT
|
|
|
|
os.chdir(REPO_ROOT)
|
|
|
|
|
2019-06-08 18:19:01 +01:00
|
|
|
RUNTESTS_LOGFILE = os.path.join(
|
|
|
|
"artifacts",
|
|
|
|
"logs",
|
|
|
|
"runtests-{}.log".format(datetime.datetime.now().strftime("%Y%m%d%H%M%S.%f")),
|
|
|
|
)
|
|
|
|
|
2019-11-27 15:10:21 +00:00
|
|
|
# Prevent Python from writing bytecode
|
|
|
|
os.environ[str("PYTHONDONTWRITEBYTECODE")] = str("1")
|
|
|
|
|
2019-03-16 19:00:01 +00:00
|
|
|
|
2019-02-20 16:40:10 +00:00
|
|
|
def _create_ci_directories():
|
|
|
|
for dirname in ("logs", "coverage", "xml-unittests-output"):
|
2019-10-31 10:14:36 +00:00
|
|
|
path = os.path.join("artifacts", dirname)
|
2019-02-20 16:40:10 +00:00
|
|
|
if not os.path.exists(path):
|
|
|
|
os.makedirs(path)
|
|
|
|
|
|
|
|
|
2019-04-12 12:02:51 +01:00
|
|
|
def _get_session_python_version_info(session):
|
2019-04-05 15:56:16 +01:00
|
|
|
try:
|
2019-04-12 12:02:51 +01:00
|
|
|
version_info = session._runner._real_python_version_info
|
2019-04-05 15:56:16 +01:00
|
|
|
except AttributeError:
|
2019-06-14 13:07:49 +01:00
|
|
|
old_install_only_value = session._runner.global_config.install_only
|
|
|
|
try:
|
|
|
|
# Force install only to be false for the following chunk of code
|
|
|
|
# For additional information as to why see:
|
|
|
|
# https://github.com/theacodes/nox/pull/181
|
|
|
|
session._runner.global_config.install_only = False
|
|
|
|
session_py_version = session.run(
|
|
|
|
"python",
|
|
|
|
"-c"
|
|
|
|
'import sys; sys.stdout.write("{}.{}.{}".format(*sys.version_info))',
|
|
|
|
silent=True,
|
|
|
|
log=False,
|
|
|
|
)
|
|
|
|
version_info = tuple(
|
|
|
|
int(part) for part in session_py_version.split(".") if part.isdigit()
|
2020-04-02 20:10:20 -05:00
|
|
|
)
|
2019-06-14 13:07:49 +01:00
|
|
|
session._runner._real_python_version_info = version_info
|
|
|
|
finally:
|
|
|
|
session._runner.global_config.install_only = old_install_only_value
|
2019-04-12 12:02:51 +01:00
|
|
|
return version_info
|
|
|
|
|
|
|
|
|
|
|
|
def _get_session_python_site_packages_dir(session):
|
|
|
|
try:
|
|
|
|
site_packages_dir = session._runner._site_packages_dir
|
|
|
|
except AttributeError:
|
2019-06-14 13:07:49 +01:00
|
|
|
old_install_only_value = session._runner.global_config.install_only
|
|
|
|
try:
|
|
|
|
# Force install only to be false for the following chunk of code
|
|
|
|
# For additional information as to why see:
|
|
|
|
# https://github.com/theacodes/nox/pull/181
|
|
|
|
session._runner.global_config.install_only = False
|
|
|
|
site_packages_dir = session.run(
|
|
|
|
"python",
|
|
|
|
"-c"
|
|
|
|
"import sys; from distutils.sysconfig import get_python_lib; sys.stdout.write(get_python_lib())",
|
|
|
|
silent=True,
|
|
|
|
log=False,
|
|
|
|
)
|
|
|
|
session._runner._site_packages_dir = site_packages_dir
|
|
|
|
finally:
|
|
|
|
session._runner.global_config.install_only = old_install_only_value
|
2019-04-12 12:02:51 +01:00
|
|
|
return site_packages_dir
|
|
|
|
|
|
|
|
|
|
|
|
def _get_pydir(session):
|
|
|
|
version_info = _get_session_python_version_info(session)
|
2019-05-10 20:41:54 +01:00
|
|
|
if version_info < (2, 7):
|
|
|
|
session.error("Only Python >= 2.7 is supported")
|
2019-04-12 12:02:51 +01:00
|
|
|
return "py{}.{}".format(*version_info)
|
|
|
|
|
|
|
|
|
|
|
|
def _get_distro_info(session):
|
|
|
|
try:
|
|
|
|
distro = session._runner._distro
|
|
|
|
except AttributeError:
|
|
|
|
# The distro package doesn't output anything for Windows
|
2019-06-14 13:07:49 +01:00
|
|
|
old_install_only_value = session._runner.global_config.install_only
|
|
|
|
try:
|
|
|
|
# Force install only to be false for the following chunk of code
|
|
|
|
# For additional information as to why see:
|
|
|
|
# https://github.com/theacodes/nox/pull/181
|
|
|
|
session._runner.global_config.install_only = False
|
|
|
|
session.install("--progress-bar=off", "distro", silent=PIP_INSTALL_SILENT)
|
|
|
|
output = session.run("distro", "-j", silent=True)
|
|
|
|
distro = json.loads(output.strip())
|
|
|
|
session.log("Distro information:\n%s", pprint.pformat(distro))
|
|
|
|
session._runner._distro = distro
|
|
|
|
finally:
|
|
|
|
session._runner.global_config.install_only = old_install_only_value
|
2019-04-12 12:02:51 +01:00
|
|
|
return distro
|
|
|
|
|
|
|
|
|
|
|
|
def _install_system_packages(session):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-12 12:02:51 +01:00
|
|
|
Because some python packages are provided by the distribution and cannot
|
|
|
|
be pip installed, and because we don't want the whole system python packages
|
|
|
|
on our virtualenvs, we copy the required system python packages into
|
|
|
|
the virtualenv
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-12 12:02:51 +01:00
|
|
|
system_python_packages = {
|
|
|
|
"__debian_based_distros__": ["/usr/lib/python{py_version}/dist-packages/*apt*"]
|
|
|
|
}
|
|
|
|
|
|
|
|
distro = _get_distro_info(session)
|
2019-12-09 18:57:19 +00:00
|
|
|
if not distro["id"].startswith(("debian", "ubuntu")):
|
|
|
|
# This only applies to debian based distributions
|
|
|
|
return
|
|
|
|
|
|
|
|
system_python_packages["{id}-{version}".format(**distro)] = system_python_packages[
|
|
|
|
"{id}-{version_parts[major]}".format(**distro)
|
|
|
|
] = system_python_packages["__debian_based_distros__"][:]
|
|
|
|
|
2019-04-12 12:02:51 +01:00
|
|
|
distro_keys = [
|
|
|
|
"{id}".format(**distro),
|
|
|
|
"{id}-{version}".format(**distro),
|
|
|
|
"{id}-{version_parts[major]}".format(**distro),
|
|
|
|
]
|
|
|
|
version_info = _get_session_python_version_info(session)
|
|
|
|
py_version_keys = ["{}".format(*version_info), "{}.{}".format(*version_info)]
|
|
|
|
session_site_packages_dir = _get_session_python_site_packages_dir(session)
|
|
|
|
for distro_key in distro_keys:
|
|
|
|
if distro_key not in system_python_packages:
|
|
|
|
continue
|
|
|
|
patterns = system_python_packages[distro_key]
|
|
|
|
for pattern in patterns:
|
|
|
|
for py_version in py_version_keys:
|
|
|
|
matches = set(glob.glob(pattern.format(py_version=py_version)))
|
|
|
|
if not matches:
|
|
|
|
continue
|
|
|
|
for match in matches:
|
|
|
|
src = os.path.realpath(match)
|
|
|
|
dst = os.path.join(
|
|
|
|
session_site_packages_dir, os.path.basename(match)
|
2020-04-02 20:10:20 -05:00
|
|
|
)
|
2019-04-12 12:02:51 +01:00
|
|
|
if os.path.exists(dst):
|
|
|
|
session.log(
|
|
|
|
"Not overwritting already existing %s with %s", dst, src
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
session.log("Copying %s into %s", src, dst)
|
|
|
|
if os.path.isdir(src):
|
|
|
|
shutil.copytree(src, dst)
|
|
|
|
else:
|
|
|
|
shutil.copyfile(src, dst)
|
2019-03-24 20:21:01 +00:00
|
|
|
|
2019-04-01 19:41:26 +01:00
|
|
|
|
2019-10-07 18:29:02 +01:00
|
|
|
def _get_distro_pip_constraints(session, transport):
|
2019-04-01 19:41:26 +01:00
|
|
|
# Install requirements
|
2019-10-07 18:29:02 +01:00
|
|
|
distro_constraints = []
|
2019-04-01 19:41:26 +01:00
|
|
|
|
The TCP transport needs the exact same requirements as the ZeroMQ one
```
10:38:21 test_down (integration.runners.test_manage.ManageTest) ... 09:37:29,619 [salt.minion :3064][CRITICAL] Unexpected error while connecting to localhost
10:38:21 Traceback (most recent call last):
10:38:21 File "/tmp/kitchen/testing/salt/minion.py", line 3036, in _connect_syndic
10:38:21 yield syndic.connect_master(failed=failed)
10:38:21 File "/tmp/kitchen/testing/.nox/runtests-parametrized-2-7-coverage-true-crypto-none-transport-tcp/lib/python2.7/site-packages/tornado/gen.py", line 1055, in run
10:38:21 value = future.result()
10:38:21 File "/tmp/kitchen/testing/.nox/runtests-parametrized-2-7-coverage-true-crypto-none-transport-tcp/lib/python2.7/site-packages/tornado/concurrent.py", line 238, in result
10:38:21 raise_exc_info(self._exc_info)
10:38:21 File "/tmp/kitchen/testing/.nox/runtests-parametrized-2-7-coverage-true-crypto-none-transport-tcp/lib/python2.7/site-packages/tornado/gen.py", line 1063, in run
10:38:21 yielded = self.gen.throw(*exc_info)
10:38:21 File "/tmp/kitchen/testing/salt/minion.py", line 1218, in connect_master
10:38:21 master, self.pub_channel = yield self.eval_master(self.opts, self.timeout, self.safe, failed)
10:38:21 File "/tmp/kitchen/testing/.nox/runtests-parametrized-2-7-coverage-true-crypto-none-transport-tcp/lib/python2.7/site-packages/tornado/gen.py", line 1055, in run
10:38:21 value = future.result()
10:38:21 File "/tmp/kitchen/testing/.nox/runtests-parametrized-2-7-coverage-true-crypto-none-transport-tcp/lib/python2.7/site-packages/tornado/concurrent.py", line 238, in result
10:38:21 raise_exc_info(self._exc_info)
10:38:21 File "/tmp/kitchen/testing/.nox/runtests-parametrized-2-7-coverage-true-crypto-none-transport-tcp/lib/python2.7/site-packages/tornado/gen.py", line 307, in wrapper
10:38:21 yielded = next(result)
10:38:21 File "/tmp/kitchen/testing/salt/minion.py", line 713, in eval_master
10:38:21 pub_channel = salt.transport.client.AsyncPubChannel.factory(self.opts, **factory_kwargs)
10:38:21 File "/tmp/kitchen/testing/salt/transport/client.py", line 161, in factory
10:38:21 import salt.transport.zeromq
10:38:21 File "/tmp/kitchen/testing/salt/transport/zeromq.py", line 41, in <module>
10:38:21 import zmq.error
10:38:21 ImportError: No module named zmq.error
```
2019-05-29 13:04:29 +01:00
|
|
|
if transport == "tcp":
|
|
|
|
# The TCP requirements are the exact same requirements as the ZeroMQ ones
|
|
|
|
transport = "zeromq"
|
|
|
|
|
2019-04-01 19:41:26 +01:00
|
|
|
pydir = _get_pydir(session)
|
|
|
|
|
2019-03-20 14:02:51 +00:00
|
|
|
if IS_WINDOWS:
|
2019-10-31 10:14:36 +00:00
|
|
|
_distro_constraints = os.path.join(
|
2019-10-07 18:29:02 +01:00
|
|
|
"requirements", "static", pydir, "{}-windows.txt".format(transport)
|
2020-04-02 20:10:20 -05:00
|
|
|
)
|
2019-10-07 18:29:02 +01:00
|
|
|
if os.path.exists(_distro_constraints):
|
|
|
|
distro_constraints.append(_distro_constraints)
|
2019-10-31 10:14:36 +00:00
|
|
|
_distro_constraints = os.path.join(
|
|
|
|
"requirements", "static", pydir, "windows.txt"
|
2019-10-07 18:29:02 +01:00
|
|
|
)
|
|
|
|
if os.path.exists(_distro_constraints):
|
|
|
|
distro_constraints.append(_distro_constraints)
|
2019-10-31 10:14:36 +00:00
|
|
|
_distro_constraints = os.path.join(
|
2019-10-28 13:55:06 +00:00
|
|
|
"requirements", "static", pydir, "windows-crypto.txt"
|
|
|
|
)
|
|
|
|
if os.path.exists(_distro_constraints):
|
|
|
|
distro_constraints.append(_distro_constraints)
|
|
|
|
elif IS_DARWIN:
|
2019-10-31 10:14:36 +00:00
|
|
|
_distro_constraints = os.path.join(
|
2019-10-28 13:55:06 +00:00
|
|
|
"requirements", "static", pydir, "{}-darwin.txt".format(transport)
|
2020-04-02 20:10:20 -05:00
|
|
|
)
|
2019-10-28 13:55:06 +00:00
|
|
|
if os.path.exists(_distro_constraints):
|
|
|
|
distro_constraints.append(_distro_constraints)
|
2019-10-31 10:14:36 +00:00
|
|
|
_distro_constraints = os.path.join(
|
|
|
|
"requirements", "static", pydir, "darwin.txt"
|
2019-10-28 13:55:06 +00:00
|
|
|
)
|
|
|
|
if os.path.exists(_distro_constraints):
|
|
|
|
distro_constraints.append(_distro_constraints)
|
2019-10-31 10:14:36 +00:00
|
|
|
_distro_constraints = os.path.join(
|
2019-10-28 13:55:06 +00:00
|
|
|
"requirements", "static", pydir, "darwin-crypto.txt"
|
|
|
|
)
|
|
|
|
if os.path.exists(_distro_constraints):
|
|
|
|
distro_constraints.append(_distro_constraints)
|
2019-03-20 14:02:51 +00:00
|
|
|
else:
|
2019-04-12 12:02:51 +01:00
|
|
|
_install_system_packages(session)
|
|
|
|
distro = _get_distro_info(session)
|
2019-03-16 19:00:01 +00:00
|
|
|
distro_keys = [
|
2019-09-30 18:49:03 +01:00
|
|
|
"linux",
|
2019-03-21 11:42:49 +00:00
|
|
|
"{id}".format(**distro),
|
2019-03-16 19:00:01 +00:00
|
|
|
"{id}-{version}".format(**distro),
|
|
|
|
"{id}-{version_parts[major]}".format(**distro),
|
|
|
|
]
|
|
|
|
for distro_key in distro_keys:
|
2019-10-31 10:14:36 +00:00
|
|
|
_distro_constraints = os.path.join(
|
2019-10-07 18:29:02 +01:00
|
|
|
"requirements", "static", pydir, "{}.txt".format(distro_key)
|
2020-04-02 20:10:20 -05:00
|
|
|
)
|
2019-10-07 18:29:02 +01:00
|
|
|
if os.path.exists(_distro_constraints):
|
|
|
|
distro_constraints.append(_distro_constraints)
|
2019-10-31 10:14:36 +00:00
|
|
|
_distro_constraints = os.path.join(
|
2019-10-28 13:55:06 +00:00
|
|
|
"requirements", "static", pydir, "{}-crypto.txt".format(distro_key)
|
2020-04-02 20:10:20 -05:00
|
|
|
)
|
2019-10-28 13:55:06 +00:00
|
|
|
if os.path.exists(_distro_constraints):
|
|
|
|
distro_constraints.append(_distro_constraints)
|
2019-10-31 10:14:36 +00:00
|
|
|
_distro_constraints = os.path.join(
|
|
|
|
"requirements",
|
2019-10-07 18:29:02 +01:00
|
|
|
"static",
|
|
|
|
pydir,
|
|
|
|
"{}-{}.txt".format(transport, distro_key),
|
|
|
|
)
|
|
|
|
if os.path.exists(_distro_constraints):
|
|
|
|
distro_constraints.append(_distro_constraints)
|
2019-10-28 13:55:06 +00:00
|
|
|
distro_constraints.append(_distro_constraints)
|
2019-10-31 10:14:36 +00:00
|
|
|
_distro_constraints = os.path.join(
|
|
|
|
"requirements",
|
2019-10-28 13:55:06 +00:00
|
|
|
"static",
|
|
|
|
pydir,
|
|
|
|
"{}-{}-crypto.txt".format(transport, distro_key),
|
|
|
|
)
|
|
|
|
if os.path.exists(_distro_constraints):
|
|
|
|
distro_constraints.append(_distro_constraints)
|
2019-10-07 18:29:02 +01:00
|
|
|
return distro_constraints
|
2019-03-16 19:00:01 +00:00
|
|
|
|
2019-10-07 18:29:02 +01:00
|
|
|
|
|
|
|
def _install_requirements(session, transport, *extra_requirements):
|
|
|
|
# Install requirements
|
|
|
|
distro_constraints = _get_distro_pip_constraints(session, transport)
|
|
|
|
|
|
|
|
_requirements_files = [
|
2019-10-31 10:14:36 +00:00
|
|
|
os.path.join("requirements", "base.txt"),
|
|
|
|
os.path.join("requirements", "zeromq.txt"),
|
|
|
|
os.path.join("requirements", "pytest.txt"),
|
2019-10-07 18:29:02 +01:00
|
|
|
]
|
|
|
|
if sys.platform.startswith("linux"):
|
2019-10-31 10:14:36 +00:00
|
|
|
requirements_files = [os.path.join("requirements", "static", "linux.in")]
|
2019-10-07 18:29:02 +01:00
|
|
|
elif sys.platform.startswith("win"):
|
|
|
|
requirements_files = [
|
2019-10-31 10:14:36 +00:00
|
|
|
os.path.join("pkg", "windows", "req.txt"),
|
|
|
|
os.path.join("requirements", "static", "windows.in"),
|
2019-10-07 18:29:02 +01:00
|
|
|
]
|
|
|
|
elif sys.platform.startswith("darwin"):
|
|
|
|
requirements_files = [
|
2019-10-31 10:14:36 +00:00
|
|
|
os.path.join("pkg", "osx", "req.txt"),
|
2020-03-23 13:56:41 -06:00
|
|
|
os.path.join("pkg", "osx", "req_ext.txt"),
|
2020-03-23 22:43:53 +00:00
|
|
|
os.path.join("pkg", "osx", "req_pyobjc.txt"),
|
2019-11-10 15:46:10 +00:00
|
|
|
os.path.join("requirements", "static", "darwin.in"),
|
2019-02-20 16:40:10 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
while True:
|
|
|
|
if not requirements_files:
|
|
|
|
break
|
|
|
|
requirements_file = requirements_files.pop(0)
|
2019-02-21 19:32:06 +00:00
|
|
|
|
|
|
|
if requirements_file not in _requirements_files:
|
|
|
|
_requirements_files.append(requirements_file)
|
|
|
|
|
2019-02-20 16:40:10 +00:00
|
|
|
session.log("Processing {}".format(requirements_file))
|
|
|
|
with open(requirements_file) as rfh: # pylint: disable=resource-leakage
|
|
|
|
for line in rfh:
|
|
|
|
line = line.strip()
|
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
if line.startswith("-r"):
|
|
|
|
reqfile = os.path.join(
|
|
|
|
os.path.dirname(requirements_file), line.strip().split()[-1]
|
|
|
|
)
|
|
|
|
if reqfile in _requirements_files:
|
|
|
|
continue
|
|
|
|
_requirements_files.append(reqfile)
|
|
|
|
continue
|
|
|
|
|
|
|
|
for requirements_file in _requirements_files:
|
2019-10-07 18:29:02 +01:00
|
|
|
install_command = ["--progress-bar=off", "-r", requirements_file]
|
|
|
|
for distro_constraint in distro_constraints:
|
|
|
|
install_command.extend(["--constraint", distro_constraint])
|
|
|
|
session.install(*install_command, silent=PIP_INSTALL_SILENT)
|
2019-02-20 16:40:10 +00:00
|
|
|
|
|
|
|
if extra_requirements:
|
2019-10-07 18:29:02 +01:00
|
|
|
install_command = [
|
|
|
|
"--progress-bar=off",
|
|
|
|
]
|
|
|
|
for distro_constraint in distro_constraints:
|
|
|
|
install_command.extend(["--constraint", distro_constraint])
|
|
|
|
install_command += list(extra_requirements)
|
|
|
|
session.install(*install_command, silent=PIP_INSTALL_SILENT)
|
2019-02-20 16:40:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _run_with_coverage(session, *test_cmd):
|
2019-12-26 04:08:22 +00:00
|
|
|
session.install("--progress-bar=off", "coverage==5.0.1", silent=PIP_INSTALL_SILENT)
|
2019-02-20 16:40:10 +00:00
|
|
|
session.run("coverage", "erase")
|
|
|
|
python_path_env_var = os.environ.get("PYTHONPATH") or None
|
|
|
|
if python_path_env_var is None:
|
|
|
|
python_path_env_var = SITECUSTOMIZE_DIR
|
|
|
|
else:
|
2019-04-20 13:25:45 +01:00
|
|
|
python_path_entries = python_path_env_var.split(os.pathsep)
|
|
|
|
if SITECUSTOMIZE_DIR in python_path_entries:
|
|
|
|
python_path_entries.remove(SITECUSTOMIZE_DIR)
|
|
|
|
python_path_entries.insert(0, SITECUSTOMIZE_DIR)
|
|
|
|
python_path_env_var = os.pathsep.join(python_path_entries)
|
2019-11-12 17:25:30 +00:00
|
|
|
|
|
|
|
env = {
|
|
|
|
# The updated python path so that sitecustomize is importable
|
|
|
|
"PYTHONPATH": python_path_env_var,
|
|
|
|
# The full path to the .coverage data file. Makes sure we always write
|
|
|
|
# them to the same directory
|
|
|
|
"COVERAGE_FILE": os.path.abspath(os.path.join(REPO_ROOT, ".coverage")),
|
|
|
|
# Instruct sub processes to also run under coverage
|
|
|
|
"COVERAGE_PROCESS_START": os.path.join(REPO_ROOT, ".coveragerc"),
|
|
|
|
}
|
|
|
|
if IS_DARWIN:
|
|
|
|
# Don't nuke our multiprocessing efforts objc!
|
|
|
|
# https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr
|
|
|
|
env["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
|
|
|
|
|
2019-04-20 11:53:27 +01:00
|
|
|
try:
|
2019-11-12 17:25:30 +00:00
|
|
|
session.run(*test_cmd, env=env)
|
2019-04-20 11:53:27 +01:00
|
|
|
finally:
|
|
|
|
# Always combine and generate the XML coverage report
|
2019-07-11 17:09:24 +01:00
|
|
|
try:
|
|
|
|
session.run("coverage", "combine")
|
|
|
|
except CommandFailed:
|
|
|
|
# Sometimes some of the coverage files are corrupt which would trigger a CommandFailed
|
|
|
|
# exception
|
|
|
|
pass
|
2019-10-23 14:58:59 +01:00
|
|
|
# Generate report for salt code coverage
|
|
|
|
session.run(
|
|
|
|
"coverage",
|
|
|
|
"xml",
|
2019-10-31 10:14:36 +00:00
|
|
|
"-o",
|
|
|
|
os.path.join("artifacts", "coverage", "salt.xml"),
|
2019-10-23 14:58:59 +01:00
|
|
|
"--omit=tests/*",
|
|
|
|
"--include=salt/*",
|
|
|
|
)
|
|
|
|
# Generate report for tests code coverage
|
|
|
|
session.run(
|
|
|
|
"coverage",
|
|
|
|
"xml",
|
2019-10-31 10:14:36 +00:00
|
|
|
"-o",
|
|
|
|
os.path.join("artifacts", "coverage", "tests.xml"),
|
2019-10-23 14:58:59 +01:00
|
|
|
"--omit=salt/*",
|
|
|
|
"--include=tests/*",
|
|
|
|
)
|
2019-02-20 16:40:10 +00:00
|
|
|
|
|
|
|
|
2019-04-14 16:00:34 +01:00
|
|
|
def _runtests(session, coverage, cmd_args):
|
2019-02-20 16:40:10 +00:00
|
|
|
# Create required artifacts directories
|
|
|
|
_create_ci_directories()
|
2019-03-22 17:27:01 +00:00
|
|
|
try:
|
|
|
|
if coverage is True:
|
2019-04-20 18:08:51 +01:00
|
|
|
_run_with_coverage(
|
|
|
|
session,
|
|
|
|
"coverage",
|
|
|
|
"run",
|
|
|
|
os.path.join("tests", "runtests.py"),
|
|
|
|
*cmd_args
|
|
|
|
)
|
2019-03-22 17:27:01 +00:00
|
|
|
else:
|
2019-11-12 17:25:30 +00:00
|
|
|
cmd_args = ["python", os.path.join("tests", "runtests.py")] + list(cmd_args)
|
|
|
|
env = None
|
|
|
|
if IS_DARWIN:
|
|
|
|
# Don't nuke our multiprocessing efforts objc!
|
|
|
|
# https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr
|
|
|
|
env = {"OBJC_DISABLE_INITIALIZE_FORK_SAFETY": "YES"}
|
|
|
|
session.run(*cmd_args, env=env)
|
2019-12-03 11:51:53 +00:00
|
|
|
except CommandFailed: # pylint: disable=try-except-raise
|
2019-04-14 15:58:31 +01:00
|
|
|
# Disabling re-running failed tests for the time being
|
|
|
|
raise
|
|
|
|
|
|
|
|
# pylint: disable=unreachable
|
2019-03-22 17:27:01 +00:00
|
|
|
names_file_path = os.path.join("artifacts", "failed-tests.txt")
|
2019-04-04 23:37:46 +01:00
|
|
|
session.log("Re-running failed tests if possible")
|
2019-04-16 12:55:48 +01:00
|
|
|
session.install(
|
|
|
|
"--progress-bar=off", "xunitparser==1.3.3", silent=PIP_INSTALL_SILENT
|
|
|
|
)
|
2019-03-22 17:27:01 +00:00
|
|
|
session.run(
|
|
|
|
"python",
|
|
|
|
os.path.join(
|
|
|
|
"tests", "support", "generate-names-file-from-failed-test-reports.py"
|
|
|
|
),
|
|
|
|
names_file_path,
|
|
|
|
)
|
|
|
|
if not os.path.exists(names_file_path):
|
2019-04-07 19:19:18 +01:00
|
|
|
session.log(
|
|
|
|
"Failed tests file(%s) was not found. Not rerunning failed tests.",
|
|
|
|
names_file_path,
|
|
|
|
)
|
|
|
|
# raise the original exception
|
|
|
|
raise
|
2019-03-22 17:27:01 +00:00
|
|
|
with open(names_file_path) as rfh:
|
2019-04-07 19:19:18 +01:00
|
|
|
contents = rfh.read().strip()
|
|
|
|
if not contents:
|
|
|
|
session.log(
|
|
|
|
"The failed tests file(%s) is empty. Not rerunning failed tests.",
|
|
|
|
names_file_path,
|
|
|
|
)
|
|
|
|
# raise the original exception
|
|
|
|
raise
|
|
|
|
failed_tests_count = len(contents.splitlines())
|
2019-03-22 17:27:01 +00:00
|
|
|
if failed_tests_count > 500:
|
|
|
|
# 500 test failures?! Something else must have gone wrong, don't even bother
|
|
|
|
session.error(
|
|
|
|
"Total failed tests({}) > 500. No point on re-running the failed tests".format(
|
|
|
|
failed_tests_count
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
for idx, flag in enumerate(cmd_args[:]):
|
|
|
|
if "--names-file=" in flag:
|
|
|
|
cmd_args.pop(idx)
|
|
|
|
break
|
|
|
|
elif flag == "--names-file":
|
|
|
|
cmd_args.pop(idx) # pop --names-file
|
|
|
|
cmd_args.pop(idx) # pop the actual names file
|
|
|
|
break
|
|
|
|
cmd_args.append("--names-file={}".format(names_file_path))
|
|
|
|
if coverage is True:
|
|
|
|
_run_with_coverage(
|
|
|
|
session, "coverage", "run", "-m", "tests.runtests", *cmd_args
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
session.run("python", os.path.join("tests", "runtests.py"), *cmd_args)
|
2019-04-14 15:58:31 +01:00
|
|
|
# pylint: enable=unreachable
|
2019-02-20 16:40:10 +00:00
|
|
|
|
|
|
|
|
2019-03-25 17:49:33 +00:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-parametrized")
|
2019-03-25 15:07:39 +00:00
|
|
|
@nox.parametrize("coverage", [False, True])
|
2019-10-07 17:56:46 +01:00
|
|
|
@nox.parametrize("transport", ["zeromq", "tcp"])
|
2020-04-23 09:32:34 +01:00
|
|
|
@nox.parametrize("crypto", [None, "m2crypto", "pycryptodome"])
|
2019-03-25 17:49:33 +00:00
|
|
|
def runtests_parametrized(session, coverage, transport, crypto):
|
2019-03-25 15:07:39 +00:00
|
|
|
# Install requirements
|
2019-11-26 18:19:05 +00:00
|
|
|
_install_requirements(session, transport, "unittest-xml-reporting==2.5.2")
|
2019-03-25 15:07:39 +00:00
|
|
|
|
2019-03-25 17:49:33 +00:00
|
|
|
if crypto:
|
2020-04-23 09:32:34 +01:00
|
|
|
session.run(
|
|
|
|
"pip",
|
|
|
|
"uninstall",
|
|
|
|
"-y",
|
|
|
|
"m2crypto",
|
|
|
|
"pycrypto",
|
|
|
|
"pycryptodome",
|
|
|
|
"pycryptodomex",
|
|
|
|
silent=True,
|
|
|
|
)
|
2019-10-07 18:29:02 +01:00
|
|
|
distro_constraints = _get_distro_pip_constraints(session, transport)
|
|
|
|
install_command = [
|
|
|
|
"--progress-bar=off",
|
|
|
|
]
|
|
|
|
for distro_constraint in distro_constraints:
|
|
|
|
install_command.extend(["--constraint", distro_constraint])
|
|
|
|
install_command.append(crypto)
|
|
|
|
session.install(*install_command, silent=PIP_INSTALL_SILENT)
|
2019-03-25 17:49:33 +00:00
|
|
|
|
2019-03-25 15:07:39 +00:00
|
|
|
cmd_args = [
|
2019-06-08 18:19:01 +01:00
|
|
|
"--tests-logfile={}".format(RUNTESTS_LOGFILE),
|
2019-03-25 15:07:39 +00:00
|
|
|
"--transport={}".format(transport),
|
|
|
|
] + session.posargs
|
2019-04-14 16:00:34 +01:00
|
|
|
_runtests(session, coverage, cmd_args)
|
2019-03-25 15:07:39 +00:00
|
|
|
|
|
|
|
|
2019-03-25 17:49:33 +00:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS)
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def runtests(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
runtests.py session with zeromq transport and default crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
|
|
|
"runtests-parametrized-{}(coverage={}, crypto=None, transport='zeromq')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
2019-03-25 15:07:39 +00:00
|
|
|
|
|
|
|
|
2019-04-05 15:57:30 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-tcp")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def runtests_tcp(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-05 15:57:30 +01:00
|
|
|
runtests.py session with TCP transport and default crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-05 15:57:30 +01:00
|
|
|
session.notify(
|
|
|
|
"runtests-parametrized-{}(coverage={}, crypto=None, transport='tcp')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-03-25 17:49:33 +00:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-zeromq")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def runtests_zeromq(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
runtests.py session with zeromq transport and default crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
|
|
|
"runtests-parametrized-{}(coverage={}, crypto=None, transport='zeromq')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-03-25 15:07:39 +00:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-m2crypto")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
2019-03-25 17:49:33 +00:00
|
|
|
def runtests_m2crypto(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
runtests.py session with zeromq transport and m2crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
|
|
|
"runtests-parametrized-{}(coverage={}, crypto='m2crypto', transport='zeromq')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-04-05 15:57:30 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-tcp-m2crypto")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def runtests_tcp_m2crypto(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-05 15:57:30 +01:00
|
|
|
runtests.py session with TCP transport and m2crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-05 15:57:30 +01:00
|
|
|
session.notify(
|
|
|
|
"runtests-parametrized-{}(coverage={}, crypto='m2crypto', transport='tcp')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-03-25 17:49:33 +00:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-zeromq-m2crypto")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def runtests_zeromq_m2crypto(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
runtests.py session with zeromq transport and m2crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
|
|
|
"runtests-parametrized-{}(coverage={}, crypto='m2crypto', transport='zeromq')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-23 09:32:34 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-pycryptodome")
|
2019-03-25 15:07:39 +00:00
|
|
|
@nox.parametrize("coverage", [False, True])
|
2020-04-23 09:32:34 +01:00
|
|
|
def runtests_pycryptodome(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-04-23 09:32:34 +01:00
|
|
|
runtests.py session with zeromq transport and pycryptodome
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
2020-04-23 09:32:34 +01:00
|
|
|
"runtests-parametrized-{}(coverage={}, crypto='pycryptodome', transport='zeromq')".format(
|
2019-03-25 17:49:33 +00:00
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
2019-03-25 15:07:39 +00:00
|
|
|
|
|
|
|
|
2020-04-23 09:32:34 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-tcp-pycryptodome")
|
2019-04-05 15:57:30 +01:00
|
|
|
@nox.parametrize("coverage", [False, True])
|
2020-04-23 09:32:34 +01:00
|
|
|
def runtests_tcp_pycryptodome(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-04-23 09:32:34 +01:00
|
|
|
runtests.py session with TCP transport and pycryptodome
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-05 15:57:30 +01:00
|
|
|
session.notify(
|
2020-04-23 09:32:34 +01:00
|
|
|
"runtests-parametrized-{}(coverage={}, crypto='pycryptodome', transport='tcp')".format(
|
2019-04-05 15:57:30 +01:00
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-23 09:32:34 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-zeromq-pycryptodome")
|
2019-03-25 17:49:33 +00:00
|
|
|
@nox.parametrize("coverage", [False, True])
|
2020-04-23 09:32:34 +01:00
|
|
|
def runtests_zeromq_pycryptodome(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-04-23 09:32:34 +01:00
|
|
|
runtests.py session with zeromq transport and pycryptodome
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
2020-04-23 09:32:34 +01:00
|
|
|
"runtests-parametrized-{}(coverage={}, crypto='pycryptodome', transport='zeromq')".format(
|
2019-03-25 17:49:33 +00:00
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-04-18 18:48:42 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-cloud")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def runtests_cloud(session, coverage):
|
|
|
|
# Install requirements
|
|
|
|
_install_requirements(session, "zeromq", "unittest-xml-reporting==2.2.1")
|
|
|
|
|
|
|
|
pydir = _get_pydir(session)
|
2019-10-31 10:14:36 +00:00
|
|
|
cloud_requirements = os.path.join("requirements", "static", pydir, "cloud.txt")
|
2019-04-18 18:48:42 +01:00
|
|
|
|
|
|
|
session.install(
|
|
|
|
"--progress-bar=off", "-r", cloud_requirements, silent=PIP_INSTALL_SILENT
|
|
|
|
)
|
|
|
|
|
|
|
|
cmd_args = [
|
2019-06-08 18:19:01 +01:00
|
|
|
"--tests-logfile={}".format(RUNTESTS_LOGFILE),
|
2019-04-18 18:48:42 +01:00
|
|
|
"--cloud-provider-tests",
|
|
|
|
] + session.posargs
|
|
|
|
_runtests(session, coverage, cmd_args)
|
|
|
|
|
|
|
|
|
2019-04-18 18:52:27 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="runtests-tornado")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def runtests_tornado(session, coverage):
|
|
|
|
# Install requirements
|
|
|
|
_install_requirements(session, "zeromq", "unittest-xml-reporting==2.2.1")
|
|
|
|
session.install("--progress-bar=off", "tornado==5.0.2", silent=PIP_INSTALL_SILENT)
|
|
|
|
session.install("--progress-bar=off", "pyzmq==17.0.0", silent=PIP_INSTALL_SILENT)
|
|
|
|
|
2019-06-08 18:19:01 +01:00
|
|
|
cmd_args = ["--tests-logfile={}".format(RUNTESTS_LOGFILE)] + session.posargs
|
2019-04-18 18:52:27 +01:00
|
|
|
_runtests(session, coverage, cmd_args)
|
|
|
|
|
|
|
|
|
2019-03-25 17:49:33 +00:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-parametrized")
|
2019-02-20 16:40:10 +00:00
|
|
|
@nox.parametrize("coverage", [False, True])
|
2019-10-07 17:56:46 +01:00
|
|
|
@nox.parametrize("transport", ["zeromq", "tcp"])
|
2020-04-23 09:32:34 +01:00
|
|
|
@nox.parametrize("crypto", [None, "m2crypto", "pycryptodome"])
|
2019-03-25 17:49:33 +00:00
|
|
|
def pytest_parametrized(session, coverage, transport, crypto):
|
2019-02-20 16:40:10 +00:00
|
|
|
# Install requirements
|
2019-03-25 14:51:45 +00:00
|
|
|
_install_requirements(session, transport)
|
2019-02-20 16:40:10 +00:00
|
|
|
|
2020-05-07 19:10:55 +01:00
|
|
|
session.run(
|
|
|
|
"pip", "uninstall", "-y", "pytest-salt", silent=True,
|
|
|
|
)
|
2019-03-25 17:49:33 +00:00
|
|
|
if crypto:
|
2020-04-23 09:32:34 +01:00
|
|
|
session.run(
|
|
|
|
"pip",
|
|
|
|
"uninstall",
|
|
|
|
"-y",
|
|
|
|
"m2crypto",
|
|
|
|
"pycrypto",
|
|
|
|
"pycryptodome",
|
|
|
|
"pycryptodomex",
|
|
|
|
silent=True,
|
|
|
|
)
|
2019-10-07 18:29:02 +01:00
|
|
|
distro_constraints = _get_distro_pip_constraints(session, transport)
|
|
|
|
install_command = [
|
|
|
|
"--progress-bar=off",
|
|
|
|
]
|
|
|
|
for distro_constraint in distro_constraints:
|
|
|
|
install_command.extend(["--constraint", distro_constraint])
|
|
|
|
install_command.append(crypto)
|
|
|
|
session.install(*install_command, silent=PIP_INSTALL_SILENT)
|
2019-03-25 17:49:33 +00:00
|
|
|
|
2019-02-20 16:40:10 +00:00
|
|
|
cmd_args = [
|
|
|
|
"--rootdir",
|
|
|
|
REPO_ROOT,
|
2019-06-08 18:19:01 +01:00
|
|
|
"--log-file={}".format(RUNTESTS_LOGFILE),
|
|
|
|
"--log-file-level=debug",
|
2019-02-20 16:40:10 +00:00
|
|
|
"--no-print-logs",
|
|
|
|
"-ra",
|
2019-03-25 14:51:45 +00:00
|
|
|
"-s",
|
|
|
|
"--transport={}".format(transport),
|
2019-02-20 16:40:10 +00:00
|
|
|
] + session.posargs
|
2019-04-14 16:00:34 +01:00
|
|
|
_pytest(session, coverage, cmd_args)
|
2019-03-25 15:07:39 +00:00
|
|
|
|
|
|
|
|
2019-03-25 17:49:33 +00:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS)
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def pytest(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
pytest session with zeromq transport and default crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
|
|
|
"pytest-parametrized-{}(coverage={}, crypto=None, transport='zeromq')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
2019-03-25 15:07:39 +00:00
|
|
|
|
|
|
|
|
2019-04-05 15:57:30 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-tcp")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def pytest_tcp(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-05 15:57:30 +01:00
|
|
|
pytest session with TCP transport and default crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-05 15:57:30 +01:00
|
|
|
session.notify(
|
|
|
|
"pytest-parametrized-{}(coverage={}, crypto=None, transport='tcp')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-03-25 17:49:33 +00:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-zeromq")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def pytest_zeromq(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
pytest session with zeromq transport and default crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
|
|
|
"pytest-parametrized-{}(coverage={}, crypto=None, transport='zeromq')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-03-25 15:07:39 +00:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-m2crypto")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
2019-03-25 17:49:33 +00:00
|
|
|
def pytest_m2crypto(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
pytest session with zeromq transport and m2crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
|
|
|
"pytest-parametrized-{}(coverage={}, crypto='m2crypto', transport='zeromq')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-04-05 15:57:30 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-tcp-m2crypto")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def pytest_tcp_m2crypto(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-05 15:57:30 +01:00
|
|
|
pytest session with TCP transport and m2crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-05 15:57:30 +01:00
|
|
|
session.notify(
|
|
|
|
"pytest-parametrized-{}(coverage={}, crypto='m2crypto', transport='tcp')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-03-25 17:49:33 +00:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-zeromq-m2crypto")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def pytest_zeromq_m2crypto(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
pytest session with zeromq transport and m2crypto
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
|
|
|
"pytest-parametrized-{}(coverage={}, crypto='m2crypto', transport='zeromq')".format(
|
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-23 09:32:34 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-pycryptodome")
|
2019-03-25 15:07:39 +00:00
|
|
|
@nox.parametrize("coverage", [False, True])
|
2020-04-23 09:32:34 +01:00
|
|
|
def pytest_pycryptodome(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-04-23 09:32:34 +01:00
|
|
|
pytest session with zeromq transport and pycryptodome
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
2020-04-23 09:32:34 +01:00
|
|
|
"pytest-parametrized-{}(coverage={}, crypto='pycryptodome', transport='zeromq')".format(
|
2019-03-25 17:49:33 +00:00
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-23 09:32:34 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-tcp-pycryptodome")
|
2019-04-05 15:57:30 +01:00
|
|
|
@nox.parametrize("coverage", [False, True])
|
2020-04-23 09:32:34 +01:00
|
|
|
def pytest_tcp_pycryptodome(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-04-23 09:32:34 +01:00
|
|
|
pytest session with TCP transport and pycryptodome
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-05 15:57:30 +01:00
|
|
|
session.notify(
|
2020-04-23 09:32:34 +01:00
|
|
|
"pytest-parametrized-{}(coverage={}, crypto='pycryptodome', transport='tcp')".format(
|
2019-04-05 15:57:30 +01:00
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-23 09:32:34 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-zeromq-pycryptodome")
|
2019-03-25 17:49:33 +00:00
|
|
|
@nox.parametrize("coverage", [False, True])
|
2020-04-23 09:32:34 +01:00
|
|
|
def pytest_zeromq_pycryptodome(session, coverage):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-04-23 09:32:34 +01:00
|
|
|
pytest session with zeromq transport and pycryptodome
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-25 17:49:33 +00:00
|
|
|
session.notify(
|
2020-04-23 09:32:34 +01:00
|
|
|
"pytest-parametrized-{}(coverage={}, crypto='pycryptodome', transport='zeromq')".format(
|
2019-03-25 17:49:33 +00:00
|
|
|
session.python, coverage
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-04-18 18:48:42 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-cloud")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def pytest_cloud(session, coverage):
|
|
|
|
# Install requirements
|
|
|
|
_install_requirements(session, "zeromq")
|
|
|
|
pydir = _get_pydir(session)
|
2019-10-31 10:14:36 +00:00
|
|
|
cloud_requirements = os.path.join("requirements", "static", pydir, "cloud.txt")
|
2019-04-18 18:48:42 +01:00
|
|
|
|
|
|
|
session.install(
|
|
|
|
"--progress-bar=off", "-r", cloud_requirements, silent=PIP_INSTALL_SILENT
|
|
|
|
)
|
|
|
|
|
|
|
|
cmd_args = [
|
|
|
|
"--rootdir",
|
|
|
|
REPO_ROOT,
|
2019-06-08 18:19:01 +01:00
|
|
|
"--log-file={}".format(RUNTESTS_LOGFILE),
|
|
|
|
"--log-file-level=debug",
|
2019-04-18 18:48:42 +01:00
|
|
|
"--no-print-logs",
|
|
|
|
"-ra",
|
|
|
|
"-s",
|
2020-04-09 11:32:38 +01:00
|
|
|
"--run-expensive",
|
|
|
|
"-k",
|
|
|
|
"cloud",
|
2019-04-18 18:48:42 +01:00
|
|
|
] + session.posargs
|
|
|
|
_pytest(session, coverage, cmd_args)
|
|
|
|
|
|
|
|
|
2019-04-18 18:52:27 +01:00
|
|
|
@nox.session(python=_PYTHON_VERSIONS, name="pytest-tornado")
|
|
|
|
@nox.parametrize("coverage", [False, True])
|
|
|
|
def pytest_tornado(session, coverage):
|
|
|
|
# Install requirements
|
|
|
|
_install_requirements(session, "zeromq")
|
|
|
|
session.install("--progress-bar=off", "tornado==5.0.2", silent=PIP_INSTALL_SILENT)
|
|
|
|
session.install("--progress-bar=off", "pyzmq==17.0.0", silent=PIP_INSTALL_SILENT)
|
|
|
|
|
|
|
|
cmd_args = [
|
|
|
|
"--rootdir",
|
|
|
|
REPO_ROOT,
|
2019-06-08 18:19:01 +01:00
|
|
|
"--log-file={}".format(RUNTESTS_LOGFILE),
|
|
|
|
"--log-file-level=debug",
|
2019-04-18 18:52:27 +01:00
|
|
|
"--no-print-logs",
|
|
|
|
"-ra",
|
|
|
|
"-s",
|
|
|
|
] + session.posargs
|
|
|
|
_pytest(session, coverage, cmd_args)
|
|
|
|
|
|
|
|
|
2019-04-14 16:00:34 +01:00
|
|
|
def _pytest(session, coverage, cmd_args):
|
2019-03-25 15:07:39 +00:00
|
|
|
# Create required artifacts directories
|
|
|
|
_create_ci_directories()
|
2019-02-20 16:40:10 +00:00
|
|
|
|
2019-11-12 17:25:30 +00:00
|
|
|
env = None
|
|
|
|
if IS_DARWIN:
|
|
|
|
# Don't nuke our multiprocessing efforts objc!
|
|
|
|
# https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr
|
|
|
|
env = {"OBJC_DISABLE_INITIALIZE_FORK_SAFETY": "YES"}
|
|
|
|
|
2020-04-17 21:37:42 +01:00
|
|
|
if CI_RUN:
|
|
|
|
# We'll print out the collected tests on CI runs.
|
|
|
|
# This will show a full list of what tests are going to run, in the right order, which, in case
|
|
|
|
# of a test suite hang, helps us pinpoint which test is hanging
|
|
|
|
session.run(
|
|
|
|
"python", "-m", "pytest", *(cmd_args + ["--collect-only", "-qqq"]), env=env
|
|
|
|
)
|
|
|
|
|
2019-03-22 17:27:01 +00:00
|
|
|
try:
|
|
|
|
if coverage is True:
|
2020-04-10 13:20:52 +01:00
|
|
|
_run_with_coverage(
|
|
|
|
session, "python", "-m", "coverage", "run", "-m", "pytest", *cmd_args
|
|
|
|
)
|
2019-03-22 17:27:01 +00:00
|
|
|
else:
|
2020-04-10 13:20:52 +01:00
|
|
|
session.run("python", "-m", "pytest", *cmd_args, env=env)
|
2019-12-03 14:10:08 +00:00
|
|
|
except CommandFailed: # pylint: disable=try-except-raise
|
2019-06-08 18:20:06 +01:00
|
|
|
# Not rerunning failed tests for now
|
|
|
|
raise
|
|
|
|
|
|
|
|
# pylint: disable=unreachable
|
2019-03-22 17:27:01 +00:00
|
|
|
# Re-run failed tests
|
|
|
|
session.log("Re-running failed tests")
|
2019-06-07 07:11:17 +01:00
|
|
|
|
|
|
|
for idx, parg in enumerate(cmd_args):
|
|
|
|
if parg.startswith("--junitxml="):
|
|
|
|
cmd_args[idx] = parg.replace(".xml", "-rerun-failed.xml")
|
2019-03-22 17:27:01 +00:00
|
|
|
cmd_args.append("--lf")
|
|
|
|
if coverage is True:
|
2020-04-10 13:20:52 +01:00
|
|
|
_run_with_coverage(
|
|
|
|
session, "python", "-m", "coverage", "run", "-m", "pytest", *cmd_args
|
|
|
|
)
|
2019-03-22 17:27:01 +00:00
|
|
|
else:
|
2020-04-10 13:20:52 +01:00
|
|
|
session.run("python", "-m", "pytest", *cmd_args, env=env)
|
2019-06-08 18:20:06 +01:00
|
|
|
# pylint: enable=unreachable
|
2019-04-01 19:41:26 +01:00
|
|
|
|
|
|
|
|
2019-12-03 12:24:05 +00:00
|
|
|
class Tee:
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-12-03 12:24:05 +00:00
|
|
|
Python class to mimic linux tee behaviour
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
|
|
|
|
2019-12-03 12:24:05 +00:00
|
|
|
def __init__(self, first, second):
|
|
|
|
self._first = first
|
|
|
|
self._second = second
|
|
|
|
|
|
|
|
def write(self, b):
|
|
|
|
wrote = self._first.write(b)
|
|
|
|
self._first.flush()
|
|
|
|
self._second.write(b)
|
|
|
|
self._second.flush()
|
|
|
|
|
|
|
|
def fileno(self):
|
|
|
|
return self._first.fileno()
|
|
|
|
|
|
|
|
|
2020-01-03 13:30:03 +00:00
|
|
|
def _lint(session, rcfile, flags, paths, tee_output=True):
|
2019-04-01 19:41:26 +01:00
|
|
|
_install_requirements(session, "zeromq")
|
2019-10-22 17:30:18 +01:00
|
|
|
requirements_file = "requirements/static/lint.in"
|
|
|
|
distro_constraints = ["requirements/static/{}/lint.txt".format(_get_pydir(session))]
|
|
|
|
install_command = ["--progress-bar=off", "-r", requirements_file]
|
|
|
|
for distro_constraint in distro_constraints:
|
|
|
|
install_command.extend(["--constraint", distro_constraint])
|
|
|
|
session.install(*install_command, silent=PIP_INSTALL_SILENT)
|
2020-01-03 13:30:03 +00:00
|
|
|
|
|
|
|
if tee_output:
|
|
|
|
session.run("pylint", "--version")
|
|
|
|
pylint_report_path = os.environ.get("PYLINT_REPORT")
|
2019-04-01 19:41:26 +01:00
|
|
|
|
|
|
|
cmd_args = ["pylint", "--rcfile={}".format(rcfile)] + list(flags) + list(paths)
|
|
|
|
|
2020-01-03 13:30:03 +00:00
|
|
|
cmd_kwargs = {"env": {"PYTHONUNBUFFERED": "1"}}
|
|
|
|
|
|
|
|
if tee_output:
|
|
|
|
stdout = tempfile.TemporaryFile(mode="w+b")
|
|
|
|
cmd_kwargs["stdout"] = Tee(stdout, sys.__stdout__)
|
|
|
|
|
2019-04-13 16:24:41 +01:00
|
|
|
lint_failed = False
|
2019-04-01 19:41:26 +01:00
|
|
|
try:
|
2020-01-03 13:30:03 +00:00
|
|
|
session.run(*cmd_args, **cmd_kwargs)
|
2019-04-01 19:41:26 +01:00
|
|
|
except CommandFailed:
|
2019-04-13 16:24:41 +01:00
|
|
|
lint_failed = True
|
2019-04-01 19:41:26 +01:00
|
|
|
raise
|
2019-04-13 16:24:41 +01:00
|
|
|
finally:
|
2020-01-03 13:30:03 +00:00
|
|
|
if tee_output:
|
|
|
|
stdout.seek(0)
|
|
|
|
contents = stdout.read()
|
|
|
|
if contents:
|
|
|
|
if IS_PY3:
|
|
|
|
contents = contents.decode("utf-8")
|
|
|
|
else:
|
|
|
|
contents = contents.encode("utf-8")
|
|
|
|
sys.stdout.write(contents)
|
|
|
|
sys.stdout.flush()
|
|
|
|
if pylint_report_path:
|
|
|
|
# Write report
|
|
|
|
with open(pylint_report_path, "w") as wfh:
|
|
|
|
wfh.write(contents)
|
|
|
|
session.log("Report file written to %r", pylint_report_path)
|
|
|
|
stdout.close()
|
|
|
|
|
|
|
|
|
|
|
|
def _lint_pre_commit(session, rcfile, flags, paths):
|
|
|
|
if "VIRTUAL_ENV" not in os.environ:
|
|
|
|
session.error(
|
|
|
|
"This should be running from within a virtualenv and "
|
|
|
|
"'VIRTUAL_ENV' was not found as an environment variable."
|
|
|
|
)
|
|
|
|
if "pre-commit" not in os.environ["VIRTUAL_ENV"]:
|
|
|
|
session.error(
|
|
|
|
"This should be running from within a pre-commit virtualenv and "
|
|
|
|
"'VIRTUAL_ENV'({}) does not appear to be a pre-commit virtualenv.".format(
|
|
|
|
os.environ["VIRTUAL_ENV"]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from nox.virtualenv import VirtualEnv
|
2020-04-02 20:10:20 -05:00
|
|
|
|
2020-01-03 13:30:03 +00:00
|
|
|
# Let's patch nox to make it run inside the pre-commit virtualenv
|
|
|
|
try:
|
|
|
|
session._runner.venv = VirtualEnv( # pylint: disable=unexpected-keyword-arg
|
|
|
|
os.environ["VIRTUAL_ENV"],
|
|
|
|
interpreter=session._runner.func.python,
|
|
|
|
reuse_existing=True,
|
|
|
|
venv=True,
|
|
|
|
)
|
|
|
|
except TypeError:
|
|
|
|
# This is still nox-py2
|
|
|
|
session._runner.venv = VirtualEnv(
|
|
|
|
os.environ["VIRTUAL_ENV"],
|
|
|
|
interpreter=session._runner.func.python,
|
|
|
|
reuse_existing=True,
|
|
|
|
)
|
|
|
|
_lint(session, rcfile, flags, paths, tee_output=False)
|
2019-04-01 19:41:26 +01:00
|
|
|
|
|
|
|
|
2019-12-03 10:57:49 +00:00
|
|
|
@nox.session(python="3")
|
2019-04-01 19:41:26 +01:00
|
|
|
def lint(session):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-01 19:41:26 +01:00
|
|
|
Run PyLint against Salt and it's test suite. Set PYLINT_REPORT to a path to capture output.
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-01 19:41:26 +01:00
|
|
|
session.notify("lint-salt-{}".format(session.python))
|
|
|
|
session.notify("lint-tests-{}".format(session.python))
|
|
|
|
|
|
|
|
|
2019-12-03 10:57:49 +00:00
|
|
|
@nox.session(python="3", name="lint-salt")
|
2019-04-01 19:41:26 +01:00
|
|
|
def lint_salt(session):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-01 19:41:26 +01:00
|
|
|
Run PyLint against Salt. Set PYLINT_REPORT to a path to capture output.
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-12-03 11:51:53 +00:00
|
|
|
flags = ["--disable=I"]
|
2019-04-01 19:41:26 +01:00
|
|
|
if session.posargs:
|
|
|
|
paths = session.posargs
|
|
|
|
else:
|
2020-04-23 11:48:17 +01:00
|
|
|
paths = ["setup.py", "noxfile.py", "salt/", "tasks/"]
|
2019-12-03 10:57:49 +00:00
|
|
|
_lint(session, ".pylintrc", flags, paths)
|
2019-04-01 19:41:26 +01:00
|
|
|
|
|
|
|
|
2019-12-03 10:57:49 +00:00
|
|
|
@nox.session(python="3", name="lint-tests")
|
2019-04-01 19:41:26 +01:00
|
|
|
def lint_tests(session):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-01 19:41:26 +01:00
|
|
|
Run PyLint against Salt and it's test suite. Set PYLINT_REPORT to a path to capture output.
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-12-03 11:51:53 +00:00
|
|
|
flags = ["--disable=I"]
|
2019-04-01 19:41:26 +01:00
|
|
|
if session.posargs:
|
|
|
|
paths = session.posargs
|
|
|
|
else:
|
|
|
|
paths = ["tests/"]
|
2019-12-03 10:57:49 +00:00
|
|
|
_lint(session, ".pylintrc", flags, paths)
|
2019-04-02 17:16:49 +01:00
|
|
|
|
|
|
|
|
2020-01-03 13:30:03 +00:00
|
|
|
@nox.session(python=False, name="lint-salt-pre-commit")
|
|
|
|
def lint_salt_pre_commit(session):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-01-03 13:30:03 +00:00
|
|
|
Run PyLint against Salt. Set PYLINT_REPORT to a path to capture output.
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-01-03 13:30:03 +00:00
|
|
|
flags = ["--disable=I"]
|
|
|
|
if session.posargs:
|
|
|
|
paths = session.posargs
|
|
|
|
else:
|
|
|
|
paths = ["setup.py", "noxfile.py", "salt/"]
|
|
|
|
_lint_pre_commit(session, ".pylintrc", flags, paths)
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(python=False, name="lint-tests-pre-commit")
|
|
|
|
def lint_tests_pre_commit(session):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-01-03 13:30:03 +00:00
|
|
|
Run PyLint against Salt and it's test suite. Set PYLINT_REPORT to a path to capture output.
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2020-01-03 13:30:03 +00:00
|
|
|
flags = ["--disable=I"]
|
|
|
|
if session.posargs:
|
|
|
|
paths = session.posargs
|
|
|
|
else:
|
|
|
|
paths = ["tests/"]
|
|
|
|
_lint_pre_commit(session, ".pylintrc", flags, paths)
|
|
|
|
|
|
|
|
|
2019-05-29 11:36:03 +01:00
|
|
|
@nox.session(python="3")
|
2019-10-28 14:17:49 +00:00
|
|
|
@nox.parametrize("update", [False, True])
|
|
|
|
@nox.parametrize("compress", [False, True])
|
|
|
|
def docs(session, compress, update):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-02 17:16:49 +01:00
|
|
|
Build Salt's Documentation
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-10-28 14:17:49 +00:00
|
|
|
session.notify("docs-html(compress={})".format(compress))
|
|
|
|
session.notify("docs-man(compress={}, update={})".format(compress, update))
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(name="docs-html", python="3")
|
|
|
|
@nox.parametrize("compress", [False, True])
|
|
|
|
def docs_html(session, compress):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-10-28 14:17:49 +00:00
|
|
|
Build Salt's HTML Documentation
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-05-29 11:36:03 +01:00
|
|
|
pydir = _get_pydir(session)
|
|
|
|
if pydir == "py3.4":
|
|
|
|
session.error("Sphinx only runs on Python >= 3.5")
|
2019-10-22 17:30:18 +01:00
|
|
|
requirements_file = "requirements/static/docs.in"
|
2020-04-20 09:35:13 -04:00
|
|
|
distro_constraints = ["requirements/static/{}/docs.txt".format(_get_pydir(session))]
|
2019-10-22 17:30:18 +01:00
|
|
|
install_command = ["--progress-bar=off", "-r", requirements_file]
|
|
|
|
for distro_constraint in distro_constraints:
|
|
|
|
install_command.extend(["--constraint", distro_constraint])
|
|
|
|
session.install(*install_command, silent=PIP_INSTALL_SILENT)
|
2019-04-02 17:16:49 +01:00
|
|
|
os.chdir("doc/")
|
|
|
|
session.run("make", "clean", external=True)
|
2019-05-29 11:28:55 +01:00
|
|
|
session.run("make", "html", "SPHINXOPTS=-W", external=True)
|
2019-10-28 14:17:49 +00:00
|
|
|
if compress:
|
2019-12-01 15:19:51 -07:00
|
|
|
session.run("tar", "-cJvf", "html-archive.tar.xz", "_build/html", external=True)
|
2019-10-28 14:17:49 +00:00
|
|
|
os.chdir("..")
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(name="docs-man", python="3")
|
|
|
|
@nox.parametrize("update", [False, True])
|
|
|
|
@nox.parametrize("compress", [False, True])
|
|
|
|
def docs_man(session, compress, update):
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-10-28 14:17:49 +00:00
|
|
|
Build Salt's Manpages Documentation
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-10-28 14:17:49 +00:00
|
|
|
pydir = _get_pydir(session)
|
|
|
|
if pydir == "py3.4":
|
|
|
|
session.error("Sphinx only runs on Python >= 3.5")
|
|
|
|
requirements_file = "requirements/static/docs.in"
|
2020-04-20 09:35:13 -04:00
|
|
|
distro_constraints = ["requirements/static/{}/docs.txt".format(_get_pydir(session))]
|
2019-10-28 14:17:49 +00:00
|
|
|
install_command = ["--progress-bar=off", "-r", requirements_file]
|
|
|
|
for distro_constraint in distro_constraints:
|
|
|
|
install_command.extend(["--constraint", distro_constraint])
|
|
|
|
session.install(*install_command, silent=PIP_INSTALL_SILENT)
|
|
|
|
os.chdir("doc/")
|
|
|
|
session.run("make", "clean", external=True)
|
|
|
|
session.run("make", "man", "SPHINXOPTS=-W", external=True)
|
|
|
|
if update:
|
|
|
|
session.run("rm", "-rf", "man/", external=True)
|
|
|
|
session.run("cp", "-Rp", "_build/man", "man/", external=True)
|
|
|
|
if compress:
|
2019-12-01 15:19:51 -07:00
|
|
|
session.run("tar", "-cJvf", "man-archive.tar.xz", "_build/man", external=True)
|
2019-04-02 17:16:49 +01:00
|
|
|
os.chdir("..")
|
2020-04-23 11:48:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def _invoke(session):
|
|
|
|
"""
|
|
|
|
Run invoke tasks
|
|
|
|
"""
|
|
|
|
requirements_file = "requirements/static/invoke.in"
|
|
|
|
distro_constraints = [
|
|
|
|
"requirements/static/{}/invoke.txt".format(_get_pydir(session))
|
|
|
|
]
|
|
|
|
install_command = ["--progress-bar=off", "-r", requirements_file]
|
|
|
|
for distro_constraint in distro_constraints:
|
|
|
|
install_command.extend(["--constraint", distro_constraint])
|
|
|
|
session.install(*install_command, silent=PIP_INSTALL_SILENT)
|
|
|
|
cmd = ["inv"]
|
|
|
|
files = []
|
|
|
|
|
|
|
|
# Unfortunately, invoke doesn't support the nargs functionality like argpase does.
|
|
|
|
# Let's make it behave properly
|
|
|
|
for idx, posarg in enumerate(session.posargs):
|
|
|
|
if idx == 0:
|
|
|
|
cmd.append(posarg)
|
|
|
|
continue
|
|
|
|
if posarg.startswith("--"):
|
|
|
|
cmd.append(posarg)
|
|
|
|
continue
|
|
|
|
files.append(posarg)
|
|
|
|
if files:
|
|
|
|
cmd.append("--files={}".format(" ".join(files)))
|
|
|
|
session.run(*cmd)
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(name="invoke", python="3")
|
|
|
|
def invoke(session):
|
|
|
|
_invoke(session)
|
|
|
|
|
|
|
|
|
|
|
|
@nox.session(name="invoke-pre-commit", python="3")
|
|
|
|
def invoke_pre_commit(session):
|
|
|
|
if "VIRTUAL_ENV" not in os.environ:
|
|
|
|
session.error(
|
|
|
|
"This should be running from within a virtualenv and "
|
|
|
|
"'VIRTUAL_ENV' was not found as an environment variable."
|
|
|
|
)
|
|
|
|
if "pre-commit" not in os.environ["VIRTUAL_ENV"]:
|
|
|
|
session.error(
|
|
|
|
"This should be running from within a pre-commit virtualenv and "
|
|
|
|
"'VIRTUAL_ENV'({}) does not appear to be a pre-commit virtualenv.".format(
|
|
|
|
os.environ["VIRTUAL_ENV"]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from nox.virtualenv import VirtualEnv
|
|
|
|
|
|
|
|
# Let's patch nox to make it run inside the pre-commit virtualenv
|
|
|
|
try:
|
|
|
|
session._runner.venv = VirtualEnv( # pylint: disable=unexpected-keyword-arg
|
|
|
|
os.environ["VIRTUAL_ENV"],
|
|
|
|
interpreter=session._runner.func.python,
|
|
|
|
reuse_existing=True,
|
|
|
|
venv=True,
|
|
|
|
)
|
|
|
|
except TypeError:
|
|
|
|
# This is still nox-py2
|
|
|
|
session._runner.venv = VirtualEnv(
|
|
|
|
os.environ["VIRTUAL_ENV"],
|
|
|
|
interpreter=session._runner.func.python,
|
|
|
|
reuse_existing=True,
|
|
|
|
)
|
|
|
|
_invoke(session)
|