This repository has been archived by the owner on May 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathelm_deps_sync.py
executable file
·70 lines (47 loc) · 2 KB
/
elm_deps_sync.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
#! /usr/bin/env python
from __future__ import print_function
import sys
import argparse
import elm_package
def sync_versions(top_level_file, spec_file, quiet=False, dry=False, note_test_deps=True):
""" first file should be the top level elm-package.json.
second file should be the spec level elm-package.json.
"""
with open(top_level_file) as f:
top_level = elm_package.load(f)
with open(spec_file) as f:
spec = elm_package.load(f)
(messages, new_deps) = elm_package.sync_deps(top_level['dependencies'], spec['dependencies'])
spec['dependencies'] = new_deps
if note_test_deps:
test_deps = {}
for (package_name, package_version) in spec['dependencies'].items():
if package_name not in top_level['dependencies']:
test_deps[package_name] = package_version
spec['test-dependencies'] = elm_package.sorted_deps(test_deps)
if len(messages) == 0 and not note_test_deps:
print('No changes needed.')
return
print('{number} packages changed.'.format(number=len(messages)))
if not quiet:
print('\n'.join(messages))
if dry:
print("No changes written.")
return
with open(spec_file, 'w') as f:
elm_package.dump(spec, f)
def main():
parser = argparse.ArgumentParser(description='Sync deps between a parent and a sub')
parser.add_argument('--quiet', '-q', action='store_true', help='don\'t print anything', default=False)
parser.add_argument('--dry', '-d', action='store_true', help='only print possible changes', default=False)
parser.add_argument('--note',
action='store_true',
help='add a test-dependencies field of things only found in the test',
default=False
)
parser.add_argument('top_level_file')
parser.add_argument('spec_file')
args = parser.parse_args()
sync_versions(args.top_level_file, args.spec_file, quiet=args.quiet, dry=args.dry, note_test_deps=args.note)
if __name__ == '__main__':
main()