forked from applitools/eyes.sdk.python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
180 lines (151 loc) · 5.25 KB
/
tasks.py
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import os
import shutil
import sys
from os import path
from invoke import task
here = path.dirname(path.abspath(__file__))
@task
def clean(c, docs=False, bytecode=False, dist=True, node=True, extra=""):
patterns = ["build", "*/temp"]
if docs:
patterns.append("docs/_build")
if bytecode:
patterns.append("**/*.pyc")
if dist:
patterns.append("**/dist")
patterns.append("**/build")
patterns.append("**/*.egg-info")
if node:
patterns.append("*/node_modules")
if extra:
patterns.append(extra)
for pattern in patterns:
c.run("rm -rf {}".format(pattern))
@task(pre=[clean])
def dist(c, common=False, core=False, selenium=False, images=False, prod=False):
git_status = c.run("git status", hide=True)
if "Changes not staged for commit" in git_status.stdout:
raise Exception("Working directory should be clean")
packages = list(
_packages_resolver(
common, core, selenium, images, full_path=True, path_as_str=True
)
)
dest = "pypi" if prod else "test"
for pack_path in packages:
with c.cd(pack_path):
c.run("python setup.py sdist", echo=True)
c.run("twine upload -r {dest} dist/*".format(dest=dest), echo=True)
@task
def install_requirements(c, dev=False, testing=False, lint=False):
dev_requires = ["ipython", "ipdb", "bump2version", "wheel", "twine", "pre-commit"]
testing_requires = [
"pytest==3.9.3",
"pytest-cov==2.6.1",
"pytest-xdist==1.26.1",
"virtualenv==16.3.0",
"pytest-virtualenv==1.4.0",
"mock",
"webdriver_manager==1.5",
"tox==3.14.3",
]
lint_requires = ["flake8", "flake8-import-order", "flake8-bugbear", "mypy"]
if testing:
requires = testing_requires
elif dev:
requires = dev_requires
elif lint:
requires = lint_requires
else:
requires = dev_requires + testing_requires + lint_requires
c.run("pip install {}".format(" ".join(requires)), echo=True)
def _packages_resolver(
common=False,
core=False,
selenium=False,
images=False,
full_path=False,
path_as_str=False,
):
packages = []
common_pkg, core_pkg, selenium_pkg, images_pkg = (
"eyes_common",
"eyes_core",
"eyes_selenium",
"eyes_images",
)
if common:
packages.append(common_pkg)
if core:
packages.append(core_pkg)
if selenium:
packages.append(selenium_pkg)
if images:
packages.append(images_pkg)
if not packages:
packages = [common_pkg, core_pkg, selenium_pkg, images_pkg]
for pack in packages:
if full_path:
pack = path.join(here, pack)
if path_as_str:
pack = str(pack)
yield pack
@task
def install_packages(
c, common=False, core=False, selenium=False, images=False, editable=False
):
packages = _packages_resolver(
common, core, selenium, images, full_path=True, path_as_str=True
)
editable = "-e" if editable else ""
for pack in packages:
c.run("pip install -U {} {}".format(editable, pack), echo=True)
@task
def uninstall_packages(c, common=False, core=False, selenium=False, images=False):
packages = _packages_resolver(common, core, selenium, images)
c.run("pip uninstall {}".format(" ".join(packages)), echo=True)
@task
def pep_check(c, common=False, core=False, selenium=False, images=False):
for pack in _packages_resolver(common, core, selenium, images, full_path=True):
c.run("flake8 {}".format(pack), echo=True)
@task
def mypy_check(c, common=False, core=False, selenium=False, images=False):
for pack in _packages_resolver(common, core, selenium, images, full_path=True):
c.run(
"mypy --no-incremental --ignore-missing-imports {}/applitools".format(pack),
echo=True,
)
@task
def retrieve_js(c):
for pack in _packages_resolver(selenium=True, full_path=True):
with c.cd(pack):
c.run("npm update --save", echo=True)
move_js_resources_to(pack)
def move_js_resources_to(pack):
paths = [
"dom-capture/dist/captureDom.js",
"dom-snapshot/dist/processPage.js",
"dom-snapshot/dist/processPageAndPoll.js",
"dom-snapshot/dist/processPageAndSerialize.js",
]
node_resources = path.join(pack, "applitools/selenium/resources/")
node_modules = path.join(pack, "node_modules/@applitools")
for pth in paths:
from_ = path.join(node_modules, pth)
name = path.basename(from_)
shutil.copy(from_, dst=path.join(node_resources, name))
@task
def run_tests_on_CI(c, tests):
browsers = os.getenv("TEST_BROWSERS", "").split(",")
if not browsers:
raise ValueError("`TEST_BROWSERS` env variable should be set")
pattern = "pytest {par} {tests} --ignore={tests}/test_dom_capture.py --ignore={tests}/test_client_sites.py".format(
par="-n6" if bool(os.getenv("TEST_REMOTE", False)) else "-n2", tests=tests
)
# use Unix background task execution for run tests in parallel
command = pattern
if browsers:
command = "&".join(
["TEST_BROWSERS={} ".format(browser) + pattern for browser in browsers]
)
c.run(command, echo=True)