Giter Club home page Giter Club logo

Comments (7)

shenker avatar shenker commented on July 18, 2024 2

Thanks for this! If anybody finds this useful, I extended @JacobHayes 's code to also reformat Jupyter notebook cells: https://github.com/shenker/nbcleanse/blob/master/nbcleanse.py

from git-filter-repo.

PavelPolyakov avatar PavelPolyakov commented on July 18, 2024 2

Thanks @newren and people in this thread for the inspiration, here is another adaptation of the lint example.
This time it is meant to format Java code using formatter-maven-plugin and custom style (for example) .

Files are processed in batches. Path to the style should be changed to the real one.

Here is gist: 🔗 .

from git-filter-repo.

JacobHayes avatar JacobHayes commented on July 18, 2024 1

Perfect, got it working. Thanks again!

from git-filter-repo.

newren avatar newren commented on July 18, 2024

filter-repo avoids checking out any of the files onto disk, which is part of its speedup. In that sense filter-repo's tree-filter is a bit easier to use here since your linting program probably expects the file on disk in normal format rather than trying to read it from git's history. However, contrib/filter-repo-demos/lint-history was specifically written to show how to lint files in history. You could just call it as
lint-history black
and have it lint every non-binary file in history for you, or you could tweak it to only call the linter for .py files (while keeping all other files as-is).

Also, the lint-history example actually includes three different implementations of how to do it: one in a comment showing how you could do it without writing a full-fledged python script that imports filter-repo, one which does it as a blob callback assuming that it doesn't matter to the lint program what the name of the file is (it just writes every file to .git/info/tmpfile and then runs the linter on that), and a third one that does it as a commit callback which makes sure the basename of the file is the same. You'll only need to use one of the three, but all three are in the demo since it's just trying to demonstrate how things could be done.

from git-filter-repo.

JacobHayes avatar JacobHayes commented on July 18, 2024

Thanks @newren, I'll try that out! It was close to working with:

git filter-repo --force --blob-callback '
  import black
  blob.data = black.format_str(blob.data.decode(), mode=black.FileMode()).encode()
'

but I needed to only reformat the python files and couldn't figure out how to limit it. Should be able to put something together with the lint-history commit-callback version!

from git-filter-repo.

newren avatar newren commented on July 18, 2024

Thanks everyone for posting examples here; I put a comment pointing at this issue in the lint-history code so that others will be more likely to find all your examples.

from git-filter-repo.

ankostis avatar ankostis commented on July 18, 2024

Adapted your script into #464 that allows to add new or replace files produced from shell commands.

from git-filter-repo.

Related Issues (20)

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.