coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
527 stars 92 forks source link

[WIP] added black #45

Closed tommyod closed 4 years ago

tommyod commented 4 years ago

Added the black code formatter.

The code should be formatted consistently. This makes it easier for many people to work on the project (read some opinions e.g. here). Black is one of many formatters that are possible to use. I like black because it's simple - after working on the code one simply runs black -l 79 to auto-format the code, see black --help.

While the formatter for this project does not have to be black, there should be some formatter so a code style is enforced.

I ran black on the code, and it produces a large diff. Most of this is just trivial changes to the codebase. If you want to verify that I haven't done anything malicious with the actual code, create a new branch, run black locally and check the diff:

$ git checkout -b my_test_branch # Create a new branch
$ git remote add tommy https://github.com/tommyod/python-mip.git # Get my branches
$ git fetch tommy
$ pip install black # assuming python 3.6+
$ black mip -l 79 # Run black on your local branch
$ git commit -am "ran black locally"
$ git diff tommy/black # Verify that I haven't changed the code apart from running black
$ git checkout master
$ git branch -d my_test_branch # Delete the branch
$ git remote remove tommy # Remove the remote

The code above should demonstrate that the only change I've made is running black.

tommyod commented 4 years ago

If you merge this, please squash merge. The previous PR was not squash-merged, leading to 7 commits, polluting the git history.

h-g-s commented 4 years ago

Great, thanks. Since I made small changes recently and some conflicts appeared, I'll run black locally and commit and then merge the commits for .travis