Skip to main content

pythontidy2

Travis PyPI

Usage

python -m pythontidy2 [-t expandtabsize] script.py

Installation

pip install pythontidy2

Description

Life is short, format the code automatically

(人生苦短,自动排版)

Tidy python scripts

Effect

Convert Tabs to Spaces(Tabs sized can be decide in argument -t, default is 4)

Delete white spaces at end of line

Own thoughts about code format, some part are different from PEP8

PEP8: Whitespace in Expressions and Statements Not compliant

Always add 1 white space between operators

Align dict and assignment statments like following

From:

list = [1, 2, {
   'Alicedefg': '2341',
   'Beth' : "c",
   'Cecil' : '3258',
}, 4]

To:

list = [1, 2, {
                'Alicedefg' : '2341',
                'Beth'      : "c",
                'Cecil'     : '3258',
                }, 4]

From:

doc = ""
long_variable = ((doc+' ') if doc else '')
x = ""

To:

doc           = ""
long_variable = ((doc + ' ') if doc else '')
x             = ""

Limitation

Only Windows(CRLF) Linux/Modern OSX(LF) end of line mark supported

Do not support classic Mac end of line mark(CR)

Widechar(Asian) in sorce code (as variable or dict Key) not tested

VIM Integration

Below example binds the tidy fucntion to F7

command -range=% -nargs=* TidyPython <line1>,<line2>!python -m pythontidy2
fun DoTidyPython()
    let Pos = line2byte( line( "." ) )
    :TidyPython
    exe "goto " . Pos
endfun
au Filetype python nmap <F7> :call DoTidyPython()<CR>
au Filetype python imap <F7> <ESC>:call DoTidyPython()<CR>
au Filetype python vmap <F7> :TidyPython<CR>

License

BSD

Copyright (c) 2016, Boying Xu All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Metadata

Release files for pythontidy2 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pythontidy2 0.1.9
File Size Uploaded
pythontidy2-0.1.9.zip 8.2 kB Details

Release files / pythontidy2-0.1.9.zip

Download URL pythontidy2-0.1.9.zip
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e0ec08101f4681f5c095de354b9b756db2c3203fed0db309349f3ae5259dc86e
BLAKE2b-256 checksum
How to use checksums
823aea13c08714d9af5c36fdaf0b612397e922c6001d4f3b5cd8dde6bc738ad9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.9 This release

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page