Skip to main content

Apply black only on mdified files

Project description

apply black only on modifed lines.

POC, still a lot of work.

what

darken --since <git commitish>

Will (try to) reformat only modified lines since <commit-ish>

or

darken --range 12-34,64-67 foo.py

Should only reformat line 12-34 and 64-67 of foo.py.

how

Looking at black internal it seem relatively hard to pass a flag tell it to only refactor some nodes. But, black support fmt:on/off comments;

So this :

  • insert comments;
  • apply black
  • remove the comments it added.
  • TADA (TM)

Long term API design:

Get - some – integration with git; I'm thinking something along:

$ darken --since <commitish>

It would run git in the BG, figure out which files and which lines have changed and apply to black to relevant lines.

I'm thinking that if the changed lines represent a significant portion of the file we could expand what need to be reformatted. Th metric for this need to be determined. I prefer the $ darken --since to a $ darken <a given commit only> as it will correctly handle many things like merges, multipple-commits branches...etc.

Issues:

This is an issue:

https://github.com/python/black/issues/560

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

darken-0.0.3.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

darken-0.0.3-py2.py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page