Skip to content

Commit 386bf4c

Browse files
authored
CI to check source code/wheels (#12)
1 parent fdb4c8b commit 386bf4c

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ This checklist is used to make sure that common guidelines for a pull request ar
44

55
### General Guidelines
66

7-
- [ ] If you modified extension source code, have you run `./scripts/ci/test_static.sh` locally? (`pip install pylint flake8` required)
8-
- [ ] If you modified the index, have you run `python scripts/ci/test_index.py -q` locally?
7+
- [ ] Have you run `./scripts/ci/test_static.sh` locally? (`pip install pylint flake8` required)
8+
- [ ] Have you run `python scripts/ci/test_integration.py -q` locally?

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
python: 3.6
2424
- stage: verify
2525
env: PURPOSE='IndexVerify'
26-
script: python ./scripts/ci/test_index.py -v
26+
script: python ./scripts/ci/test_integration.py -v
2727
python: 3.6
2828
allow_failures:
2929
- env: PURPOSE='SourceTests'

scripts/ci/test_index.py renamed to scripts/ci/test_integration.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6+
""" Test the index and the wheels from both the index and from source extensions in repository """
7+
68
from __future__ import print_function
79

810
import os
@@ -12,10 +14,15 @@
1214
import zipfile
1315
import hashlib
1416
import shutil
17+
import subprocess
1518
from util import get_repo_root
1619
from wheel.install import WHEEL_INFO_RE
1720

1821
INDEX_PATH = os.path.join(get_repo_root(), 'src', 'index.json')
22+
SRC_PATH = os.path.join(get_repo_root(), 'src')
23+
24+
# Extensions to skip dep. check. Aim to keep this list empty.
25+
SKIP_DEP_CHECK = ['azure_cli_iot_ext']
1926

2027

2128
def catch_dup_keys(pairs):
@@ -62,6 +69,9 @@ def get_extension_modname(ext_dir):
6269
EXTENSIONS_MOD_PREFIX = 'azext_'
6370
pos_mods = [n for n in os.listdir(ext_dir)
6471
if n.startswith(EXTENSIONS_MOD_PREFIX) and os.path.isdir(os.path.join(ext_dir, n))]
72+
if len(pos_mods) != 1:
73+
raise AssertionError("Expected 1 module to load starting with "
74+
"'{}': got {}".format(EXTENSIONS_MOD_PREFIX, pos_mods))
6575
return pos_mods[0]
6676

6777

@@ -180,8 +190,42 @@ def test_metadata(self):
180190
"Metadata for {} in index doesn't match the expected of: \n"
181191
"{}".format(item['filename'], json.dumps(metadata, indent=2, sort_keys=True,
182192
separators=(',', ': '))))
193+
run_requires = metadata.get('run_requires')
194+
if run_requires and ext_name not in SKIP_DEP_CHECK:
195+
deps = run_requires[0]['requires']
196+
self.assertTrue(all(not dep.startswith('azure-') for dep in deps),
197+
"Dependencies of {} use disallowed extension dependencies. "
198+
"Remove these dependencies: {}".format(item['filename'], deps))
183199
shutil.rmtree(extensions_dir)
184200

185201

202+
class TestSourceWheels(unittest.TestCase):
203+
204+
def test_source_wheels(self):
205+
# Test we can build all sources into wheels and that metadata from the wheel is valid
206+
from subprocess import PIPE
207+
built_whl_dir = tempfile.mkdtemp()
208+
source_extensions = [os.path.join(SRC_PATH, n) for n in os.listdir(SRC_PATH)
209+
if os.path.isdir(os.path.join(SRC_PATH, n))]
210+
for s in source_extensions:
211+
try:
212+
subprocess.check_call(['python', 'setup.py', 'bdist_wheel', '-q', '-d', built_whl_dir],
213+
cwd=s, stdout=PIPE, stderr=PIPE)
214+
except subprocess.CalledProcessError as err:
215+
self.fail("Unable to build extension {} : {}".format(s, err))
216+
for filename in os.listdir(built_whl_dir):
217+
ext_file = os.path.join(built_whl_dir, filename)
218+
ext_dir = tempfile.mkdtemp(dir=built_whl_dir)
219+
ext_name = WHEEL_INFO_RE(filename).groupdict().get('name')
220+
metadata = get_ext_metadata(ext_dir, ext_file, ext_name)
221+
run_requires = metadata.get('run_requires')
222+
if run_requires and ext_name not in SKIP_DEP_CHECK:
223+
deps = run_requires[0]['requires']
224+
self.assertTrue(all(not dep.startswith('azure-') for dep in deps),
225+
"Dependencies of {} use disallowed extension dependencies. "
226+
"Remove these dependencies: {}".format(filename, deps))
227+
shutil.rmtree(built_whl_dir)
228+
229+
186230
if __name__ == '__main__':
187231
unittest.main()

0 commit comments

Comments
 (0)