Giter VIP home page Giter VIP logo

ernest's Introduction

Ernest

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.

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.

ernest's People

Contributors

alycejenni avatar

Watchers

James Cloos avatar

ernest's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.