A CLI-based tool for making bulk changes to file text.
Project description
Ernest
What Ernest is
- 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.
- 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).
- 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
- A tool that will fix all your syntax problems.
- Pulling from any set of code standards - any new refactorings have to defined manually (though you can pick and choose which ones to apply).
- Particularly reliable.
Installation
pip install ernest
Configuration
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.
Usage
Quickstart
ernest /project/path fix py
General Options
--config /path/to/config
--name "My Project"
Subcommands
stats
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
fix
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
Contributing
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ernest-0.1.6.tar.gz.
File metadata
- Download URL: ernest-0.1.6.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53bef7a42d6c1ccfe0b746ddff84cc5c7505e54148da6f67756217445169a443
|
|
| MD5 |
20bf8b41e5b3d5443d3986fcc292204d
|
|
| BLAKE2b-256 |
f0f1461b4295421d2c52ca1de134b697024e7a74e359157e9a1a1cec9ae57073
|
File details
Details for the file ernest-0.1.6-py3.7.egg.
File metadata
- Download URL: ernest-0.1.6-py3.7.egg
- Upload date:
- Size: 11.9 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5923d02e6073d331194c9d51e3d3b08b1e4ba68946609c343f9918eef954d7d3
|
|
| MD5 |
a9cf4350aba25a96079d5a08c3379ab9
|
|
| BLAKE2b-256 |
ff9fe775ae87e9d822c8c4e73d6cb174e5598103e9ee3c4484493cf4457b265e
|
File details
Details for the file ernest-0.1.6-py3-none-any.whl.
File metadata
- Download URL: ernest-0.1.6-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3e5e6ae791b54f1404ca62fb6f080cdd7bf2a122aaf5be844c70f5acc7c04b3
|
|
| MD5 |
a83186d269b1c82aff68e940b29ed070
|
|
| BLAKE2b-256 |
711b957d4f26ca61e819d6071271c06c8503071127a5d43615ff494f8e256ec6
|
File details
Details for the file ernest-0.1.6-py2.7.egg.
File metadata
- Download URL: ernest-0.1.6-py2.7.egg
- Upload date:
- Size: 11.9 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee3c768788a2f5bac50ff662be56ad199a42a52676e1c33a164b4ca390f02e94
|
|
| MD5 |
8bba8aa0adcdd3dec9e524bb0d5b8732
|
|
| BLAKE2b-256 |
7a42f02feac615ee4a90322c973e8ec6757f48b4df7e444b0e80312e51979763
|
File details
Details for the file ernest-0.1.6-py2-none-any.whl.
File metadata
- Download URL: ernest-0.1.6-py2-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
958a09fcb19b12967e4e7e1883dd5487198a33d0d56e2d4f76c5a43d935de6c1
|
|
| MD5 |
77e7a6566debd95f677438642c528dd5
|
|
| BLAKE2b-256 |
3b0ec8da4c93aff85b83a64c69f81fc8f328c9981b9fe7af7a3f21a7a2ae0bbc
|