Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

A simple yet flexible utility to convert indentation.

Project description

A simple yet flexible utility to convert indentation in your source code files.

Why?

I needed to convert indentations in a source code file, and I wasn’t able to find anything really flexible to do this. So, this is an attempt to code something flexible enough to handle any possible use-case.

Installation

From GitHub

To install the latest revision, just clone the repository and run the setup.py script:

git clone https://github.com/mattoufoutu/FixIndents.git
cd FixIndents
python setup.py install

From PyPI

As usual…:

pip install FixIndents

Usage

fixindents -h

usage: fixindents.py [-h] [--version] (--source-tabs | --source-size SIZE)
                     (--dest-tabs | --dest-size SIZE) --source SOURCE
                     (--dest DEST | --debug) [--exclude FOLDERS]
                     [--extensions EXTENSIONS]

A simple yet flexible utility to convert indentation.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --source-tabs         Source file uses tabs for indentation.
  --source-size SIZE    Indents size in source file(s).
  --dest-tabs           Use tabs for indentation in destination file.
  --dest-size SIZE      Indents size in destination file.
  --source SOURCE       File of folder from which code should be read.
  --dest DEST           File or folder to which code should be written.
  --debug               Output converted data to console, don't write
                        anything.
  --exclude FOLDERS     Comma-separated list of directory names to ignore.
                        Only useful when SOURCE is a directory.
  --extensions EXTENSIONS
                        Comma-separated list of specific file extensions to
                        convert. Only useful when SOURCE is a directory.

Exemples

Convert fixindents.py 4-spaces indents to tab indents, write to fixendents_tabs.py:

fixindents.py --source-size 4 --dest-tabs --source fixindents.py --dest fixindents_tabs.py

Convert previously created fixindents_tabs.py to 2-spaces indents, write to fixindents_space.py:

fixindents.py --source-tabs --dest-size 2 --source fixindents_tabs.py --dest fixindents_space.py

Convert all files in the FixIndents folder from 4-spaces to tabs, write to the FixIndentsTabs folder:

fixindents.py --source-size 4 --dest-tabs --source FixIndents --dest FixIndentsTabs

Convert 4-spaces .py files in the FixIndents folder to tabs, write to the FixIndentsTabs folder:

fixindents.py --source-size 4 --dest-tabs --source FixIndents --dest FixIndentsTabs --extentions ".py"

Contribute

Feel free to fork this repository and improve the code, any pull-request will be welcome.

Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
FixIndents-0.2.tar.gz (2.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page