myint / pyformat Goto Github PK
View Code? Open in Web Editor NEWFormats Python code to follow a consistent style
Home Page: https://pypi.python.org/pypi/pyformat
Formats Python code to follow a consistent style
Home Page: https://pypi.python.org/pypi/pyformat
There is a nice project https://github.com/asottile/add-trailing-comma. Could you add it as an additional optional formatter?
When pyformat
is used, an existing pep8 configuration is not applied.
Example:
# test.py
l = ['a', 'really', 'really', 'really', 'long', 'line', 'that', 'violates', 'max-line', 'limit']
# .pep8
[pep8]
max-line-length=120
Running autopep8 -i test.py
results in:
# test.py after running autopep8
l = ['a', 'really', 'really', 'really', 'long', 'line', 'that', 'violates', 'max-line', 'limit']
As expected the file was not changed because it is under the 120 max-line-length
in the autopep8 config.
Running pyformat -i test.py
results in:
# test.py after running pyformat
l = ['a', 'really', 'really', 'really', 'long',
'line', 'that', 'violates', 'max-line', 'limit']
yapf
has very similar command line interface as pyformat
but provides one additional one: pass a code via stdin and print result on stdout.
Such a feature makes it very easy for integrating e.g. into vim
editor by adding following line into .vimrc
file:
autocmd FileType python setlocal equalprg=yapf
and user may format the code of whole file:
gg=G
or in visual mode (multiple lines selected):
=
pyformat
does not accept file on stdin thus it is not possible to use it in the same style. Adding such feature to pyformat
would make use simpler.
With newest docformatter version 1.5, pyformat fails with AttributeError: module 'docformatter' has no attribute 'format_code'
The isort library can sort the imports so that they fully comply with the import section of PEP 8. (autopep8 only does a few changes in regards to imports.)
Which we need for HypothesisWorks/hypothesis#1136. Do you have any advice on how to handle this, or can we just wait for a pyformat update?
$ cat unicode.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
'ö'
$ autopep8 -i unicode.py
$ pyformat -i unicode.py
Traceback (most recent call last):
File "/usr/local/bin/pyformat", line 42, in <module>
standard_error=sys.stderr))
File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 179, in main
format_multiple_files(set(args.files), args, standard_out, standard_error)
File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 126, in format_multiple_files
_format_file((name, args, standard_out, standard_error))
File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 104, in _format_file
format_file(*parameters[:-1])
File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 79, in format_file
formatted_source = format_code(source, aggressive=args.aggressive)
File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 64, in format_code
formatted_source = fix(formatted_source)
File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 54, in <lambda>
yield lambda code: autopep8.fix_string(code, options=autopep8_options)
File "/usr/local/lib/python2.7/dist-packages/autopep8.py", line 1941, in fix_string
source = source.decode(locale.getpreferredencoding(False))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 44: ordinal not in range(128)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.