Skip to content

Use Black for code formatting #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,attribute-defined-outside-init
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,attribute-defined-outside-init,bad-continuation

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
3 changes: 2 additions & 1 deletion .stickler.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
linters:
flake8:
enable: true
ignore: F401,E226,I101,I100,E741
ignore: E203, E266, E501, W503, F401, E741
max-line-length: 88
shellcheck:
shell: bash
csslint:
Expand Down
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
- secure: "md4fgPt9RC/sCoN5//5PcNHLUd9gWQGewV5hFpWW88MRTjxTng1Zfs8r7SqlF2AkEEepFfyzq0BEe9c3FMAnFbec3KmqdlQen4V8xDbLrcTlvkPlTrYGbAScUvdhhqojB//hMHoTD4KvxAv9CiUwFBO4hCMmj2buWHUbV9Ksu5WCW9mF/gkt/hIuYAU6Mbwt8PiYyMgUpzMHO1vruofcWRaVnvKwmBqHB0ae86D4/drpwn4CWjlM12WUnphT2bssiyPkw24FZtCN6kPVta6bLZKBxu0bZpw2vbXuUG+Yh19Q4mp8wNYT3XSHJf8Hl5LfujF48+cLWu+6rlCkdcelyVylhWLFc3rGOONAv4G8jWW2yNSz/bLQfJnMpd81fQEu5eySmFxB7mdB0uyKpvIG1jMJQ73LlYKakKLAPdYhMFyQAHoX9gvCE3S4QR95DBMi5gM/pZubOCcMLdjPHB5JKpJHSjxbOzyVwgmsUIEgd5Bi2vZvvYQXn1plk4xpQ3PhXc+/gi33bzY89mKcfOn0HJ2pD1vLqDXRCBsMCakoLZ0JB/6bacaz4FngbsGWuQ+I1cz20lJGL/MSi9bW1G7Uoidt3GXXWDmXrWt70vIXlLIxr8XV0Mu/rPbauGgWE+ZSYEfvdM5sP+FNF7vQ5de+Fkvzg5Z3tTfR+O1W+d7+vM4="
- TWINE_USERNAME=Leonardo.Uieda
- COVERAGE=false
- CHECK=false
- BUILD_DOCS=false
- DEPLOY_DOCS=false
- DEPLOY_PYPI=false
Expand All @@ -35,6 +36,7 @@ matrix:
env:
- PYTHON=3.6
- COVERAGE=true
- CHECK=true
- BUILD_DOCS=true
- DEPLOY_DOCS=true
- DEPLOY_PYPI=true
Expand Down Expand Up @@ -69,9 +71,10 @@ install:
- pip install dist/*

script:
# Check code for PEP8 style and lint for code quality
- make pep8
- make lint
# Check code for style and lint for code quality
- if [ "$CHECK" == "true" ]; then
make check;
fi
# Run the test suite
- if [ "$COVERAGE" == "true" ]; then
make coverage;
Expand Down
30 changes: 19 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Contributing Guidelines

First off, thank you for considering contributing to GMT/Python!
It is a community-driven project, so it's people like you that make it useful
and successful.
First off, thank you for considering contributing to GMT/Python! It is a
community-driven project, so it's people like you that make it useful and successful.

We love contributions from community members, just like you!
There are many ways to contribute:
Expand All @@ -12,10 +11,9 @@ There are many ways to contribute:
* Improvements to the documentation
* Writing code which can be incorporated into project for everyone to use

If you get stuck at
any point you can create an
[issue on GitHub](https://github.com/GenericMappingTools/gmt-python/issues)
or contact us at one of the other channels mentioned below.
If you get stuck at any point you can create an [issue on
GitHub](https://github.com/GenericMappingTools/gmt-python/issues) or contact us at one
of the other channels mentioned below.

For more information on contributing to open source projects,
[GitHub's own guide](https://guides.github.com/activities/contributing-to-open-source/)
Expand Down Expand Up @@ -124,6 +122,9 @@ Activate it by running:

source activate gmt-python


## Automation

The `Makefile` provides rules for installing, running the tests and coverage
analysis, running linters, etc.
If you don't want to use `make`, see the [Makefile](Makefile) and copy the
Expand All @@ -143,8 +144,16 @@ and the coverage analysis using:

make coverage

To check your code for PEP8 style and common errors (runs `flake8` and
`pylint`):
We use [Black](https://github.com/ambv/black) to format the code so we don't have to
think about it. You don't have to worry about formatting the code yourself. Before
committing, run the following to automatically format your code:

make format

Don't worry if you forget to do it. Our continuous integration systems will warn us and
you can make a new commit with the formatted code.

To check your code for style and common errors (runs `black` and `pylint`):

make check

Expand Down Expand Up @@ -183,8 +192,7 @@ quickly:
for documentation.

Pull requests will automatically have tests run by TravisCI.
This includes running both the unit tests as well as the `flake8` and `pylint`
code linters.
This includes running both the unit tests as well as `black` and `pylint`.
Github will show the status of these checks on the pull request.
Try to get them all passing (green).
If you have any trouble, leave a comment asking for help.
Expand Down
17 changes: 8 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
TESTDIR=tmp-test-dir-with-unique-name
PYTEST_ARGS=--doctest-modules -v --pyargs
PYTEST_COV_ARGS=--cov-config=../.coveragerc --cov-report=term-missing
CHECK_FILES=gmt setup.py

help:
@echo "Commands:"
@echo ""
@echo " develop install in editable mode"
@echo " test run the test suite (including doctests)"
@echo " check run all code quality checks (pep8, linter)"
@echo " pep8 check for PEP8 style compliance"
@echo " lint run static analysis using pylint"
@echo " check run code quality checks (black and pylint)"
@echo " format run black to automatically format the code"
@echo " coverage calculate test coverage"
@echo " clean clean up build and generated files"
@echo ""
Expand All @@ -34,13 +34,12 @@ coverage:
cp $(TESTDIR)/.coverage* .
rm -r $(TESTDIR)

pep8:
flake8 gmt setup.py
format:
black $(CHECK_FILES)

lint:
pylint gmt setup.py

check: pep8 lint
check:
black --check $(CHECK_FILES)
pylint $(CHECK_FILES)

clean:
find . -name "*.pyc" -exec rm -v {} \;
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
- pytest-cov
- pytest-mpl
- coverage
- flake8
- black
- pylint
- sphinx
- sphinx_rtd_theme
Expand Down
28 changes: 14 additions & 14 deletions gmt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@


# Get the version number through versioneer
__version__ = _get_versions()['version']
__commit__ = _get_versions()['full-revisionid']
__version__ = _get_versions()["version"]
__commit__ = _get_versions()["full-revisionid"]

# Start our global modern mode session
_begin()
Expand All @@ -43,15 +43,15 @@ def print_libgmt_info():

columns = shutil.get_terminal_size().columns
title = "Currently loaded libgmt"
left = (columns - len(title) - 2)//2
right = left + (columns - (2*left + len(title) + 2))
header = ' '.join(['='*left, title, '='*right])
left = (columns - len(title) - 2) // 2
right = left + (columns - (2 * left + len(title) + 2))
header = " ".join(["=" * left, title, "=" * right])

with LibGMT() as lib:
lines = [header]
for key in sorted(lib.info):
lines.append('{}: {}'.format(key, lib.info[key]))
print('\n'.join(lines))
lines.append("{}: {}".format(key, lib.info[key]))
print("\n".join(lines))


def test(doctest=True, verbose=True, coverage=False, figures=True):
Expand Down Expand Up @@ -91,15 +91,15 @@ def test(doctest=True, verbose=True, coverage=False, figures=True):

args = []
if verbose:
args.append('-vv')
args.append("-vv")
if coverage:
args.append('--cov=gmt')
args.append('--cov-report=term-missing')
args.append("--cov=gmt")
args.append("--cov-report=term-missing")
if doctest:
args.append('--doctest-modules')
args.append("--doctest-modules")
if figures:
args.append('--mpl')
args.append('--pyargs')
args.append('gmt')
args.append("--mpl")
args.append("--pyargs")
args.append("gmt")
status = pytest.main(args)
assert status == 0, "Some tests have failed."
Loading