Skip to content

Commit 78da51a

Browse files
committed
Merge branch 'pep8-cleanup'
2 parents 591dac7 + 6048389 commit 78da51a

File tree

13 files changed

+3975
-2911
lines changed

13 files changed

+3975
-2911
lines changed

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# See: https://pre-commit.com/hooks.html
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v2.2.3
5+
hooks:
6+
- id: double-quote-string-fixer
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-docstring-first
10+
- id: check-yaml
11+
- id: debug-statements
12+
- id: check-merge-conflict
13+
- id: no-commit-to-branch
14+
15+
- repo: https://github.com/pre-commit/pre-commit-hooks
16+
rev: v2.2.3
17+
hooks:
18+
- id: flake8
19+
args: ["--max-line-length=88", "--exclude=__init__.py"]

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ install:
3131
- python setup.py install --user
3232

3333
script:
34+
- flake8 proplot --ignore=W503,F401,F403
3435
- pushd docs
3536
- make html
3637
- popd
37-

HOWTOCONTRIBUTE.rst

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,35 @@ Preparing pull requests
9191
If you need some help with git, follow the
9292
`quick start guide <https://git.wiki.kernel.org/index.php/QuickStart>`__.
9393

94+
#. Install `pre-commit <https://pre-commit.com>`_ and its hook on the ``proplot`` repo
95+
96+
.. code-block:: bash
97+
98+
pip install --user pre-commit
99+
pre-commit install
100+
101+
Afterwards ``pre-commit`` will run whenever you commit. https://pre-commit.com/
102+
is a framework for managing and maintaining multi-language pre-commit hooks to
103+
ensure code-style and code formatting is consistent.
104+
105+
You can now edit your local working copy as necessary. Please follow
106+
PEP-8 naming conventions. When committing, ``pre-commit`` will modify the
107+
files as needed, or will generally be clear about what you need to do to
108+
pass the commit test.
109+
94110
#. If you intend to make changes / add examples to the ipython notebooks,
95111
you need to install and configure
96112
`nbstripout <https://github.com/kynan/nbstripout>`__ with
97113

98114
.. code-block:: bash
99115
100-
cd proplot
101-
pip install nbstripout
116+
pip install --user nbstripout
102117
git config --local include.path ../.gitconfig
103118
104119
This strips notebook cell output when files are staged, which reduces the
105120
repo storage size and lets us use
106121
`nbsphinx <https://nbsphinx.readthedocs.io/en/0.4.3/>`__
107-
to test each ``git push``, since ``nbsphinx`` must then re-run every cell.
122+
to test each ``git push``.
108123

109124
The ``git config`` command associates the filters declared in
110125
``proplot/.gitattributes`` with the operations described in ``proplot/.gitconfig``
@@ -118,7 +133,8 @@ Preparing pull requests
118133
pip install -e .
119134
120135
This way when you ``import proplot``, your
121-
local copy is used. Make sure matplotlib is already installed.
136+
local copy is used. You can print ``proplot.__file__`` to verify this.
137+
Make sure matplotlib is already installed.
122138

123139
#. Break your edits up into reasonably sized commits.
124140

@@ -140,11 +156,11 @@ Preparing pull requests
140156

141157
- The entry should be entered as:
142158

143-
.. code-block::
159+
.. code-block::
144160
145161
<description> (:pr:`<PR number>`) `<author name>`_
146162
147-
where ``<description>`` is the description of the PR related to the change, ``<PR number>`` is the pull request number, and ``<author name>`` is your first and last name.
163+
where ``<description>`` is the description of the PR related to the change, ``<PR number>`` is the pull request number, and ``<author name>`` is your first and last name.
148164

149165
- Add yourself to list of authors at the end of ``CHANGELOG.rst`` file if not there yet, in alphabetical order.
150166

__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

proplot/__init__.py

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
#!/usr/bin/env python3
2-
#------------------------------------------------------------------------------#
32
# Import everything into the top-level module namespace
4-
# Have sepearate files for various categories, so we don't end up with a
5-
# single enormous 12,000-line file
6-
#------------------------------------------------------------------------------#
7-
# Monkey patch warnings format for warnings issued by ProPlot, make sure to
8-
# detect if this is just a matplotlib warning traced back to ProPlot code
9-
# See: https://stackoverflow.com/a/2187390/4970632
10-
# For internal warning call signature: https://docs.python.org/3/library/warnings.html#warnings.showwarning
11-
# For default warning source code see: https://github.com/python/cpython/blob/master/Lib/warnings.py
3+
# Make sure to load styletools early so we can try to update TTFPATH before
4+
# the fontManager is loaded by other modules (requiring a rebuild)
5+
import os as _os
126
import warnings as _warnings
7+
import pkg_resources as _pkg
8+
from .utils import _benchmark
9+
with _benchmark('total time'):
10+
from .utils import *
11+
with _benchmark('styletools'):
12+
from .styletools import *
13+
with _benchmark('rctools'):
14+
from .rctools import *
15+
with _benchmark('axistools'):
16+
from .axistools import *
17+
with _benchmark('wrappers'):
18+
from .wrappers import *
19+
with _benchmark('projs'):
20+
from .projs import *
21+
with _benchmark('axes'):
22+
from .axes import *
23+
with _benchmark('subplots'):
24+
from .subplots import *
25+
26+
1327
def _warning_proplot(message, category, filename, lineno, line=None):
28+
"""
29+
Format for warnings issued by ProPlot. If this is
30+
just a matplotlib warning traced back to ProPlot code the *default*
31+
warning format is used.
32+
See the `internal warning call signature
33+
<https://docs.python.org/3/library/warnings.html#warnings.showwarning>`__
34+
and the `default warning source code
35+
<https://github.com/python/cpython/blob/master/Lib/warnings.py>`__.
36+
"""
1437
if line is None:
1538
try:
1639
import linecache
@@ -22,13 +45,17 @@ def _warning_proplot(message, category, filename, lineno, line=None):
2245
else:
2346
string = f'{filename}:{lineno}: {category.__name__}: {message}'
2447
if line is not None:
25-
string += ('\n' + line) # default behavior
26-
return (string + '\n') # must end in newline or not shown in IPython
48+
string += ('\n' + line) # default behavior
49+
return (string + '\n') # must end in newline or not shown in IPython
50+
51+
52+
# Apply monkeypatch
53+
# See: https://stackoverflow.com/a/2187390/4970632
2754
if _warnings.formatwarning is not _warning_proplot:
2855
_warnings.formatwarning = _warning_proplot
2956

57+
3058
# Initialize customization folders
31-
import os as _os
3259
_rc_folder = _os.path.join(_os.path.expanduser('~'), '.proplot')
3360
if not _os.path.isdir(_rc_folder):
3461
_os.mkdir(_rc_folder)
@@ -45,35 +72,15 @@ def _warning_proplot(message, category, filename, lineno, line=None):
4572
lines = ''.join(
4673
'# ' + line if line.strip() and line[0] != '#' else line
4774
for line in f.readlines()
48-
)
75+
)
4976
with open(_rc_file, 'x') as f:
50-
f.write('# User default settings\n'
51-
+ '# See https://proplot.readthedocs.io/en/latest/rctools.html\n'
52-
+ lines)
53-
54-
# Import stuff in reverse dependency order
55-
# Make sure to load styletools early so we can try to update TTFPATH before
56-
# the fontManager is loaded by other modules (requiring a rebuild)
57-
from .utils import _benchmark
58-
with _benchmark('total time'):
59-
from .utils import *
60-
with _benchmark('styletools'):
61-
from .styletools import *
62-
with _benchmark('rctools'):
63-
from .rctools import *
64-
with _benchmark('axistools'):
65-
from .axistools import *
66-
with _benchmark('wrappers'):
67-
from .wrappers import *
68-
with _benchmark('projs'):
69-
from .projs import *
70-
with _benchmark('axes'):
71-
from .axes import *
72-
with _benchmark('subplots'):
73-
from .subplots import *
77+
f.write(
78+
'# User default settings\n'
79+
'# See https://proplot.readthedocs.io/en/latest/rctools.html\n'
80+
+ lines
81+
)
7482

7583
# SCM versioning
76-
import pkg_resources as _pkg
7784
name = 'proplot'
7885
try:
7986
version = __version__ = _pkg.get_distribution(__name__).version

0 commit comments

Comments
 (0)