Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
add deps checks
Browse files Browse the repository at this point in the history
  • Loading branch information
eeue56 committed Mar 8, 2016
1 parent eab5e25 commit aa24a86
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# elm-ops-tooling
Tooling for Elm ops


## elm_deps_check

Sometimes we need to make sure that two different exact-dependencies are the same. This is the case when you have a parent project, and a test project where the parent project dependencies are a sub list of test project.

Usage:

```bash

python elm-stuff/exact-dependencies.json tests/elm-stuff/exact-dependencies.json

```
52 changes: 52 additions & 0 deletions elm_deps_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#! /usr/bin/env python
from __future__ import print_function

import sys

import json


def have_matching_versions(top_level_file, spec_file):
""" first file should be the top level elm-package
second file should be the spec file
"""

with open(top_level_file) as f:
top_level = json.loads(f.read())
print(top_level_file, json.dumps(top_level, sort_keys=True, indent=4))

with open(spec_file) as f:
spec = json.loads(f.read())
print(spec_file, json.dumps(spec, sort_keys=True, indent=4))

errors = []

for (package_name, package_version) in top_level.items():
if package_name not in spec:
errors.append('Package {package_name} not found in {spec_file}, but was found in {top_level_file}'.format(
package_name=package_name, spec_file=spec_file, top_level_file=top_level_file)
)
elif spec[package_name] != package_version:
errors.append('Package version mismatch for'
' {package_name}!\n\n {top_level_file} had {package_version}\n {spec_file} had {other_package_version}'.format(
package_version=package_version, package_name=package_name, top_level_file=top_level_file,
spec_file=spec_file, other_package_version=spec[package_name])
)

if len(errors) > 0:
print('FAILED due to elm-deps mismatch, errors:')
print('\n'.join(errors))
return False
else:
print('Matching deps!')
return True


if __name__ == '__main__':
if len(sys.argv) > 2:
top_level_file = sys.argv[1]
spec_file = sys.argv[2]

if not have_matching_versions(top_level_file, spec_file):
sys.exit(1)

0 comments on commit aa24a86

Please sign in to comment.