Skip to content

Commit 97fc4f9

Browse files
authored
Modernize: use pyproject.toml for more things, add pre-commit; remove versioneer (#67)
* Modernize: use pyproject.toml for more things, add pre-commit; remove versioneer - Move metadata and config to `pyproject.toml` (and flake8 config to `.flake8`) - Use `setuptools-git-versioning` instead of `versioneer.py` - Add `.pre-commit-config.yaml` for git pre-commit hooks - Add GitHub Action to run pre-commit hooks to check linting
1 parent 86cb2f1 commit 97fc4f9

15 files changed

+227
-2937
lines changed

.flake8

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[flake8]
2+
max-line-length = 100
3+
inline-quotes = "
4+
extend-ignore =
5+
E203,
6+
# E203 whitespace before ':' (to be compatible with black)
7+
per-file-ignores =
8+
suitesparse_graphblas/io/binary.py:C408

.gitattributes

-1
This file was deleted.

.github/workflows/lint.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint via pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches-ignore:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
pre-commit:
14+
name: pre-commit-hooks
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-python@v4
19+
with:
20+
python-version: "3.10"
21+
- uses: pre-commit/[email protected]

.github/workflows/test.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
steps:
2424
- name: Checkout
2525
uses: actions/checkout@v3
26+
with:
27+
fetch-depth: 0
2628
- name: Conda
2729
uses: conda-incubator/setup-miniconda@v2
2830
with:
@@ -57,18 +59,13 @@ jobs:
5759
popd
5860
- name: Build
5961
run: |
60-
python setup.py build_ext --inplace
61-
python setup.py develop
62+
pip install -e . --no-deps
6263
- name: Test
6364
env:
6465
CYTHON_COVERAGE: true
6566
run: |
6667
coverage run --branch -m pytest
6768
coverage run -a --branch suitesparse_graphblas/tests/test_initialize.py
68-
- name: Lint
69-
run: |
70-
black *py suitesparse_graphblas --check --diff
71-
flake8 *py suitesparse_graphblas
7269
- name: create_headers.py check
7370
if: (! contains(matrix.os, 'windows'))
7471
run: |

.pre-commit-config.yaml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# https://pre-commit.com/
2+
#
3+
# Before first use: `pre-commit install`
4+
# To run: `pre-commit run --all-files`
5+
# To update: `pre-commit autoupdate`
6+
# - &flake8_dependencies below needs updated manually
7+
fail_fast: true
8+
default_language_version:
9+
python: python3
10+
repos:
11+
- repo: https://github.com/pre-commit/pre-commit-hooks
12+
rev: v4.4.0
13+
hooks:
14+
- id: check-added-large-files
15+
- id: check-ast
16+
- id: check-toml
17+
- id: check-yaml
18+
- id: debug-statements
19+
- id: end-of-file-fixer
20+
- id: mixed-line-ending
21+
# - id: trailing-whitespace
22+
- repo: https://github.com/abravalheri/validate-pyproject
23+
rev: v0.12.1
24+
hooks:
25+
- id: validate-pyproject
26+
name: Validate pyproject.toml
27+
- repo: https://github.com/myint/autoflake
28+
rev: v2.0.1
29+
hooks:
30+
- id: autoflake
31+
args: [--in-place]
32+
- repo: https://github.com/pycqa/isort
33+
rev: 5.12.0
34+
hooks:
35+
- id: isort
36+
- repo: https://github.com/asottile/pyupgrade
37+
rev: v3.3.1
38+
hooks:
39+
- id: pyupgrade
40+
args: [--py38-plus]
41+
# - repo: https://github.com/MarcoGorelli/auto-walrus
42+
# rev: v0.2.2
43+
# hooks:
44+
# - id: auto-walrus
45+
# args: [--line-length, "100"]
46+
- repo: https://github.com/psf/black
47+
rev: 23.1.0
48+
hooks:
49+
- id: black
50+
# - id: black-jupyter
51+
- repo: https://github.com/PyCQA/flake8
52+
rev: 6.0.0
53+
hooks:
54+
- id: flake8
55+
additional_dependencies: &flake8_dependencies
56+
# These versions need updated manually
57+
- flake8==6.0.0
58+
- flake8-comprehensions==3.10.1
59+
- flake8-bugbear==23.1.20
60+
# - flake8-simplify==0.19.3
61+
- repo: https://github.com/asottile/yesqa
62+
rev: v1.4.0
63+
hooks:
64+
- id: yesqa
65+
additional_dependencies: *flake8_dependencies
66+
- repo: https://github.com/pre-commit/pre-commit-hooks
67+
rev: v4.4.0
68+
hooks:
69+
- id: no-commit-to-branch # no commit directly to main

MANIFEST.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ include suitesparse_graphblas/*.pxd
55
include suitesparse_graphblas/*.pyx
66
include suitesparse_graphblas/*.c
77
include suitesparse_graphblas/*.h
8-
include versioneer.py
9-
include suitesparse_graphblas/_version.py
8+
include suitesparse_graphblas/tests/*.py

pyproject.toml

+102-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,106 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "numpy>=1.19", "cython"]
2+
build-backend = "setuptools.build_meta"
3+
requires = [
4+
"setuptools >=64",
5+
"setuptools-git-versioning",
6+
"wheel",
7+
"cffi",
8+
"cython",
9+
"oldest-supported-numpy",
10+
]
11+
12+
[project]
13+
name = "suitesparse-graphblas"
14+
dynamic = ["version"]
15+
description = "SuiteSparse:GraphBLAS Python bindings."
16+
readme = "README.md"
17+
requires-python = ">=3.8"
18+
license = {file = "LICENSE"}
19+
authors = [
20+
{name = "Erik Welch"},
21+
{name = "Jim Kitchen"},
22+
{name = "Michel Pelletier"},
23+
]
24+
maintainers = [
25+
{name = "Erik Welch", email = "[email protected]"},
26+
{name = "Jim Kitchen", email = "[email protected]"},
27+
{name = "Michel Pelletier", email = "[email protected]"},
28+
]
29+
classifiers = [
30+
"Development Status :: 4 - Beta",
31+
"License :: OSI Approved :: Apache Software License",
32+
"Operating System :: MacOS :: MacOS X",
33+
"Operating System :: POSIX :: Linux",
34+
"Operating System :: Microsoft :: Windows",
35+
"Programming Language :: Python",
36+
"Programming Language :: Python :: 3",
37+
"Programming Language :: Python :: 3.8",
38+
"Programming Language :: Python :: 3.9",
39+
"Programming Language :: Python :: 3.10",
40+
"Programming Language :: Python :: 3.11",
41+
"Programming Language :: Python :: 3 :: Only",
42+
"Intended Audience :: Science/Research",
43+
"Topic :: Scientific/Engineering",
44+
"Topic :: Scientific/Engineering :: Mathematics",
45+
]
46+
dependencies = [
47+
# These are super-old; can/should we update them?
48+
"cffi>=1.0.0",
49+
"numpy>=1.19",
50+
]
51+
[project.urls]
52+
homepage = "https://github.com/GraphBLAS/python-suitesparse-graphblas"
53+
repository = "https://github.com/GraphBLAS/python-suitesparse-graphblas"
54+
changelog = "https://github.com/GraphBLAS/python-suitesparse-graphblas/releases"
55+
56+
[project.optional-dependencies]
57+
test = [
58+
"pytest",
59+
]
60+
61+
[tool.setuptools]
62+
packages = [
63+
'suitesparse_graphblas',
64+
# 'suitesparse_graphblas.tests',
65+
'suitesparse_graphblas.io',
66+
]
67+
68+
[tool.setuptools-git-versioning]
69+
enabled = true
70+
dev_template = "{tag}+{ccount}.g{sha}"
71+
dirty_template = "{tag}+{ccount}.g{sha}.dirty"
372

473
[tool.black]
574
line-length = 100
75+
target-version = ["py38", "py39", "py310", "py311"]
76+
77+
[tool.isort]
78+
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
79+
profile = "black"
80+
skip_gitignore = true
81+
float_to_top = true
82+
default_section = "THIRDPARTY"
83+
known_first_party = "suitesparse_graphblas"
84+
line_length = 100
85+
skip_glob = ["*.pxd", "*.pyx"]
86+
87+
[tool.coverage.run]
88+
branch = true
89+
source = ["suitesparse_graphblas"]
90+
omit = []
91+
plugins = ["Cython.Coverage"]
92+
93+
[tool.coverage.report]
94+
ignore_errors = false
95+
precision = 1
96+
fail_under = 0
97+
skip_covered = true
98+
skip_empty = true
99+
exclude_lines = [
100+
"pragma: no cover",
101+
"raise AssertionError",
102+
"raise NotImplementedError",
103+
]
104+
105+
[tool.pytest]
106+
testpaths = ["suitesparse_graphblas/tests"]

setup.cfg

-45
This file was deleted.

setup.py

+1-48
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
# Twiddle Dee (switch this between Dee and Dum to add meaningless git commits)
21
import os
32
import sys
43
from glob import glob
54

65
import numpy as np
7-
from setuptools import Extension, find_packages, setup
8-
9-
import versioneer
6+
from setuptools import Extension, setup
107

118
try:
129
from Cython.Build import cythonize
@@ -16,8 +13,6 @@
1613
except ImportError:
1714
use_cython = False
1815

19-
20-
is_win = sys.platform.startswith("win")
2116
define_macros = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
2217

2318
if use_cython:
@@ -51,49 +46,7 @@
5146
if use_cython:
5247
ext_modules = cythonize(ext_modules, include_path=include_dirs)
5348

54-
with open("README.md") as f:
55-
long_description = f.read()
56-
57-
package_data = {"suitesparse_graphblas": ["*.pyx", "*.pxd", "*.c", "*.h"]}
58-
if is_win:
59-
package_data["suitesparse_graphblas"].append("*.dll")
60-
6149
setup(
62-
name="suitesparse-graphblas",
63-
version=versioneer.get_version(),
64-
cmdclass=versioneer.get_cmdclass(),
65-
description="SuiteSparse:GraphBLAS Python bindings.",
66-
long_description=long_description,
67-
long_description_content_type="text/markdown",
68-
packages=find_packages(),
69-
author="Michel Pelletier, James Kitchen, Erik Welch",
70-
71-
url="https://github.com/GraphBLAS/python-suitesparse-graphblas",
7250
ext_modules=ext_modules,
7351
cffi_modules=["suitesparse_graphblas/build.py:ffibuilder"],
74-
python_requires=">=3.8",
75-
install_requires=["cffi>=1.0.0", "numpy>=1.19"],
76-
setup_requires=["cffi>=1.0.0", "pytest-runner"],
77-
tests_require=["pytest"],
78-
license="Apache License 2.0",
79-
package_data=package_data,
80-
include_package_data=True,
81-
classifiers=[
82-
"Development Status :: 4 - Beta",
83-
"License :: OSI Approved :: Apache Software License",
84-
"Operating System :: MacOS :: MacOS X",
85-
"Operating System :: POSIX :: Linux",
86-
"Operating System :: Microsoft :: Windows",
87-
"Programming Language :: Python",
88-
"Programming Language :: Python :: 3",
89-
"Programming Language :: Python :: 3.8",
90-
"Programming Language :: Python :: 3.9",
91-
"Programming Language :: Python :: 3.10",
92-
"Programming Language :: Python :: 3.11",
93-
"Programming Language :: Python :: 3 :: Only",
94-
"Intended Audience :: Science/Research",
95-
"Topic :: Scientific/Engineering",
96-
"Topic :: Scientific/Engineering :: Mathematics",
97-
],
98-
zip_safe=False,
9952
)

0 commit comments

Comments
 (0)