This repository was 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
Native deps sync + native_package_install fixes #22
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6e7db0d
Extract elm_package.sync_deps
ento a99ab51
Add native_deps_sync.py
ento 973baf2
Run doctests
ento b9d1532
Add native_package_install test and rename functions/variables to mat…
ento ca4f2b1
More renamings for clarity
ento 282682a
Fix: don't fetch already installed package
ento 17b5bb9
More renamings for clarity
ento 2f22015
Fix native_package_install: don't generate trailing whitespaces
ento 4d54924
Fix tests
ento bcfe86c
Python 3 compat: urllib2 merged into urllib
ento e5f9e8c
user -> owner: orgs can own repos too
ento 704948d
Switch to mypy-style type annotation comments
ento 96106d4
pep-0257
ento 2d602cd
Simplfy branches
ento File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was edging against this so that the file could be run by itself without needing the whole repo, but maybe it doesn't matter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I guessed so :p I didn't see myself downloading a single file without the option to easily upgrade: I'd do either pip or a git clone