Skip to content

Commit

Permalink
Add git pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw committed Apr 16, 2022
1 parent c4642b0 commit 9ea1c17
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 91 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ jobs:
activate-environment: graphblas
- name: Update env
run: |
conda install -c conda-forge pytest coverage 'black>=20.8b1' flake8 coveralls pytest-randomly
conda install -c conda-forge pytest coverage 'black>=20.8b1' flake8 \
coveralls pytest-randomly flake8-comprehensions flake8-bugbear
- name: Style Checks
run: |
flake8
Expand Down
56 changes: 56 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# https://pre-commit.com/
#
# Before first use: `pre-commit install`
# To run: `pre-commit run --all-files`
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-added-large-files
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args: [--in-place]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
language_version: python3
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
language_version: python3
args: [--target-version=py38]
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: &flake8_dependencies
- flake8==4.0.1
- flake8-comprehensions==3.8.0
- flake8-bugbear==22.3.23
- repo: https://github.com/asottile/yesqa
rev: v1.3.0
hooks:
- id: yesqa
additional_dependencies: *flake8_dependencies
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
types_or: [python, rst, markdown]
files: ^(graphblas|docs)/
args: ["--ignore-words-list=coo,ba"]
# Maybe: black-jupyter, blacken-docs, blackdoc mypy, velin
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
[![Tests](https://github.com/metagraph-dev/python-graphblas/workflows/Tests/badge.svg?branch=main)](https://github.com/metagraph-dev/python-graphblas/actions)
[![Docs](https://readthedocs.org/projects/python-graphblas/badge/?version=latest)](https://python-graphblas.readthedocs.io/en/latest/)
[![Coverage](https://coveralls.io/repos/metagraph-dev/python-graphblas/badge.svg?branch=main)](https://coveralls.io/r/metagraph-dev/python-graphblas)
[![Code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/metagraph-dev/python-graphblas/HEAD?filepath=notebooks%2FIntro%20to%20GraphBLAS%20%2B%20SSSP%20example.ipynb)

Python wrapper around GraphBLAS
Expand Down
4 changes: 2 additions & 2 deletions graphblas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from importlib.abc import MetaPathFinder as _MetaPathFinder

from . import mask # noqa
from ._version import get_versions # noqa
from ._version import get_versions


class replace:
Expand Down Expand Up @@ -110,7 +110,7 @@ def init(backend="suitesparse", blocking=False):
def _init(backend_arg, blocking, automatic=False):
global _init_params, backend, lib, ffi

passed_params = dict(backend=backend_arg, blocking=blocking, automatic=automatic)
passed_params = {"backend": backend_arg, "blocking": blocking, "automatic": automatic}
if _init_params is not None:
if blocking is None:
passed_params["blocking"] = _init_params["blocking"]
Expand Down
2 changes: 2 additions & 0 deletions graphblas/_ss/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3834,6 +3834,7 @@ def compactify_rowwise(
- smallest : take the smallest values (if tied, may take any)
- largest : take the largest values (if tied, may take any)
- random : take values randomly with equal probability and without replacement
Chosen values may not be ordered randomly
reverse : bool, default False
Reverse the values in each row when True
asindex : bool, default False
Expand Down Expand Up @@ -3867,6 +3868,7 @@ def compactify_columnwise(
- smallest : take the smallest values (if tied, may take any)
- largest : take the largest values (if tied, may take any)
- random : take values randomly with equal probability and without replacement
Chosen values may not be ordered randomly
reverse : bool, default False
Reverse the values in each column when True
asindex : bool, default False
Expand Down
1 change: 1 addition & 0 deletions graphblas/_ss/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,7 @@ def selectk(self, how, k, *, name=None):
----------
how : str
- "random": choose k elements with equal probability
Chosen values may not be ordered randomly
- "first": choose the first k elements
- "last": choose the last k elements
- "largest": choose the k largest elements. If tied, any may be chosen.
Expand Down
6 changes: 3 additions & 3 deletions graphblas/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
"""
rootdirs = []

for i in range(3):
for _ in range(3):
dirname = os.path.basename(root)
if dirname.startswith(parentdir_prefix):
return {
Expand Down Expand Up @@ -284,7 +284,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
# TAG-NUM-gHEX
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
if not mo:
# unparseable. Maybe git-describe is misbehaving?
# unparsable. Maybe git-describe is misbehaving?
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
return pieces

Expand Down Expand Up @@ -511,7 +511,7 @@ def get_versions():
# versionfile_source is the relative path from the top of the source
# tree (where the .git directory might live) to this file. Invert
# this to find the root from __file__.
for i in cfg.versionfile_source.split("/"):
for _ in cfg.versionfile_source.split("/"):
root = os.path.dirname(root)
except NameError:
return {
Expand Down
2 changes: 1 addition & 1 deletion graphblas/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def lookup(
mask_complement=False,
mask_structure=False,
transpose_first=False,
transpose_second=False
transpose_second=False,
):
key = (
output_replace,
Expand Down
6 changes: 3 additions & 3 deletions graphblas/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def mmread(source, *, dup_op=None, name=None):
https://math.nist.gov/MatrixMarket/formats.html
"""
try:
from scipy.io import mmread # noqa
from scipy.sparse import coo_matrix # noqa
from scipy.io import mmread
from scipy.sparse import coo_matrix
except ImportError: # pragma: no cover
raise ImportError("scipy is required to read Matrix Market files") from None
array = mmread(source)
Expand All @@ -180,7 +180,7 @@ def mmwrite(target, matrix, *, comment="", field=None, precision=None, symmetry=
https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.mmwrite.html
"""
try:
from scipy.io import mmwrite # noqa
from scipy.io import mmwrite
except ImportError: # pragma: no cover
raise ImportError("scipy is required to write Matrix Market files") from None

Expand Down
4 changes: 2 additions & 2 deletions graphblas/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ def _build(cls, name, func, *, anonymous=False, is_udt=False):
return_types = {}
nt = numba.types
if not is_udt:
for type_, sample_val in _sample_values.items():
for type_ in _sample_values:
sig = (type_.numba_type,)
try:
unary_udf.compile(sig)
Expand Down Expand Up @@ -1391,7 +1391,7 @@ def _build(cls, name, func, *, is_udt=False, anonymous=False):
return_types = {}
nt = numba.types
if not is_udt:
for type_, sample_val in _sample_values.items():
for type_ in _sample_values:
sig = (type_.numba_type, type_.numba_type)
try:
binary_udf.compile(sig)
Expand Down
2 changes: 1 addition & 1 deletion graphblas/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _scalar_index(name):
class Scalar(BaseType):
"""
GraphBLAS Scalar
Pseudo-object for GraphBLAS functions which accumlate into a scalar type
Pseudo-object for GraphBLAS functions which accumulate into a scalar type
"""

__slots__ = "_empty", "_is_cscalar"
Expand Down
8 changes: 4 additions & 4 deletions graphblas/tests/test_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def test_unify_dtypes():

def test_dtype_bad_comparison():
with pytest.raises(TypeError):
dtypes.BOOL == object()
assert dtypes.BOOL == object()
with pytest.raises(TypeError):
object() != dtypes.BOOL
assert object() != dtypes.BOOL


def test_dtypes_match_numpy():
Expand All @@ -137,7 +137,7 @@ def test_pickle():
assert val.np_type == val2.np_type
assert val.name == val2.name
else:
val == val2
assert val == val2
s = pickle.dumps(dtypes._INDEX)
val2 = pickle.loads(s)
assert dtypes._INDEX == val2
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_lt_dtypes():
assert sorted(all_dtypes) == expected
assert dtypes.BOOL < "FP32"
with pytest.raises(TypeError):
dtypes.BOOL < 5
assert dtypes.BOOL < 5


def test_bad_register():
Expand Down
2 changes: 1 addition & 1 deletion graphblas/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3247,7 +3247,7 @@ def test_mxv_repr_html(A, v):

@pytest.mark.skipif("not pd")
def test_matrix_reduce_columns_repr_html(A):
# This is implmeneted using the transpose of A, so make sure we're oriented correctly!
# This is implemented using the transpose of A, so make sure we're oriented correctly!
html_printer(A.reduce_columnwise(), "A.reduce_columnwise()")
assert repr_html(A.reduce_columnwise()) == (
'<div><details class="gb-expr-details"><summary class="gb-expr-summary"><b><tt>gb.VectorExpression:</tt></b><div>\n'
Expand Down
26 changes: 13 additions & 13 deletions graphblas/tests/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1784,9 +1784,9 @@ def test_import_export(A, do_iso, methods):
assert B5b.ss.is_iso is do_iso
else:
# B5b == [A, A]
B5b.nvals == 2 * A.nvals
B5b.nrows == A.nrows
B5b.ncols == 2 * A.ncols
assert B5b.nvals == 2 * A.nvals
assert B5b.nrows == 2 * A.nrows
assert B5b.ncols == A.ncols
else:
A5.ss.pack_any(**d)
assert A5.isequal(A)
Expand Down Expand Up @@ -2201,26 +2201,26 @@ def test_no_bool_or_eq(A):
with pytest.raises(TypeError, match="not defined"):
bool(A)
# with pytest.raises(TypeError, match="not defined"):
A == A
assert (A == A) is not None
with pytest.raises(TypeError, match="not defined"):
bool(A.S)
with pytest.raises(TypeError, match="not defined"):
A.S == A.S
assert A.S == A.S
expr = A.ewise_mult(A)
with pytest.raises(TypeError, match="not defined"):
bool(expr)
with pytest.raises(TypeError, match="not enabled"):
expr == expr
assert expr == expr
assigner = A[1, 2]()
with pytest.raises(TypeError, match="not defined"):
bool(assigner)
with pytest.raises(TypeError, match="not defined"):
assigner == assigner
assert assigner == assigner
updater = A()
with pytest.raises(TypeError, match="not defined"):
bool(updater)
with pytest.raises(TypeError, match="not defined"):
updater == updater
assert updater == updater


@autocompute
Expand All @@ -2241,7 +2241,7 @@ def test_bool_eq_on_scalar_expressions(A):

expr = A[0, [1, 1]]
# with pytest.raises(TypeError, match="not defined"):
expr == expr # Now okay
assert (expr == expr) is not None # Now okay
with pytest.raises(TypeError, match="not defined"):
bool(expr)
with pytest.raises(TypeError):
Expand All @@ -2255,7 +2255,7 @@ def test_bool_eq_on_scalar_expressions(A):
def test_bool_eq_on_scalar_expressions_no_auto(A):
expr = A.reduce_scalar()
with pytest.raises(TypeError, match="autocompute"):
expr == 47
assert expr == 47
with pytest.raises(TypeError, match="autocompute"):
bool(expr)
with pytest.raises(TypeError, match="autocompute"):
Expand All @@ -2270,11 +2270,11 @@ def test_contains(A):
assert (1, 0) not in A

with pytest.raises(TypeError):
1 in A
assert 1 in A
with pytest.raises(TypeError):
(1,) in A.T
assert (1,) in A.T
with pytest.raises(TypeError, match="Invalid index"):
(1, [1, 2]) in A
assert (1, [1, 2]) in A


def test_iter(A):
Expand Down
4 changes: 2 additions & 2 deletions graphblas/tests/test_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,9 @@ def _udt_identity(val):
assert int in udt_identity
assert operator.get_typed_op(udt_identity, udt) is udt_identity[udt]
with pytest.raises(ValueError):
"badname" in binary.eq
assert "badname" in binary.eq
with pytest.raises(ValueError):
"badname" in udt_identity
assert "badname" in udt_identity

def _udt_getx(val):
return val["x"] # pragma: no cover
Expand Down

0 comments on commit 9ea1c17

Please sign in to comment.