Browse code

Verify package data in setup.py installs all files (#59537)

* Add sanity test to ensure all non-py files are installed

* Fix mode and regex

* Fix role skel inventory package_data

* Add docs

* Update package_data for inventory files

* Address pylint concerns

* Another tweak to package_data

* Address review feedback

* Change index to 1

* add to ansible-only.txt

Matt Martz authored on 2019/07/25 03:58:13
Showing 6 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+Sanity Tests ยป package-data
1
+===========================
2
+
3
+Verifies that the combination of ``MANIFEST.in`` and ``package_data`` from ``setup.py``
4
+properly installs data files from within ``lib/ansible``
... ...
@@ -271,6 +271,7 @@ static_setup_params = dict(
271 271
             'galaxy/data/*/*/.*',
272 272
             'galaxy/data/*/*/*.*',
273 273
             'galaxy/data/*/tests/inventory',
274
+            'galaxy/data/*/role/tests/inventory',
274 275
             'config/base.yml',
275 276
             'config/module_defaults.yml',
276 277
         ],
... ...
@@ -6,3 +6,4 @@ deprecated-config.py
6 6
 docs-build.py
7 7
 test-constraints.py
8 8
 update-bundled.py
9
+package-data.py
9 10
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+{
1
+    "disabled": true,
2
+    "always": true,
3
+    "output": "path-message"
4
+}
0 5
new file mode 100755
... ...
@@ -0,0 +1,48 @@
0
+#!/usr/bin/env python
1
+from __future__ import (absolute_import, division, print_function)
2
+__metaclass__ = type
3
+
4
+import fnmatch
5
+import os
6
+import re
7
+import tempfile
8
+import subprocess
9
+
10
+
11
+def main():
12
+    ignore_files = frozenset((
13
+        '*/.git_keep',
14
+        '*/galaxy/data/default/role/*/main.yml.j2',
15
+        '*/galaxy/data/default/role/*/test.yml.j2',
16
+        '*/galaxy/data/default/collection/plugins/README.md.j2',
17
+    ))
18
+
19
+    non_py_files = []
20
+    for root, _dummy, files in os.walk('lib/ansible/'):
21
+        for filename in files:
22
+            path = os.path.join(root, filename)
23
+            if os.path.splitext(path)[1] not in ('.py', '.pyc', '.pyo'):
24
+                add = True
25
+                for ignore in ignore_files:
26
+                    if fnmatch.fnmatch(path, ignore):
27
+                        add = False
28
+                if add:
29
+                    non_py_files.append(os.path.relpath(path, 'lib/ansible'))
30
+
31
+    with tempfile.TemporaryDirectory() as tmp_dir:
32
+        stdout, _dummy = subprocess.Popen(
33
+            ['python', 'setup.py', 'install', '--root=%s' % tmp_dir],
34
+            stdout=subprocess.PIPE,
35
+            stderr=subprocess.PIPE,
36
+            universal_newlines=True,
37
+        ).communicate()
38
+        match = re.search('^creating (%s/.*?/(?:site|dist)-packages/ansible)$' % tmp_dir, stdout, flags=re.M)
39
+
40
+        for filename in non_py_files:
41
+            path = os.path.join(match.group(1), filename)
42
+            if not os.path.exists(path):
43
+                print('%s: File not installed' % os.path.join('lib', 'ansible', filename))
44
+
45
+
46
+if __name__ == '__main__':
47
+    main()
... ...
@@ -17,7 +17,7 @@ fi
17 17
 
18 18
 case "${group}" in
19 19
     1) options=(--skip-test pylint --skip-test ansible-doc --skip-test docs-build) ;;
20
-    2) options=(--test ansible-doc --test docs-build) ;;
20
+    2) options=(--test ansible-doc --test docs-build --test package-data) ;;
21 21
     3) options=(--test pylint --exclude test/units/ --exclude lib/ansible/module_utils/ --exclude lib/ansible/modules/network/) ;;
22 22
     4) options=(--test pylint           test/units/           lib/ansible/module_utils/           lib/ansible/modules/network/) ;;
23 23
 esac