1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
from os import getcwd
import sys
from invocations import ci
from invocations import checks
from invocations.docs import docs, www, sites, watch_docs
from invocations.pytest import (
test,
integration as integration_,
coverage as coverage_,
)
from invocations.packaging import release
from invoke import Collection, task
@task
def safety_test_v1_to_v2_shim(c):
"""
Run some very quick in-process safety checks on a dual fabric1-v-2 env.
Assumes Fabric 2+ is already installed as 'fabric2'.
"""
c.run("pip install 'fabric<2'")
# Make darn sure the two copies of fabric are coming from install root, not
# local directory - which would result in 'fabric' always being v2!
for serious in (getcwd(), ""):
if serious in sys.path: # because why would .remove be idempotent?!
sys.path.remove(serious)
from fabric.api import env
from fabric2 import Connection
env.gateway = "some-gateway"
env.no_agent = True
env.password = "sikrit"
env.user = "admin"
env.host_string = "localghost"
env.port = "2222"
cxn = Connection.from_v1(env)
config = cxn.config
assert config.run.pty is True
assert config.gateway == "some-gateway"
assert config.connect_kwargs.password == "sikrit"
assert config.sudo.password == "sikrit"
assert cxn.host == "localghost"
assert cxn.user == "admin"
assert cxn.port == 2222
# TODO: as usual, this just wants a good pattern for "that other task, with a
# tweaked default arg value"
@task
def integration(
c,
opts=None,
pty=True,
x=False,
k=None,
verbose=True,
color=True,
capture="no",
module=None,
):
return integration_(c, opts, pty, x, k, verbose, color, capture, module)
# NOTE: copied from invoke's tasks.py
@task
def coverage(c, report="term", opts="", codecov=False):
"""
Run pytest in coverage mode. See `invocations.pytest.coverage` for details.
"""
# Use our own test() instead of theirs.
# Also add integration test so this always hits both.
coverage_(
c,
report=report,
opts=opts,
tester=test,
additional_testers=[integration],
codecov=codecov,
)
ns = Collection(
checks.blacken, # backwards compat
checks,
ci,
coverage,
docs,
integration,
release,
sites,
test,
watch_docs,
www,
safety_test_v1_to_v2_shim,
)
ns.configure(
{
"packaging": {
# NOTE: this is currently for identifying the source directory.
# Should it get used for actual releasing, needs changing.
"package": "fabric",
"sign": False,
"wheel": True,
"check_desc": True,
"changelog_file": "sites/www/changelog.rst",
"rebuild_with_env": dict(PACKAGE_AS_FABRIC2="yes"),
}
}
)
|