Skip to content

Commit 227c8c0

Browse files
committed
Cleanup repo + prepare precommit
1 parent 9dff30b commit 227c8c0

File tree

8 files changed

+128
-25
lines changed

8 files changed

+128
-25
lines changed

.github/workflows/pytest.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ jobs:
1919
- name: Install dependencies
2020
run: |
2121
python -m pip install --upgrade pip
22-
pip install flake8 'pytest~=6.1.1' 'pytest-cov==2.10.1' 'pytest-mpl==0.12'
2322
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
23+
if [ -f test_requirements.txt ]; then pip install -r test_requirements.txt; fi
2424
- name: Lint with flake8
2525
run: |
2626
# stop the build if there are Python syntax errors or undefined names

.pre-commit-config.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- repo: https://github.com/ambv/black
2+
rev: 19.10b0
3+
hooks:
4+
- id: black
5+
language_version: python3.7
6+
- repo: https://github.com/timothycrosley/isort
7+
rev: '5.5.3'
8+
hooks:
9+
- id: isort
10+
- repo: https://gitlab.com/pycqa/flake8
11+
rev: '3.8.1'
12+
hooks:
13+
- id: flake8
14+
- repo: https://github.com/ikamensh/flynt
15+
rev: '0.52'
16+
hooks:
17+
- id: flynt

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include Readme.md LICENSE

dev_requirements.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
flake8==3.8.3
2+
flake8-black==0.2.1
3+
flake8-bugbear==20.11.1
4+
pytest~=6.1.1
5+
pytest-cov==2.10.1
6+
pytest-mpl==0.12

labellines/core.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from datetime import datetime
33
from math import atan2, degrees
44

5-
import matplotlib.pyplot as plt
65
import numpy as np
76
from matplotlib.container import ErrorbarContainer
87
from matplotlib.dates import DateConverter, date2num, num2date
@@ -21,8 +20,8 @@ def labelLine(line, x, label=None, align=True, drop_label=False, **kwargs):
2120
label : string, optional
2221
The label to set. This is inferred from the line by default
2322
drop_label : bool, optional
24-
If True, the label is consumed by the function so that subsequent calls to e.g. legend
25-
do not use it anymore.
23+
If True, the label is consumed by the function so that subsequent
24+
calls to e.g. legend do not use it anymore.
2625
kwargs : dict, optional
2726
Optional arguments passed to ax.text
2827
"""
@@ -40,8 +39,9 @@ def labelLine(line, x, label=None, align=True, drop_label=False, **kwargs):
4039
xa = min(xdata)
4140
xb = max(xdata)
4241
else:
43-
for i, (xa, xb) in enumerate(zip(xdata[:-1], xdata[1:])):
42+
for imatch, (xa, xb) in enumerate(zip(xdata[:-1], xdata[1:])):
4443
if min(xa, xb) <= x <= max(xa, xb):
44+
i = imatch
4545
break
4646
else:
4747
raise Exception("x label location is outside data range!")
@@ -126,8 +126,8 @@ def labelLines(
126126
The location of the labels. If a tuple, the labels will be
127127
evenly spaced between xfirst and xlast (in the axis units).
128128
drop_label : bool, optional
129-
If True, the label is consumed by the function so that subsequent calls to e.g. legend
130-
do not use it anymore.
129+
If True, the label is consumed by the function so that subsequent
130+
calls to e.g. legend do not use it anymore.
131131
shrink_factor : double, optional
132132
Relative distance from the edges to place closest labels. Defaults to 0.05.
133133
kwargs : dict, optional

pyproject.toml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[build-system]
2+
# See https://github.com/scipy/scipy/pull/10431 for the AIX issue.
3+
requires = [
4+
"setuptools>=19.6",
5+
"wheel"
6+
]
7+
8+
# To be kept consistent with "Code Style" section in CONTRIBUTING.rst
9+
[tool.black]
10+
line-length = 88
11+
target-version = ['py36', 'py37', 'py38']
12+
include = '\.pyi?$'
13+
exclude = '''
14+
/(
15+
\.eggs
16+
| \.git
17+
| \.hg
18+
| \.mypy_cache
19+
| \.tox
20+
| \.venv
21+
| build
22+
| dist
23+
)/
24+
'''
25+
26+
27+
# To be kept consistent with "Import Formatting" section in CONTRIBUTING.rst
28+
[tool.isort]
29+
profile = "black"
30+
combine_as_imports = true
31+
skip = []
32+
known_third_party = [
33+
"IPython",
34+
"nose",
35+
"numpy",
36+
"sympy",
37+
"matplotlib",
38+
"git",
39+
"yaml",
40+
"dateutil",
41+
"requests",
42+
"coverage",
43+
"pytest",
44+
"pyx",
45+
]
46+
known_first_party = ["labellines"]
47+
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]

setup.cfg

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[egg_info]
2+
#tag_build = .dev
3+
#tag_svn_revision = 1
4+
5+
[flake8]
6+
# Copied from the yt-project
7+
max-line-length=88
8+
exclude = doc,
9+
benchmarks,
10+
*/api.py, # avoid spurious "unused import"
11+
yt/convenience.py, # avoid spurious "unused import"
12+
*/__init__.py, # avoid spurious "unused import"
13+
*/__config__.py, # autogenerated
14+
yt/extern, # vendored libraries
15+
yt/units, # wrapper around unyt, avoid spurious "unused import"
16+
yt/frontends/stream/sample_data, # autogenerated
17+
18+
# individual files
19+
yt/visualization/_mpl_imports.py,
20+
yt/utilities/fits_image.py,
21+
yt/utilities/lodgeit.py,
22+
yt/mods.py,
23+
yt/visualization/_colormap_data.py,
24+
25+
ignore = E203, # Whitespace before ':' (black compatibility)
26+
E231, # Missing whitespace after ',', ';', or ':'
27+
E266, # Too many leading '#' for block comment
28+
E302, # Expected 2 blank lines, found 0
29+
E306, # Expected 1 blank line before a nested definition
30+
E741, # Do not use variables named 'I', 'O', or 'l'
31+
W503, # Line break occurred before a binary operator (black compatibility)
32+
W605, # Invalid escape sequence 'x'
33+
B302, # this is a python 3 compatibility warning, not relevant since don't support python 2 anymore
34+
35+
jobs=8

setup.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
# -*- coding: utf-8 -*-
22

3-
from setuptools import setup, find_packages
3+
from setuptools import find_packages, setup
44

5-
with open('Readme.md') as file:
5+
with open("Readme.md") as file:
66
long_description = file.read()
77

8-
with open('LICENSE') as f:
8+
with open("LICENSE") as f:
99
license = f.read()
1010

1111
setup(
12-
name='matplotlib-label-lines',
13-
version='0.3.8',
14-
description='Label lines in matplotlib.',
15-
long_description = long_description,
16-
long_description_content_type='text/markdown',
17-
author='Corentin Cadiou',
18-
author_email='[email protected]',
19-
url='https://github.com/cphyc/matplotlib-label-lines',
20-
license='MIT',
21-
packages=find_packages(exclude=('tests', 'docs')),
22-
install_requires=[
23-
'numpy',
24-
'matplotlib'
25-
],
26-
include_package_data=True
12+
name="matplotlib-label-lines",
13+
version="0.3.8",
14+
description="Label lines in matplotlib.",
15+
long_description=long_description,
16+
long_description_content_type="text/markdown",
17+
author="Corentin Cadiou",
18+
author_email="[email protected]",
19+
url="https://github.com/cphyc/matplotlib-label-lines",
20+
license="MIT",
21+
packages=find_packages(exclude=("tests", "docs")),
22+
install_requires=["numpy", "matplotlib"],
23+
include_package_data=True,
2724
)

0 commit comments

Comments
 (0)