Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pre-commit hooks #142

Merged
merged 3 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[flake8]
extend-ignore =
# whitespace before ':' (currently conflicts with black formatting):
E203,
# line too long (in docstrings):
E501,
# ‘from module import *’ used; unable to detect undefined names:
F403,
# doc line too long (105 > 80 characters):
W505,
# missing docstring in public module:
D100,
# missing docstring in public class:
D101,
# missing docstring in public method:
D102,
# missing docstring in public function:
D103,
# missing docstring in public package:
D104,
# missing docstring in magic method:
D105,
# missing docstring in __init__:
D107,
# no blank lines allowed after function docstring:
D202,
# 1 blank line required between summary line and description:
D205,
# first line should end with a period:
D400,
# first line should be in imperative mood:
D401,
# first line should not be the function's "signature":
D402,
# first word of the first line should be properly capitalized
D403,

per-file-ignores =
mkl_fft/__init__.py: E402, F401
mkl_fft/interfaces/__init__.py: F401
mkl_fft/interfaces/scipy_fft.py: F401
mkl_fft/interfaces/numpy_fft.py: F401

exclude = _vendored/conv_template.py

filename = *.py, *.pyx, *.pxi, *.pxd
max_line_length = 80
max-doc-length = 80
show-source = True

# Print detailed statistic if any issue detected
count = True
statistics = True
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs

# Add pre-commit hooks
2e1b33fcf6b7f0c7c9d7d5d7f55d2d0ba35f393a
5 changes: 2 additions & 3 deletions .github/workflows/conda-package-cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ env:
MODULE_NAME: mkl_fft
TEST_ENV_NAME: test_mkl_fft
VER_SCRIPT1: "import json; f = open('ver.json', 'r'); j = json.load(f); f.close(); d = j['mkl_fft'][0];"
VER_SCRIPT2: "print('='.join((d[s] for s in ('version', 'build'))))"
VER_SCRIPT2: "print('='.join((d[s] for s in ('version', 'build'))))"

jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -280,4 +280,3 @@ jobs:
shell: cmd /C CALL {0}
run: >-
conda activate ${{ env.TEST_ENV_NAME }} && python -m pytest -v -s --pyargs ${{ env.MODULE_NAME }}

3 changes: 1 addition & 2 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
MODULE_NAME: mkl_fft
TEST_ENV_NAME: test_mkl_fft
VER_SCRIPT1: "import json; f = open('ver.json', 'r'); j = json.load(f); f.close(); d = j['mkl_fft'][0];"
VER_SCRIPT2: "print('='.join((d[s] for s in ('version', 'build'))))"
VER_SCRIPT2: "print('='.join((d[s] for s in ('version', 'build'))))"

jobs:
build:
Expand Down Expand Up @@ -278,4 +278,3 @@ jobs:
shell: cmd /C CALL {0}
run: >-
conda activate ${{ env.TEST_ENV_NAME }} && python -m pytest -v -s --pyargs ${{ env.MODULE_NAME }}

33 changes: 33 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

permissions: read-all

jobs:
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo
uses: actions/[email protected]

- name: Set up python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- uses: BSFishy/pip-action@v1
with:
packages: |
pylint

- name: Version of clang-format
run: |
clang-format --version

- name: Run pre-commit checks
uses: pre-commit/[email protected]
76 changes: 76 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-toml
- id: debug-statements
- id: destroyed-symlinks
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
exclude: "_vendored/conv_template.py"

- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: ["-i"]

- repo: https://github.com/pycqa/flake8
rev: 7.1.2
hooks:
- id: flake8
args: ["--config=.flake8"]
additional_dependencies:
- flake8-docstrings==1.7.0
- flake8-bugbear==24.4.26

- repo: https://github.com/pycqa/isort
rev: 6.0.1
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
- id: isort
name: isort (pyi)
types: [pyi]

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.14.0
hooks:
- id: pretty-format-toml
args: [--autofix]

- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
require_serial: true
args:
[
"-rn", # Only display messages
"-sn", # Don't display the score
"--errors-only",
"--disable=import-error",
]

- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: shellcheck
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Fix for issue #29.
1.0.7
=====
Improved exception message raised if MKL is signalling an error. The message now includes MKL's own description of the exception.
This partially improves #24.
This partially improves #24.

Improved argument validation for ND transforms aligning with scipy 1.2.0

Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Security Policy
Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation.
Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation.

## Reporting a Vulnerability
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).
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).
2 changes: 1 addition & 1 deletion _vendored/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

File `conv_template.py` is copied from NumPy's numpy/distutils folder, since
`numpy.distutils` is absent from the installation layout starting with
Python 3.12
Python 3.12
3 changes: 1 addition & 2 deletions conda-recipe-cf/build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/bin/bash -x

if [ `uname` == Darwin ]; then
if [ "$(uname)" == Darwin ]; then
export MACOSX_DEPLOYMENT_TARGET=10.9
fi

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

3 changes: 1 addition & 2 deletions conda-recipe/build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/bin/bash -x

if [ `uname` == Darwin ]; then
if [ "$(uname)" == Darwin ]; then
export MACOSX_DEPLOYMENT_TARGET=10.9
fi

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

41 changes: 36 additions & 5 deletions mkl_fft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,45 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import mkl_fft.interfaces

from . import _init_helper
from ._pydfti import (fft, ifft, fft2, ifft2, fftn, ifftn, rfftpack, irfftpack,
rfft, irfft, rfft2, irfft2, rfftn, irfftn)

# pylint: disable=no-name-in-module
from ._pydfti import (
fft,
fft2,
fftn,
ifft,
ifft2,
ifftn,
irfft,
irfft2,
irfftn,
irfftpack,
rfft,
rfft2,
rfftn,
rfftpack,
)
from ._version import __version__
import mkl_fft.interfaces

__all__ = ['fft', 'ifft', 'fft2', 'ifft2', 'fftn', 'ifftn', 'rfftpack', 'irfftpack'
'rfft', 'irfft', 'rfft2', 'irfft2', 'rfftn', 'irfftn','interfaces']
__all__ = [
"fft",
"ifft",
"fft2",
"ifft2",
"fftn",
"ifftn",
"rfftpack",
"irfftpack",
"rfft",
"irfft",
"rfft2",
"irfft2",
"rfftn",
"irfftn",
"interfaces",
]

del _init_helper
21 changes: 14 additions & 7 deletions mkl_fft/_float_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@

import numpy as np

__all__ = ['__upcast_float16_array', '__downcast_float128_array', '__supported_array_or_not_implemented']
__all__ = [
"__upcast_float16_array",
"__downcast_float128_array",
"__supported_array_or_not_implemented",
]


def __upcast_float16_array(x):
"""
Used in _scipy_fft to upcast float16 to float32,
instead of float64, as mkl_fft would do"""
Used in _scipy_fft to upcast float16 to float32,
instead of float64, as mkl_fft would do
"""
if hasattr(x, "dtype"):
xdt = x.dtype
if xdt == np.half:
Expand All @@ -53,8 +59,9 @@ def __upcast_float16_array(x):

def __downcast_float128_array(x):
"""
Used in _numpy_fft to unsafely downcast float128/complex256 to
complex128, instead of raising an error"""
Used in _numpy_fft to unsafely downcast float128/complex256 to
complex128, instead of raising an error
"""
if hasattr(x, "dtype"):
xdt = x.dtype
if xdt == np.longdouble and not xdt == np.float64:
Expand All @@ -79,9 +86,9 @@ def __supported_array_or_not_implemented(x):
"""
__x = np.asarray(x)
black_list = [np.half]
if hasattr(np, 'float128'):
if hasattr(np, "float128"):
black_list.append(np.float128)
if hasattr(np, 'complex256'):
if hasattr(np, "complex256"):
black_list.append(np.complex256)
if __x.dtype in black_list:
return NotImplemented
Expand Down
Loading
Loading