Skip to main content

reindent script by Tim Peters

Project description

reindent

Packaged Tools/scripts/reindent from cpython

reindent [-d][-r][-v] [ path ... ]

-d (--dryrun)   Dry run.   Analyze, but don't make any changes to, files.
-r (--recurse)  Recurse.   Search for all .py files in subdirectories too.
-n (--nobackup) No backup. Does not make a ".bak" file before reindenting.
-v (--verbose)  Verbose.   Print informative msgs; else no output.
   (--newline)  Newline.   Specify the newline character to use (CRLF, LF).
                           Default is the same as the original file.
-h (--help)     Help.      Print this usage information and exit.

Change Python (.py) files to use 4-space indents and no hard tab characters. Also trim excess spaces and tabs from ends of lines, and remove empty lines at the end of files. Also ensure the last line ends with a newline.

If no paths are given on the command line, reindent operates as a filter, reading a single source file from standard input and writing the transformed source to standard output. In this case, the -d, -r and -v flags are ignored.

You can pass one or more file and/or directory paths. When a directory path, all .py files within the directory will be examined, and, if the -r option is given, likewise recursively for subdirectories.

If output is not to standard output, reindent overwrites files in place, renaming the originals with a .bak extension. If it finds nothing to change, the file is left alone. If reindent does change a file, the changed file is a fixed-point for future runs (i.e., running reindent on the resulting .py file won't change it again).

The hard part of reindenting is figuring out what to do with comment lines. So long as the input files get a clean bill of health from tabnanny.py, reindent should do a good job.

The backup file is a copy of the one that is being reindented. The ".bak" file is generated with shutil.copy(), but some corner cases regarding user/group and permissions could leave the backup file more readable than you'd prefer. You can always use the --nobackup option to prevent this.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reindent-3.5.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

reindent-3.5.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file reindent-3.5.1.tar.gz.

File metadata

  • Download URL: reindent-3.5.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for reindent-3.5.1.tar.gz
Algorithm Hash digest
SHA256 59aeb8fbc16e45686f65df23b91896a17eb14ace7a7546860f50d2bb5ec4c9c0
MD5 6c38f5ede98bbd3eaaad46337ba3cd44
BLAKE2b-256 2bb8ae4d040d58d2be57a2f738656ea5dcce95410d3be58ae9e16a5ab54e67e6

See more details on using hashes here.

File details

Details for the file reindent-3.5.1-py3-none-any.whl.

File metadata

  • Download URL: reindent-3.5.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for reindent-3.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1248ddf8bb209499ddaff6e841d60c822edff7dcff5e0e5beedbafa06dbc33aa
MD5 b6d05a5ce0c7adad0aad05828ebb6eae
BLAKE2b-256 e221bbfe0baec43c1d1cb1683653334b55161ccc950991c1803e17f276b5759a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page