Skip to content

Commit

Permalink
Compare original file contents. Bump pre-commit versions and config.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhoherd committed Dec 21, 2019
1 parent 1a8d3b9 commit d0ec497
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401
max-line-length = 120
max-complexity = 18
select = B,C,E,F,W,T4,B9
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
*~
.DS_Store
.idea
.vscode
build
dist
16 changes: 9 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v2.4.0
hooks:
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
- id: check-toml
- id: check-xml
- id: check-yaml
args: ['--allow-multiple-documents']
- id: debug-statements
- id: end-of-file-fixer
- id: flake8
- id: mixed-line-ending
args: ['--fix=lf' ]
args: ['--fix=lf']
- id: requirements-txt-fixer
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/detailyang/pre-commit-shell
rev: 1.0.5
hooks:
- id: shell-lint
- repo: https://github.com/ambv/black
rev: 19.3b0
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
args: ['-l', '132']
Expand All @@ -33,13 +34,14 @@ repos:
- id: remove-tabs
exclude_types: [makefile, binary]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.18.0
rev: v1.19.0
hooks:
- id: yamllint
- repo: https://github.com/danielhoherd/pre-commit-hooks
rev: 0b84f996d085b772bcdb94279ebcddc827a2fd57
rev: 1a8d3b95b329e8aecd81ce0620a220f4053b46f0
hooks:
- id: CVE-2017-18342
- id: remove-en-dashes
- id: remove-unicode-non-breaking-spaces
- id: remove-unicode-zero-width-non-breaking-spaces
- id: remove-en-dashes
- id: sort-gitignore
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://github.com/psf/black#configuration-format
[tool.black]
line-length = 132
target-version = ['py36', 'py37', 'py38']
include = '\.pyi?$'
exclude = '(venv|.vscode)'
18 changes: 11 additions & 7 deletions scripts/sort-ansible-requirements-yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import argparse


def sort_yaml(data):
def sort_data(data):
return_data = []
sorted_data = sorted(data, key=lambda record: record["name"])

for entry in sorted_data:
entry = sorted(entry)
sorted_keys = sorted(entry)
return_data.append({key: entry[key] for key in sorted_keys})

return yaml.safe_dump(sorted_data)
return sorted_data


def main(argv=None):
Expand All @@ -24,12 +27,13 @@ def main(argv=None):

for filename in args.filenames:
with open(filename, "r+") as f:
input_yaml = yaml.safe_load(f)
output_yaml = sort_yaml(input_yaml)
if yaml.safe_dump(input_yaml) != output_yaml:
original_file_content = f.read()
input_data = yaml.safe_load(original_file_content)
output_data_dumped = "---\n" + yaml.safe_dump(sort_data(input_data))
if original_file_content != output_data_dumped:
print(f"Sorting contents of {filename}")
f.seek(0)
f.write("---\n" + output_yaml)
f.write(output_data_dumped)
f.truncate()

retval = 1
Expand Down

0 comments on commit d0ec497

Please sign in to comment.