A CLI-based tool for making bulk changes to file text.

pip install ernest==0.1.6



What Ernest is

  1. A CLI-based tool for making bulk changes to files via Python, partly achieved through syntax trees (for .py files, using redbaron) and partly through regular expressions.
  2. Useful if you're making a load of really boring changes that you can't really do with regexes alone (or only with regexes the length of War and Peace).
  3. Named after the Nitpicker from The Adventure Zone.

It was made as part of a refactoring effort for a specific project and as such is pretty limited at the moment - it currently only contains methods for refactoring Python files but it is intended to be extensible.

What Ernest isn't

  1. A tool that will fix all your syntax problems.
  2. Pulling from any set of code standards - any new refactorings have to defined manually (though you can pick and choose which ones to apply).
  3. Particularly reliable.


pip install ernest


You can override the defaults by making a JSON config file. By default Ernest looks in ~/.config/ernest/ernest.json but you can specify a different json file using the --config option.

  "name": "",  // the name of the project - used in headers
  "header": [  // added at the top of python files
    "#!/usr/bin/env python",
    "# encoding: utf-8",
    "This file is part of the {} project",  // example of how the name is used
  "imports": {  // checks python imports
    "exclude": [],  // do not allow these ever
    "conditional_exclude": {},  // do not allow these submodules from the main module, e.g. {'ernest': 'models'} excludes 'ernest.models' but allows 'ernest.helpers'
    "conditional_include": {}  // allow only these submodules from the main module, e.g. {'ernest': 'models'} allows 'ernest.models' but not 'ernest.helpers'

You can find an example of the config file in the data folder.



ernest /project/path fix py

General Options

--config /path/to/config
--name "My Project"



ernest [--config /path/to/config] [--name "My Project"] [/path/to/dir] stats [filetypes]

Show statistics for all files:

ernest /path/to/dir stats

Stats for just (e.g.) txt and md files:

ernest /path/to/dir stats txt md


ernest [--config /path/to/config] [--name "My Project"] [/path/to/dir] fix [filetype] [fix(es)]

Run all fixes for .py files:

ernest /path/to/dir fix py all

Run the literal string quote and docstring quote fixes for .py files:

ernest /path/to/dir fix py literal docstring


Please feel free to fork, submit pull requests, etc.! It doesn't have to be limited to Python files - that's just how Ernest processes the text.