Skip to content

Commit

Permalink
Replace ruamel.yaml with oyaml.
Browse files Browse the repository at this point in the history
  • Loading branch information
feluxe committed Sep 30, 2018
1 parent c52e8ea commit 77b9539
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ wheel = "*"
setuptools = "*"
pylint = "*"
yapf = "*"
"ruamel.yaml" = "*"
cmdi = "*"
sty = "*"
prmt = "*"
headlines = "*"
oyaml = "*"

[requires]
python_version = "3.6"
Expand Down
71 changes: 32 additions & 39 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 24 additions & 26 deletions Project
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
"public_name": "buildlib"
"interal_name": "buildlib"
"version": "2.0.1"
"license": "unlicensed"
"author": "Felix Meyer-Wolters"
"author_email": "[email protected]"
"maintainer": "Felix Meyer-Wolters"
"maintainer_email": "[email protected]"
"url": "https://github.com/feluxe/buildlib"
"description": "A library to help build projects."
"keywords": ["build", "library"]

"pypi":
"install_requires": ["headlines", "prmt", "ruamel.yaml", "cmdi", "sty", "requests"]
"tests_require": []
"packages": ["buildlib"]
"package_dir": {"buildlib": "buildlib"}
"package_data": {}
"py_modules": []
"data_files": []
"classifiers": []
"platforms": ""
"entry_points": {"console_scripts": []
, "gui_scripts": []
}

public_name: buildlib
interal_name: buildlib
version: 2.0.2
license: unlicensed
author: Felix Meyer-Wolters
author_email: [email protected]
maintainer: Felix Meyer-Wolters
maintainer_email: [email protected]
url: https://github.com/feluxe/buildlib
description: A library to help build projects.
keywords: [build, library]
pypi:
install_requires: [headlines, prmt, oyaml, cmdi, sty, requests]
tests_require: []
packages: [buildlib]
package_dir: {buildlib: buildlib}
package_data: {}
py_modules: []
data_files: []
classifiers: []
platforms: ''
entry_points:
console_scripts: []
gui_scripts: []
2 changes: 1 addition & 1 deletion buildlib/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def bump_version(
config_file: str = 'Project',
) -> str:

cfg: dict = yaml.loadfile(config_file, keep_order=True)
cfg: dict = yaml.loadfile(config_file)

if not semver_num:
semver_num = semver_prompt.semver_num_by_choice(cfg['version'])
Expand Down
41 changes: 19 additions & 22 deletions buildlib/yaml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
import ruamel.yaml as yaml
import oyaml as yaml
import sys
from typing import Any


def loadfile(
file: str,
keep_order: bool = False
) -> dict:
def loadfile(file: str, safe=False) -> dict:
"""
Load yaml file.
"""
with open(file, 'r') as stream:
if keep_order:
return yaml.load(stream.read(), Loader=yaml.RoundTripLoader)
else:
return yaml.safe_load(stream.read())


def savefile(
data: Any,
file: str,
default_style: str = '"'
) -> None:
if safe:
with open(file, 'r') as f:
return yaml.safe_load(f.read())
else:
with open(file, 'r') as f:
return yaml.load(f.read())


def savefile(data: Any, file: str, **kwargs) -> None:
"""
Save data to yaml file.
"""
with open(file, 'w') as yaml_file:
yaml.dump(data, yaml_file, Dumper=yaml.RoundTripDumper,
default_style=default_style)
with open(file, 'w') as f:
yaml.dump(data=data, stream=f, **kwargs)


def pprint_yaml(data: Any) -> None:
lines: list = yaml.round_trip_dump(
data, indent=4,

lines: list = yaml.dump(
data,
indent=4,
block_seq_indent=4,
).splitlines(True)

print(''.join([line for line in lines]))

0 comments on commit 77b9539

Please sign in to comment.