Skip to content

Commit

Permalink
Update pre-commit versions and run separate CI job for linting checks (
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknw authored Jan 30, 2023
1 parent 6eaab4c commit 140bea8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 28 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Lint via pre-commit

on:
pull_request:
push:
branches-ignore:
- main

permissions:
contents: read

jobs:
pre-commit:
name: pre-commit-hooks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: pre-commit/action@v3.0.0
13 changes: 4 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
run:
shell: bash -l {0}
strategy:
fail-fast: false
fail-fast: true
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.8", "3.9", "3.10"]
Expand All @@ -30,21 +30,16 @@ jobs:
activate-environment: testing
- name: Install dependencies
run: |
conda install -c conda-forge python-graphblas scipy pandas \
pytest-cov pytest-randomly black flake8-comprehensions flake8-bugbear
conda install -c conda-forge python-graphblas scipy pandas pytest-cov pytest-randomly
# matplotlib lxml pygraphviz pydot sympy # Extra networkx deps we don't need yet
pip install git+https://github.com/networkx/networkx.git@main --no-deps
pip install -e . --no-deps
- name: Style checks
run: |
flake8
black . --check --diff
- name: PyTest
run: |
python -c 'import sys, graphblas_algorithms; assert "networkx" not in sys.modules'
coverage run --branch -m pytest -v --check-structure
coverage run --branch -m pytest --color=yes -v --check-structure
coverage report
NETWORKX_GRAPH_CONVERT=graphblas pytest --pyargs networkx --cov --cov-append
NETWORKX_GRAPH_CONVERT=graphblas pytest --color=yes --pyargs networkx --cov --cov-append
coverage report
coverage xml
- name: Coverage
Expand Down
35 changes: 20 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
# To update: `pre-commit autoupdate`
# - &flake8_dependencies below needs updated manually
fail_fast: true
default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -17,40 +19,45 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.11
hooks:
- id: validate-pyproject
name: Validate pyproject.toml
- repo: https://github.com/myint/autoflake
rev: v1.7.7
rev: v2.0.0
hooks:
- id: autoflake
args: [--in-place]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
language_version: python3
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/MarcoGorelli/auto-walrus
rev: v0.2.1
rev: v0.2.2
hooks:
- id: auto-walrus
- id: auto-walrus
args: [--line-length, "100"]
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
language_version: python3
args: [--target-version=py38]
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: &flake8_dependencies
# These versions need updated manually
- flake8==5.0.4
- flake8==6.0.0
- flake8-comprehensions==3.10.1
- flake8-bugbear==22.10.27
- flake8-bugbear==23.1.20
- flake8-simplify==0.19.3
- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
Expand All @@ -62,9 +69,7 @@ repos:
- id: codespell
types_or: [python, rst, markdown]
files: ^(graphblas_algorithms|docs)/
# args: ["--ignore-words-list=coo,ba"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: no-commit-to-branch # no commit directly to main
# Maybe: black-jupyter, blacken-docs, blackdoc mypy, velin
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ requires = ["setuptools", "wheel"]

[tool.black]
line-length = 100
target-version = ["py38", "py39", "py310", "py311"]
10 changes: 7 additions & 3 deletions scripts/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,21 @@ def getfunction(functionname, backend):
return getattr(nx, functionname)


def main(dataname, backend, functionname, time=3.0, n=None, extra=None, display=True):
def getgraph(dataname, backend="graphblas", functionname=None):
filename = find_data(dataname)
is_symmetric = get_symmetry(filename) == "symmetric"
if not is_symmetric and functionname in undirected_only:
if not is_symmetric and functionname is not None and functionname in undirected_only:
# Should we automatically symmetrize?
raise ValueError(
f"Data {dataname!r} is not symmetric, but {functionname} only works on undirected"
)
if is_symmetric and functionname in directed_only:
is_symmetric = False # Make into directed graph
G = readfile(filename, is_symmetric, backend)
return readfile(filename, is_symmetric, backend)


def main(dataname, backend, functionname, time=3.0, n=None, extra=None, display=True):
G = getgraph(dataname, backend, functionname)
func = getfunction(functionname, backend)
benchstring = functioncall.get(functionname, "func(G)")
if extra is not None:
Expand Down
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ max-line-length = 100
inline-quotes = "
exclude =
versioneer.py,
graphblas_algorithms/_version.py,
graphblas_algorithms/*/tests/,
graphblas_algorithms/*/*/tests/,
build/
extend-ignore =
E203,
SIM105,
SIM401,
# E203 whitespace before ':' (to be compatible with black)
per-file-ignores =
__init__.py:F401,F403, # allow unused and star imports
test_*.py:F401,F403,
graphblas_algorithms/nxapi/exception.py:F401,
graphblas_algorithms/**/__init__.py:F401,F403
[isort]
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
Expand All @@ -26,7 +30,8 @@ default_section = THIRDPARTY
known_first_party = graphblas_algorithms
line_length = 100
skip =
graphblas_algorithms/nxapi/__init__.py
graphblas_algorithms/nxapi/__init__.py,
scripts/bench.py
[coverage:run]
source = graphblas_algorithms
Expand Down

0 comments on commit 140bea8

Please sign in to comment.