Skip to content

Commit d9386da

Browse files
authored
ARROW-59 Set up flake8 config (#54)
1 parent 0e8648f commit d9386da

20 files changed

+55
-36
lines changed

.github/workflows/release-python.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
uses: actions/setup-python@v2
2323
with:
2424
python-version: ${{ matrix.python-version }}
25+
cache: 'pip'
26+
cache-dependency-path: '**/setup.cfg'
2527
- name: Build wheels
2628
working-directory: ./bindings/python
2729
shell: bash

.github/workflows/test-python.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
uses: actions/setup-python@v2
4242
with:
4343
python-version: ${{ matrix.python-version }}
44+
cache: 'pip'
45+
cache-dependency-path: '**/setup.cfg'
4446
- name: Start MongoDB on Linux
4547
if: ${{ startsWith(runner.os, 'Linux') }}
4648
uses: supercharge/[email protected]

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ repos:
3030
files: \.py$
3131
args: [--profile=black]
3232

33+
- repo: https://gitlab.com/pycqa/flake8
34+
rev: 4.0.1
35+
hooks:
36+
- id: flake8
37+
args: [--config=bindings/python/.flake8]
38+
types: [file]
39+
files: \.(py|pyx|pxd)$
40+
additional_dependencies: [
41+
'flake8-bugbear==20.1.4',
42+
'flake8-logging-format==0.6.0',
43+
'flake8-implicit-str-concat==0.2.0',
44+
]
45+
46+
3347
# We use the Python version instead of the original version which seems to require Docker
3448
# https://github.com/koalaman/shellcheck-precommit
3549
- repo: https://github.com/shellcheck-py/shellcheck-py

bindings/python/.flake8

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[flake8]
2+
max-line-length = 100
3+
enable-extensions = G
4+
extend-ignore =
5+
G200, G202,
6+
# black adds spaces around ':'
7+
E203,
8+
# E501 line too long (let black handle line length)
9+
E501
10+
per-file-ignores =
11+
# E227 missing whitespace around bitwise or shift operator
12+
# E225 missing whitespace around operator
13+
# E999 SyntaxError: invalid syntax
14+
bindings/python/pymongoarrow/*.pyx: E227,E225,E999
15+
bindings/python/pymongoarrow/*.pxd: E227,E225,E999

bindings/python/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ exclude THIRD-PARTY-NOTICES
77
exclude release.sh
88
exclude addtags.py
99
exclude benchmark.py
10+
exclude .flake8
1011

1112
graft pymongoarrow
1213

bindings/python/benchmark.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import pandas as pd
1111
import pyarrow
1212
import pymongo
13-
from bson import BSON, CodecOptions, Int64, ObjectId
14-
from bson.raw_bson import RawBSONDocument
13+
from bson import BSON, Int64, ObjectId
1514
from pymongoarrow.api import Schema, find_arrow_all, find_numpy_all, find_pandas_all
1615

1716
assert pymongo.has_c()
@@ -125,9 +124,9 @@ def to_numpy(use_large):
125124
@bench("conventional-to-pandas")
126125
def conventional_pandas(use_large):
127126
collection = db[collection_names[use_large]]
128-
dtype = dtypes[use_large]
127+
_ = dtypes[use_large]
129128
cursor = collection.find(projection={"_id": 0})
130-
data_frame = pd.DataFrame(list(cursor))
129+
_ = pd.DataFrame(list(cursor))
131130

132131

133132
@bench("pymongoarrow-to-pandas")

bindings/python/docs/source/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
13-
import os
1413
import os.path as p
1514

1615
# -- Project information -----------------------------------------------------

bindings/python/pymongoarrow/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import warnings
1616

1717
# We must import pyarrow before attempting to load the Cython module.
18-
import pyarrow
19-
from pymongoarrow.version import _MIN_LIBBSON_VERSION, __version__
18+
import pyarrow # noqa: F401
19+
from pymongoarrow.version import _MIN_LIBBSON_VERSION, __version__ # noqa: F401
2020

2121
try:
2222
from pkg_resources import parse_version as _parse_version

bindings/python/pymongoarrow/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def find_arrow_all(collection, query, *, schema, **kwargs):
5959
for opt in ("cursor_type",):
6060
if kwargs.pop(opt, None):
6161
warnings.warn(
62-
f"Ignoring option {opt!r} as it is not supported by " "PyMongoArrow",
62+
f"Ignoring option {opt!r} as it is not supported by PyMongoArrow",
6363
UserWarning,
6464
stacklevel=2,
6565
)
@@ -99,7 +99,7 @@ def aggregate_arrow_all(collection, pipeline, *, schema, **kwargs):
9999
for opt in ("batchSize", "useCursor"):
100100
if kwargs.pop(opt, None):
101101
warnings.warn(
102-
f"Ignoring option {opt!r} as it is not supported by " "PyMongoArrow",
102+
f"Ignoring option {opt!r} as it is not supported by PyMongoArrow",
103103
UserWarning,
104104
stacklevel=2,
105105
)

bindings/python/pymongoarrow/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""Exceptions raised by PyMongoArrow."""
1616

17-
from bson.errors import InvalidBSON
17+
from bson.errors import InvalidBSON # noqa: F401
1818

1919

2020
class PyMongoArrowError(Exception):

0 commit comments

Comments
 (0)