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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from NoRedInk/native-deps-sync
Native deps sync + native_package_install fixes
- Loading branch information
Showing
12 changed files
with
436 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
hypothesis | ||
pytest | ||
pytest-mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
enum34==1.1.6 | ||
# | ||
# This file is autogenerated by pip-compile | ||
# To update, run: | ||
# | ||
# pip-compile --output-file dev-requirements.txt dev-requirements.in | ||
# | ||
enum34==1.1.6 # via hypothesis | ||
funcsigs==1.0.2 # via mock | ||
hypothesis==3.6.0 | ||
py==1.4.31 | ||
pytest==3.0.3 | ||
mock==2.0.0 # via pytest-mock | ||
pbr==1.10.0 # via mock | ||
py==1.4.31 # via pytest | ||
pytest-mock==1.4.0 | ||
pytest==3.0.4 | ||
six==1.10.0 # via mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#! /usr/bin/env python | ||
""" | ||
Load and save elm-package.json safely. | ||
""" | ||
|
||
# from typing import Dict, Tuple, IO | ||
import copy | ||
from collections import OrderedDict | ||
import json | ||
|
||
|
||
def load(fileobj): | ||
# type: (IO[str]) -> Dict | ||
return json.load(fileobj, object_pairs_hook=OrderedDict) | ||
|
||
|
||
def dump(package, fileobj): | ||
# type: (Dict, IO[str]) -> None | ||
to_save = copy.deepcopy(package) | ||
to_save['dependencies'] = sorted_deps(to_save['dependencies']) | ||
json.dump(to_save, fileobj, sort_keys=False, indent=4, separators=(',', ': ')) | ||
|
||
|
||
def sorted_deps(deps): | ||
# type: (Dict) -> Dict | ||
return OrderedDict(sorted(deps.items())) | ||
|
||
|
||
def sync_deps(from_deps, to_deps): | ||
# type: (Dict, Dict) -> Tuple[List[str], Dict] | ||
messages = [] | ||
result = copy.deepcopy(to_deps) | ||
|
||
for (package_name, package_version) in from_deps.items(): | ||
if package_name not in to_deps: | ||
result[package_name] = package_version | ||
|
||
messages.append('Inserting new package {package_name} at version {package_version}'.format( | ||
package_name=package_name, package_version=package_version) | ||
) | ||
elif to_deps[package_name] != package_version: | ||
result[package_name] = package_version | ||
|
||
messages.append('Changing {package_name} from version {package_version} to {other_package_version}'.format( | ||
package_version=package_version, package_name=package_name, | ||
other_package_version=to_deps[package_name]) | ||
) | ||
|
||
return messages, result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#! /usr/bin/env python | ||
""" | ||
Load and save exact-dependencies.json safely. | ||
The format of exact-dependencies is simply a dictionary of | ||
package name and its exact version: | ||
{ | ||
"elm-lang/core": "4.0.5" | ||
} | ||
""" | ||
|
||
# from typing import Dict, IO | ||
import json | ||
|
||
import elm_package | ||
|
||
|
||
load = elm_package.load | ||
|
||
|
||
def dump(package, fileobj): | ||
# type: (Dict, IO[str]) -> None | ||
to_save = elm_package.sorted_deps(package) | ||
json.dump(to_save, fileobj, sort_keys=False, indent=4, separators=(',', ': ')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#! /usr/bin/env python | ||
from __future__ import print_function | ||
|
||
import sys | ||
import argparse | ||
|
||
import elm_package | ||
import exact_dependencies | ||
|
||
|
||
def sync_versions(top_level_file, spec_file, quiet=False, dry=False, note_test_deps=True): | ||
""" first file should be the top level elm-native-package.json. | ||
second file should be the spec level elm-native-package.json. | ||
""" | ||
|
||
with open(top_level_file) as f: | ||
top_level = exact_dependencies.load(f) | ||
|
||
with open(spec_file) as f: | ||
spec = exact_dependencies.load(f) | ||
|
||
(messages, new_deps) = elm_package.sync_deps(top_level, spec) | ||
spec = new_deps | ||
|
||
if len(messages) == 0: | ||
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: | ||
exact_dependencies.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('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) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.