Kaydet (Commit) 7980630d authored tarafından Anthony Sottile's avatar Anthony Sottile

Add initial skeleton

üst
[run]
branch = True
source =
.
omit =
.tox/*
/usr/*
*/tmp*
setup.py
# Don't complain if non-runnable code isn't run
*/__main__.py
[report]
show_missing = True
skip_covered = True
exclude_lines =
# Have to re-enable the standard pragma
\#\s*pragma: no cover
# We optionally substitute this
${COVERAGE_IGNORE_WINDOWS}
# Don't complain if tests don't hit defensive assertion code:
^\s*raise AssertionError\b
^\s*raise NotImplementedError\b
^\s*return NotImplemented\b
^\s*raise$
# Don't complain if non-runnable code isn't run:
^if __name__ == ['"]__main__['"]:$
[html]
directory = coverage-html
# vim:ft=dosini
*.egg-info
*.pyc
/.cache
/.coverage
/.tox
/venv*
- repo: https://github.com/pre-commit/pre-commit-hooks
sha: v0.7.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: autopep8-wrapper
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: name-tests-test
- id: requirements-txt-fixer
- id: flake8
- repo: https://github.com/asottile/reorder_python_imports
sha: v0.3.1
hooks:
- id: reorder-python-imports
- id: add-trailing-comma
name: add-trailing-comma
description: Automatically add trailing commas to calls and literals.
entry: add-trailing-comma
language: python
types: [python]
language: python
matrix:
include:
- env: TOXENV=py27
- env: TOXENV=py35
python: 3.5
- env: TOXENV=py36
python: 3.6
- env: TOXENV=pypy
install: pip install coveralls tox
script: tox
after_success: coveralls
cache:
directories:
- $HOME/.cache/pip
- $HOME/.pre-commit
Copyright (c) 2017 Anthony Sottile
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
[![Build Status](https://travis-ci.org/asottile/add-trailing-comma.svg?branch=master)](https://travis-ci.org/asottile/add-trailing-comma)
[![Coverage Status](https://coveralls.io/repos/github/asottile/add-trailing-comma/badge.svg?branch=master)](https://coveralls.io/github/asottile/add-trailing-comma?branch=master)
add-trailing-comma
=========
A tool (and pre-commit hook) to automatically add trailing commas to calls and
literals.
## Installation
`pip install add-trailing-comma`
## As a pre-commit hook
See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
Sample `.pre-commit-config.yaml`:
```yaml
- repo: https://github.com/asottile/add-trailing-comma
sha: v0.0.0
hooks:
- id: add-trailing-comma
```
## TODO
`--py35-plus` will append a trailing comma even after `*args` or `**kwargs`
(this is a syntax error in older versions).
from __future__ import absolute_import
from __future__ import unicode_literals
import argparse
import io
def fix_file(filename, args):
with open(filename, 'rb') as f:
contents_bytes = f.read()
try:
contents_text_orig = contents_text = contents_bytes.decode('UTF-8')
except UnicodeDecodeError:
print('{} is non-utf-8 (not supported)'.format(filename))
return 1
if contents_text != contents_text_orig:
print('Rewriting {}'.format(filename))
with io.open(filename, 'w', encoding='UTF-8') as f:
f.write(contents_text)
return 1
return 0
def main(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*')
parser.add_argument('--py35-plus', action='store_true')
args = parser.parse_args(argv)
ret = 0
for filename in args.filenames:
ret |= fix_file(filename, args)
return ret
if __name__ == '__main__':
exit(main())
coverage
flake8
pre-commit
pytest
[wheel]
universal = True
from setuptools import setup
setup(
name='add_trailing_comma',
description='Automatically add trailing commas to calls and literals',
url='https://github.com/asottile/add_trailing_comma',
version='0.0.0',
author='Anthony Sottile',
author_email='asottile@umich.edu',
classifiers=[
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
install_requires=['tokenize-rt'],
py_modules=['add_trailing_comma'],
entry_points={
'console_scripts': ['add-trailing-comma = add_trailing_comma:main'],
},
)
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
from add_trailing_comma import main
def test_main_trivial():
assert main(()) == 0
def test_main_noop(tmpdir):
f = tmpdir.join('f.py')
f.write('x = 5\n')
assert main((f.strpath,)) == 0
assert f.read() == 'x = 5\n'
# def test_main_changes_a_file(tmpdir, capsys):
# f = tmpdir.join('f.py')
# f.write('x(\n 1\n)\n')
# assert main((f.strpath,)) == 1
# out, _ = capsys.readouterr()
# assert out == 'Rewriting {}\n'.format(f.strpath)
# assert f.read() == 'x(\n 1,\n)\n'
def test_main_syntax_error(tmpdir):
f = tmpdir.join('f.py')
f.write('from __future__ import print_function\nprint 1\n')
assert main((f.strpath,)) == 0
def test_main_non_utf8_bytes(tmpdir, capsys):
f = tmpdir.join('f.py')
f.write_binary('# -*- coding: cp1252 -*-\nx = €\n'.encode('cp1252'))
assert main((f.strpath,)) == 1
out, _ = capsys.readouterr()
assert out == '{} is non-utf-8 (not supported)\n'.format(f.strpath)
# def test_py35_plus_argument_star_args(tmpdir):
# f = tmpdir.join('f.py')
# f.write('x(\n *args\n)\n')
# assert main((f.strpath,)) == 0
# assert f.read() == 'x(\n *args\n)\n')
# assert main((f.strpath, '--py35-plus')) == 1
# assert f.read() == 'x(\n *args,\n)\n'
[tox]
project = add-trailing-comma
# These should match the travis env list
envlist = py27,py35,py36,pypy
[testenv]
deps = -rrequirements-dev.txt
commands =
coverage erase
coverage run -m pytest {posargs:tests}
coverage report --show-missing --fail-under 100
pre-commit install -f --install-hooks
pre-commit run --all-files
[testenv:venv]
envdir = venv-{[tox]project}
commands =
[pep8]
ignore = E265,E309,E501
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment