Skip to content

Commit

Permalink
Changed library for YAML so comments are preserved
Browse files Browse the repository at this point in the history
- Introduced ruamel.yaml
  • Loading branch information
seriva committed Feb 26, 2020
1 parent 0890657 commit 9ae42e3
Show file tree
Hide file tree
Showing 5 changed files with 991 additions and 1,287 deletions.
48 changes: 34 additions & 14 deletions core/src/epicli/.devcontainer/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
adal==1.2.2
ansible==2.8.6
antlr4-python3-runtime==4.7.2 ; python_version >= '3.0'
antlr4-python3-runtime==4.7.2
applicationinsights==0.11.7
argcomplete==1.10.0
astroid==2.3.3
attrs==19.3.0
azure-batch==6.0.0
azure-cli==2.0.67
azure-cli-acr==2.2.9
azure-cli-acs==2.4.4
azure-cli-advisor==2.0.1
Expand Down Expand Up @@ -64,7 +66,6 @@ azure-cli-sqlvm==0.2.0
azure-cli-storage==2.4.3
azure-cli-telemetry==1.0.2
azure-cli-vm==2.2.23
azure-cli==2.0.67
azure-common==1.1.23
azure-cosmos==3.1.2
azure-datalake-store==0.0.39
Expand Down Expand Up @@ -136,6 +137,7 @@ azure-storage-blob==1.3.1
azure-storage-common==1.4.2
azure-storage-nspkg==3.1.0
bcrypt==3.1.7
bleach==3.1.1
boto3==1.10.9
botocore==1.13.9
certifi==2019.9.11
Expand All @@ -150,45 +152,63 @@ idna==2.8
importlib-metadata==0.23
invoke==1.3.0
isodate==0.6.0
jinja2==2.10.3
isort==4.3.21
jeepney==0.4.2
Jinja2==2.10.3
jmespath==0.9.4
jsonschema==3.1.1
keyring==21.1.0
knack==0.6.3
markupsafe==1.1.1
lazy-object-proxy==1.4.3
MarkupSafe==1.1.1
mccabe==0.6.1
mock==3.0.5
more-itertools==7.2.0
msrest==0.6.10
msrestazure==0.6.2
oauthlib==3.1.0
packaging==20.1
paramiko==2.6.0
pkginfo==1.5.0.1
pluggy==0.13.1
portalocker==1.2.1
prompt-toolkit==1.0.18
psutil==5.6.4
py==1.8.1
pycparser==2.19
pygments==2.4.2
pyjwt==1.7.1
pynacl==1.3.0
pyopenssl==19.0.0
Pygments==2.4.2
PyJWT==1.7.1
PyNaCl==1.3.0
pyOpenSSL==19.0.0
pyparsing==2.4.6
pyperclip==1.7.0
pyrsistent==0.15.5
python-dateutil==2.8.0 ; python_version >= '2.7'
python-dateutil==2.8.0
python-json-logger==0.1.11
pytz==2019.3
pyyaml==5.1.2
requests-oauthlib==1.2.0
PyYAML==5.3
readme-renderer==24.0
requests==2.22.0
requests-oauthlib==1.2.0
requests-toolbelt==0.9.1
ruamel.yaml==0.16.10
ruamel.yaml.clib==0.2.0
s3transfer==0.2.1
scp==0.13.2
SecretStorage==3.1.2
six==1.12.0
skopeo-bin==1.0.3
sshtunnel==0.1.5
tabulate==0.8.5
terraform-bin==1.0.1
urllib3[secure]==1.25.6 ; python_version >= '3.4'
vsts-cd-manager==1.0.2
tqdm==4.43.0
typed-ast==1.4.1
urllib3==1.25.6
vsts==0.1.25
vsts-cd-manager==1.0.2
wcwidth==0.1.7
webencodings==0.5.1
websocket-client==0.56.0
wheel==0.30.0
wrapt==1.11.2
xmltodict==0.12.0
zipp==0.6.0
18 changes: 13 additions & 5 deletions core/src/epicli/cli/helpers/yaml_helpers.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import yaml
from ruamel.yaml import YAML
from cli.helpers.objdict_helpers import objdict_to_dict, dict_to_objdict


def safe_load_all(stream):
docs = list(yaml.safe_load_all(stream))
yaml = YAML()
yaml.default_flow_style = False
docs = list(yaml.load_all(stream))
conv_docs = []
for doc in docs:
conv_docs.append(dict_to_objdict(doc))
return conv_docs


def safe_load(stream):
doc = yaml.safe_load(stream)
yaml = YAML()
yaml.default_flow_style = False
doc = yaml.load(stream)
return dict_to_objdict(doc)


def dump_all(docs, stream):
yaml = YAML()
yaml.default_flow_style = False
doc2 = docs
conv_docs = []
for doc in doc2:
conv_docs.append(objdict_to_dict(doc))
yaml.dump_all(conv_docs, stream, default_flow_style=False)
yaml.dump_all(conv_docs, stream)


def dump(doc, stream):
yaml.dump(objdict_to_dict(doc), stream, default_flow_style=False)
yaml = YAML()
yaml.default_flow_style = False
yaml.dump(objdict_to_dict(doc), stream)

2,125 changes: 902 additions & 1,223 deletions core/src/epicli/cli/licenses.py

Large diffs are not rendered by default.

39 changes: 8 additions & 31 deletions core/src/epicli/gen-licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,12 @@
import pkg_resources


def _get_dependencies_from_pipfile() -> Set[str]:
with open('Pipfile') as pip_file:
start_gen = dropwhile(lambda x: x.strip() != '[packages]', pip_file)
next(start_gen)
interesting_gen = takewhile(lambda x: not (x.startswith('[') or x == "\n"), start_gen)
return {interesting.split()[0] for interesting in interesting_gen}


def _get_package_dependencies(dependencies: List[Dict[str, str]]) -> Set[str]:
return {dependency['key'] for dependency in dependencies}


def _get_recursive_dependencies_for(direct_dependencies: Set[str]) -> Set[str]:
result = subprocess.run(
['pipenv', 'graph', '--json'], stdout=subprocess.PIPE)
dependencies_dict = {
k['package']['key']: k
for k in json.loads(result.stdout)
}
universe = set(dependencies_dict)
res = direct_dependencies
set_to_check = direct_dependencies
while set_to_check:
deps = universe & reduce(
lambda x, y: x | _get_package_dependencies(dependencies_dict[y]['dependencies']),
set_to_check, set())
set_to_check = deps - res
res = res | deps
return {dependencies_dict[r]['package']['package_name'] for r in res}
def get_dependencies_from_requirements() -> Set[str]:
req = []
with open('requirements.txt') as req_file:
for line in req_file:
req.append(line.split("==")[0])
return req

def makeRequest(url, token):
request = urllib.request.Request(url)
Expand Down Expand Up @@ -96,8 +73,8 @@ def _main() -> None:
if pat == None:
logging.critical('No Github personal access tokens passed as argument.' )
return
direct_dependencies = _get_dependencies_from_pipfile()
all_deps = _get_recursive_dependencies_for(direct_dependencies)
all_deps = get_dependencies_from_requirements()
print(all_deps)
all_deps_data = []
for dep in all_deps:
data = get_pkg_data(dep, pat)
Expand Down
48 changes: 34 additions & 14 deletions core/src/epicli/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
adal==1.2.2
ansible==2.8.6
antlr4-python3-runtime==4.7.2 ; python_version >= '3.0'
antlr4-python3-runtime==4.7.2
applicationinsights==0.11.7
argcomplete==1.10.0
astroid==2.3.3
attrs==19.3.0
azure-batch==6.0.0
azure-cli==2.0.67
azure-cli-acr==2.2.9
azure-cli-acs==2.4.4
azure-cli-advisor==2.0.1
Expand Down Expand Up @@ -64,7 +66,6 @@ azure-cli-sqlvm==0.2.0
azure-cli-storage==2.4.3
azure-cli-telemetry==1.0.2
azure-cli-vm==2.2.23
azure-cli==2.0.67
azure-common==1.1.23
azure-cosmos==3.1.2
azure-datalake-store==0.0.39
Expand Down Expand Up @@ -136,6 +137,7 @@ azure-storage-blob==1.3.1
azure-storage-common==1.4.2
azure-storage-nspkg==3.1.0
bcrypt==3.1.7
bleach==3.1.1
boto3==1.10.9
botocore==1.13.9
certifi==2019.9.11
Expand All @@ -150,45 +152,63 @@ idna==2.8
importlib-metadata==0.23
invoke==1.3.0
isodate==0.6.0
jinja2==2.10.3
isort==4.3.21
jeepney==0.4.2
Jinja2==2.10.3
jmespath==0.9.4
jsonschema==3.1.1
keyring==21.1.0
knack==0.6.3
markupsafe==1.1.1
lazy-object-proxy==1.4.3
MarkupSafe==1.1.1
mccabe==0.6.1
mock==3.0.5
more-itertools==7.2.0
msrest==0.6.10
msrestazure==0.6.2
oauthlib==3.1.0
packaging==20.1
paramiko==2.6.0
pkginfo==1.5.0.1
pluggy==0.13.1
portalocker==1.2.1
prompt-toolkit==1.0.18
psutil==5.6.4
py==1.8.1
pycparser==2.19
pygments==2.4.2
pyjwt==1.7.1
pynacl==1.3.0
pyopenssl==19.0.0
Pygments==2.4.2
PyJWT==1.7.1
PyNaCl==1.3.0
pyOpenSSL==19.0.0
pyparsing==2.4.6
pyperclip==1.7.0
pyrsistent==0.15.5
python-dateutil==2.8.0 ; python_version >= '2.7'
python-dateutil==2.8.0
python-json-logger==0.1.11
pytz==2019.3
pyyaml==5.1.2
requests-oauthlib==1.2.0
PyYAML==5.3
readme-renderer==24.0
requests==2.22.0
requests-oauthlib==1.2.0
requests-toolbelt==0.9.1
ruamel.yaml==0.16.10
ruamel.yaml.clib==0.2.0
s3transfer==0.2.1
scp==0.13.2
SecretStorage==3.1.2
six==1.12.0
skopeo-bin==1.0.3
sshtunnel==0.1.5
tabulate==0.8.5
terraform-bin==1.0.1
urllib3[secure]==1.25.6 ; python_version >= '3.4'
vsts-cd-manager==1.0.2
tqdm==4.43.0
typed-ast==1.4.1
urllib3==1.25.6
vsts==0.1.25
vsts-cd-manager==1.0.2
wcwidth==0.1.7
webencodings==0.5.1
websocket-client==0.56.0
wheel==0.30.0
wrapt==1.11.2
xmltodict==0.12.0
zipp==0.6.0

0 comments on commit 9ae42e3

Please sign in to comment.