一个简单而灵活的工具来转换缩进。
FixIndents的Python项目详细描述
一个简单而灵活的工具,用于转换源代码文件中的缩进。
为什么?
我需要转换源代码文件中的缩进,但我没有 能够找到任何真正灵活的方式来做到这一点。所以,这是一次尝试 编写足够灵活的处理任何可能的用例的代码。
安装
来自github
要安装最新版本,只需克隆存储库并运行setup.py脚本:
git clone https://github.com/mattoufoutu/FixIndents.git cd FixIndents python setup.py install
来自Pypi
像往常一样…:
pip install FixIndents
用法
< H3>固定物-h<EH3>
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.
示例
将fixindents.py4空格缩进转换为制表符缩进,写入fixendents_tabs.py:
fixindents.py --source-size 4 --dest-tabs --source fixindents.py --dest fixindents_tabs.py
将以前创建的fixindents_tabs.py转换为两个空格的缩进,写入fixindents_space.py:
fixindents.py --source-tabs --dest-size 2 --source fixindents_tabs.py --dest fixindents_space.py
将FixIndents文件夹中的所有文件从4个空格转换为制表符,写入FixIndentsTabs文件夹:
fixindents.py --source-size 4 --dest-tabs --source FixIndents --dest FixIndentsTabs
将FixIndents文件夹中的4个空格.py文件转换为制表符,写入FixIndentsTabs文件夹:
fixindents.py --source-size 4 --dest-tabs --source FixIndents --dest FixIndentsTabs --extentions ".py"
贡献
请随意分叉这个存储库并改进代码,任何pull请求 会很受欢迎的。