diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..5ef2b10 --- /dev/null +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fd5fd15..d22022e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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"] @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d11c621..862dfcd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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: @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 90ccf9c..57ff4a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,3 +3,4 @@ requires = ["setuptools", "wheel"] [tool.black] line-length = 100 +target-version = ["py38", "py39", "py310", "py311"] diff --git a/scripts/bench.py b/scripts/bench.py index 4221514..e67640b 100755 --- a/scripts/bench.py +++ b/scripts/bench.py @@ -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: diff --git a/setup.cfg b/setup.cfg index 38a76c1..c5a9664 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 @@ -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