Skip to content

Commit bee4cf6

Browse files
authored
add pre-commit format (#142)
* add pre-commit hooks * add pre-commit workflow * add .git-blame-ignore-revs file
1 parent 87ef5fb commit bee4cf6

28 files changed

+1232
-672
lines changed

.flake8

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[flake8]
2+
extend-ignore =
3+
# whitespace before ':' (currently conflicts with black formatting):
4+
E203,
5+
# line too long (in docstrings):
6+
E501,
7+
# ‘from module import *’ used; unable to detect undefined names:
8+
F403,
9+
# doc line too long (105 > 80 characters):
10+
W505,
11+
# missing docstring in public module:
12+
D100,
13+
# missing docstring in public class:
14+
D101,
15+
# missing docstring in public method:
16+
D102,
17+
# missing docstring in public function:
18+
D103,
19+
# missing docstring in public package:
20+
D104,
21+
# missing docstring in magic method:
22+
D105,
23+
# missing docstring in __init__:
24+
D107,
25+
# no blank lines allowed after function docstring:
26+
D202,
27+
# 1 blank line required between summary line and description:
28+
D205,
29+
# first line should end with a period:
30+
D400,
31+
# first line should be in imperative mood:
32+
D401,
33+
# first line should not be the function's "signature":
34+
D402,
35+
# first word of the first line should be properly capitalized
36+
D403,
37+
38+
per-file-ignores =
39+
mkl_fft/__init__.py: E402, F401
40+
mkl_fft/interfaces/__init__.py: F401
41+
mkl_fft/interfaces/scipy_fft.py: F401
42+
mkl_fft/interfaces/numpy_fft.py: F401
43+
44+
exclude = _vendored/conv_template.py
45+
46+
filename = *.py, *.pyx, *.pxi, *.pxd
47+
max_line_length = 80
48+
max-doc-length = 80
49+
show-source = True
50+
51+
# Print detailed statistic if any issue detected
52+
count = True
53+
statistics = True

.git-blame-ignore-revs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs
2+
3+
# Add pre-commit hooks
4+
2e1b33fcf6b7f0c7c9d7d5d7f55d2d0ba35f393a

.github/workflows/conda-package-cf.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ env:
1313
MODULE_NAME: mkl_fft
1414
TEST_ENV_NAME: test_mkl_fft
1515
VER_SCRIPT1: "import json; f = open('ver.json', 'r'); j = json.load(f); f.close(); d = j['mkl_fft'][0];"
16-
VER_SCRIPT2: "print('='.join((d[s] for s in ('version', 'build'))))"
17-
16+
VER_SCRIPT2: "print('='.join((d[s] for s in ('version', 'build'))))"
17+
1818
jobs:
1919
build:
2020
runs-on: ubuntu-latest
@@ -280,4 +280,3 @@ jobs:
280280
shell: cmd /C CALL {0}
281281
run: >-
282282
conda activate ${{ env.TEST_ENV_NAME }} && python -m pytest -v -s --pyargs ${{ env.MODULE_NAME }}
283-

.github/workflows/conda-package.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313
MODULE_NAME: mkl_fft
1414
TEST_ENV_NAME: test_mkl_fft
1515
VER_SCRIPT1: "import json; f = open('ver.json', 'r'); j = json.load(f); f.close(); d = j['mkl_fft'][0];"
16-
VER_SCRIPT2: "print('='.join((d[s] for s in ('version', 'build'))))"
16+
VER_SCRIPT2: "print('='.join((d[s] for s in ('version', 'build'))))"
1717

1818
jobs:
1919
build:
@@ -278,4 +278,3 @@ jobs:
278278
shell: cmd /C CALL {0}
279279
run: >-
280280
conda activate ${{ env.TEST_ENV_NAME }} && python -m pytest -v -s --pyargs ${{ env.MODULE_NAME }}
281-

.github/workflows/pre-commit.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master]
7+
8+
permissions: read-all
9+
10+
jobs:
11+
pre-commit:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 30
14+
steps:
15+
- name: Checkout repo
16+
uses: actions/checkout@v4.2.2
17+
18+
- name: Set up python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.12'
22+
23+
- uses: BSFishy/pip-action@v1
24+
with:
25+
packages: |
26+
pylint
27+
28+
- name: Version of clang-format
29+
run: |
30+
clang-format --version
31+
32+
- name: Run pre-commit checks
33+
uses: pre-commit/action@v3.0.1

.pre-commit-config.yaml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-ast
6+
- id: check-builtin-literals
7+
- id: check-case-conflict
8+
- id: check-executables-have-shebangs
9+
- id: check-merge-conflict
10+
- id: check-toml
11+
- id: debug-statements
12+
- id: destroyed-symlinks
13+
- id: end-of-file-fixer
14+
- id: fix-byte-order-marker
15+
- id: mixed-line-ending
16+
- id: trailing-whitespace
17+
18+
- repo: https://github.com/psf/black
19+
rev: 25.1.0
20+
hooks:
21+
- id: black
22+
exclude: "_vendored/conv_template.py"
23+
24+
- repo: https://github.com/pocc/pre-commit-hooks
25+
rev: v1.3.5
26+
hooks:
27+
- id: clang-format
28+
args: ["-i"]
29+
30+
- repo: https://github.com/pycqa/flake8
31+
rev: 7.1.2
32+
hooks:
33+
- id: flake8
34+
args: ["--config=.flake8"]
35+
additional_dependencies:
36+
- flake8-docstrings==1.7.0
37+
- flake8-bugbear==24.4.26
38+
39+
- repo: https://github.com/pycqa/isort
40+
rev: 6.0.1
41+
hooks:
42+
- id: isort
43+
name: isort (python)
44+
- id: isort
45+
name: isort (cython)
46+
types: [cython]
47+
- id: isort
48+
name: isort (pyi)
49+
types: [pyi]
50+
51+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
52+
rev: v2.14.0
53+
hooks:
54+
- id: pretty-format-toml
55+
args: [--autofix]
56+
57+
- repo: local
58+
hooks:
59+
- id: pylint
60+
name: pylint
61+
entry: pylint
62+
language: system
63+
types: [python]
64+
require_serial: true
65+
args:
66+
[
67+
"-rn", # Only display messages
68+
"-sn", # Don't display the score
69+
"--errors-only",
70+
"--disable=import-error",
71+
]
72+
73+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
74+
rev: 3.0.0
75+
hooks:
76+
- id: shellcheck

CHANGES.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Fix for issue #29.
125125
1.0.7
126126
=====
127127
Improved exception message raised if MKL is signalling an error. The message now includes MKL's own description of the exception.
128-
This partially improves #24.
128+
This partially improves #24.
129129

130130
Improved argument validation for ND transforms aligning with scipy 1.2.0
131131

SECURITY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Security Policy
2-
Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation.
2+
Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation.
33

44
## Reporting a Vulnerability
5-
Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html).
5+
Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html).

_vendored/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
File `conv_template.py` is copied from NumPy's numpy/distutils folder, since
44
`numpy.distutils` is absent from the installation layout starting with
5-
Python 3.12
5+
Python 3.12

conda-recipe-cf/build.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/bin/bash -x
22

3-
if [ `uname` == Darwin ]; then
3+
if [ "$(uname)" == Darwin ]; then
44
export MACOSX_DEPLOYMENT_TARGET=10.9
55
fi
66

77
export MKLROOT=$PREFIX
88
export CFLAGS="-I$PREFIX/include $CFLAGS"
99
$PYTHON -m pip install --no-build-isolation --no-deps .
10-

conda-recipe/build.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/bin/bash -x
22

3-
if [ `uname` == Darwin ]; then
3+
if [ "$(uname)" == Darwin ]; then
44
export MACOSX_DEPLOYMENT_TARGET=10.9
55
fi
66

77
export MKLROOT=$PREFIX
88
export CFLAGS="-I$PREFIX/include $CFLAGS"
99
$PYTHON -m pip install --no-build-isolation --no-deps .
10-

mkl_fft/__init__.py

+36-5
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,45 @@
2424
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2525
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

27+
import mkl_fft.interfaces
28+
2729
from . import _init_helper
28-
from ._pydfti import (fft, ifft, fft2, ifft2, fftn, ifftn, rfftpack, irfftpack,
29-
rfft, irfft, rfft2, irfft2, rfftn, irfftn)
3030

31+
# pylint: disable=no-name-in-module
32+
from ._pydfti import (
33+
fft,
34+
fft2,
35+
fftn,
36+
ifft,
37+
ifft2,
38+
ifftn,
39+
irfft,
40+
irfft2,
41+
irfftn,
42+
irfftpack,
43+
rfft,
44+
rfft2,
45+
rfftn,
46+
rfftpack,
47+
)
3148
from ._version import __version__
32-
import mkl_fft.interfaces
3349

34-
__all__ = ['fft', 'ifft', 'fft2', 'ifft2', 'fftn', 'ifftn', 'rfftpack', 'irfftpack'
35-
'rfft', 'irfft', 'rfft2', 'irfft2', 'rfftn', 'irfftn','interfaces']
50+
__all__ = [
51+
"fft",
52+
"ifft",
53+
"fft2",
54+
"ifft2",
55+
"fftn",
56+
"ifftn",
57+
"rfftpack",
58+
"irfftpack",
59+
"rfft",
60+
"irfft",
61+
"rfft2",
62+
"irfft2",
63+
"rfftn",
64+
"irfftn",
65+
"interfaces",
66+
]
3667

3768
del _init_helper

mkl_fft/_float_utils.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@
2626

2727
import numpy as np
2828

29-
__all__ = ['__upcast_float16_array', '__downcast_float128_array', '__supported_array_or_not_implemented']
29+
__all__ = [
30+
"__upcast_float16_array",
31+
"__downcast_float128_array",
32+
"__supported_array_or_not_implemented",
33+
]
34+
3035

3136
def __upcast_float16_array(x):
3237
"""
33-
Used in _scipy_fft to upcast float16 to float32,
34-
instead of float64, as mkl_fft would do"""
38+
Used in _scipy_fft to upcast float16 to float32,
39+
instead of float64, as mkl_fft would do
40+
"""
3541
if hasattr(x, "dtype"):
3642
xdt = x.dtype
3743
if xdt == np.half:
@@ -53,8 +59,9 @@ def __upcast_float16_array(x):
5359

5460
def __downcast_float128_array(x):
5561
"""
56-
Used in _numpy_fft to unsafely downcast float128/complex256 to
57-
complex128, instead of raising an error"""
62+
Used in _numpy_fft to unsafely downcast float128/complex256 to
63+
complex128, instead of raising an error
64+
"""
5865
if hasattr(x, "dtype"):
5966
xdt = x.dtype
6067
if xdt == np.longdouble and not xdt == np.float64:
@@ -79,9 +86,9 @@ def __supported_array_or_not_implemented(x):
7986
"""
8087
__x = np.asarray(x)
8188
black_list = [np.half]
82-
if hasattr(np, 'float128'):
89+
if hasattr(np, "float128"):
8390
black_list.append(np.float128)
84-
if hasattr(np, 'complex256'):
91+
if hasattr(np, "complex256"):
8592
black_list.append(np.complex256)
8693
if __x.dtype in black_list:
8794
return NotImplemented

0 commit comments

Comments
 (0)