Giter Site home page Giter Site logo

yapf-diff's Introduction

yapf_diff

change only what was changed

install

with pipenv
pipenv install git+https://github.com/luxresearch/yapf-diff.git@master#egg=yapf-diff
with pip
pip install git+https://github.com/luxresearch/yapf-diff.git@master#egg=yapf-diff
in requirements.txt
# requirements.txt: for a fast download
https://github.com/luxresearch/yapf-diff/archive/master.tar.gz

should I use yapf_diff?

Only if formatting all the lines in your modified file(s) would cause an unacceptably big diff in your revision history. PEP 8 recommends keeping your code consistent with the surrounding code. yapf-diff guarantees consistency only within the lines touched within a diff.

  • if you're the the one choosing how and when to lint, choose black for consistency and speed.
  • if formatting entire file at a time is an option, use something like
git diff --name-only | xargs black # or yapf, if you need a custom format

usage

# usage: yapf-diff [-h] [-d] [--debug] [-i] [--from-git-diff [BASE_REF]]
#
# format only changed lines
#
# optional arguments:
#   -h, --help            show this help message and exit
#   -d, --diff            print the yapf args and produced diff
#   --debug               print the style yapf is picking up
#   -i, --in-place        modify the changed files
#   --from-git-diff [BASE_REF]
#                         if used as a flag, this indicates that stdin is from
#                         git diff. If used as an argument, it indicates a ref
#                         against which to call git diff

# examples:
git diff origin/master | python -m yapf-diff --diff
python -m yapf-diff --from-git-diff="$(git log --merges -n 1)" --diff

Credit where credit is due

This module modifies a function from pycodestyle, which is under an MIT license. Their license is included within ./src/lib.py. Thanks to the PyCQA team for doing a much better job at unified diff parsing than my initial implementation.

See also:

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.