Git Product home page Git Product logo

dev-tool-testing's Introduction

dev-tool-testing

Using Black

To run black on a single file, we can do:

black single_python_file.py

which will automatically write the necessary formatting changes directly to the file. To do a "dry run" and see the effect of the formatting changes without altering the file itself, do:

black --diff single_python_file.py

To format all the Python files (or check all the files) in the current directory, do:

black .

Run Black Automatically Before Committing

  1. These instructions assume you have an active Conda environment built for PVAde which contains the black package for code formatting. If not, build a minimal Conda environment with black and numpy to follow along.

  2. Activate your Conda environment and install the pre-commit package:

    pip install pre-commit
  3. Define the .pre-commit-config.yaml file at the root of the repo (this step is already done here)

  4. Install the pre-commit hooks in your .git/ directory:

    pre-commit install
  5. To test it, try to commit a new file or modify an existing file with formatting problems (for example, a line of code longer than 88 characters). Add this file to the staging area, git add modified_file.py, and then commit it, git commit -m "add a too long line". If configured correctly, you should see something like the following:

    (pvade) [conda-arm] eyoung$ git commit -m "add a too long line"
    black....................................................................Failed
    - hook id: black
    - files were modified by this hook
    
    reformatted modified_file.py
    
    All done! ✨ 🍰 ✨
    1 file reformatted.

    where black has alerted you to the fact that formatting changes were necessary. To proceed with the commit, you must re-add the formatted file to the staging area, git add modified_file.py, then again commit it git commit -m "add a too long line", which should result in something like:

    (pvade) [conda-arm] eyoung$ git commit -m "add a too long line"
    black....................................................................Passed
    [main 013b033] add a too long line
    1 file changed, 4 insertions(+)

dev-tool-testing's People

Contributors

eyoung55 avatar arswalid avatar

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.