Skip to content

Commit a9b3acf

Browse files
author
Vahid Tavanashad
committed
add precommit hooks
1 parent 2da024a commit a9b3acf

14 files changed

Lines changed: 747 additions & 520 deletions

.flake8

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
36+
per-file-ignores =
37+
mkl/__init__.py: E402, F401, F405
38+
39+
filename = *.py, *.pyx, *.pxi, *.pxd
40+
max_line_length = 80
41+
max-doc-length = 80
42+
show-source = True
43+
44+
# Print detailed statistic if any issue detected
45+
count = True
46+
statistics = True

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs
2+
3+
# Add pre-commit hooks

.github/workflows/build-with-clang.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
export CFLAGS="${CFLAGS} -fno-fast-math"
7474
python setup.py develop
7575
76-
- name: Run mkl-service tests
76+
- name: Run mkl-service tests
7777
run: |
7878
source ${{ env.ONEAPI_ROOT }}/setvars.sh
7979
pytest -s -v --pyargs mkl

.github/workflows/conda-package.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
uses: styfle/cancel-workflow-action@0.12.1
8888
with:
8989
access_token: ${{ github.token }}
90-
90+
9191
- uses: actions/checkout@v4.1.7
9292
with:
9393
fetch-depth: 0
@@ -114,7 +114,7 @@ jobs:
114114

115115
- name: Build conda package
116116
run: conda build --no-test --python ${{ matrix.python }} -c https://software.repos.intel.com/python/conda -c conda-forge --override-channels conda-recipe
117-
117+
118118
- name: Upload artifact
119119
uses: actions/upload-artifact@v4.6.2
120120
with:
@@ -254,9 +254,9 @@ jobs:
254254
restore-keys: |
255255
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
256256
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
257-
257+
258258
# add intel-openmp as an explicit dependency
259-
# to avoid it being missed when package version is specified exactly
259+
# to avoid it being missed when package version is specified exactly
260260
- name: Install mkl-service
261261
shell: cmd
262262
run: |

.github/workflows/pre-commit.yml

Lines changed: 33 additions & 0 deletions
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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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/MarcoGorelli/cython-lint
31+
rev: v0.16.6
32+
hooks:
33+
- id: cython-lint
34+
- id: double-quote-cython-strings
35+
36+
- repo: https://github.com/pycqa/flake8
37+
rev: 7.1.2
38+
hooks:
39+
- id: flake8
40+
args: ["--config=.flake8"]
41+
additional_dependencies:
42+
- flake8-docstrings==1.7.0
43+
- flake8-bugbear==24.4.26
44+
45+
- repo: https://github.com/pycqa/isort
46+
rev: 6.0.1
47+
hooks:
48+
- id: isort
49+
name: isort (python)
50+
- id: isort
51+
name: isort (cython)
52+
types: [cython]
53+
- id: isort
54+
name: isort (pyi)
55+
types: [pyi]
56+
57+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
58+
rev: v2.14.0
59+
hooks:
60+
- id: pretty-format-toml
61+
args: [--autofix]
62+
63+
- repo: local
64+
hooks:
65+
- id: pylint
66+
name: pylint
67+
entry: pylint
68+
language: system
69+
types: [python]
70+
require_serial: true
71+
args:
72+
[
73+
"-rn", # Only display messages
74+
"-sn", # Don't display the score
75+
"--errors-only",
76+
"--disable=import-error",
77+
]
78+
79+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
80+
rev: 3.0.0
81+
hooks:
82+
- id: shellcheck

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Added tests checking that `cbwr_set` and `cbwr_get` round-trip.
1010
2.2.0
1111
=====
1212

13-
Closed issues #8, #7 and #5.
13+
Closed issues #8, #7 and #5.
1414

1515
Extended `mkl.cbwr_set` to recognize `'avx512_e1'`, `'avx512_mic_e1'`, as as strict conditional numerical reproducibility, supported via `'avx2,strict'`, `'avx512,strict'` (see [issue/8](http://github.com/IntelPython/mkl-service/issues/8)).
1616

@@ -21,7 +21,7 @@ Extended `mkl.cbwrt_get()` to mean `mkl.cbwr('all')`.
2121

2222
Change in setup script to not use `numpy.distutils` thus removing numpy as build-time dependency.
2323

24-
Change in conda-recipe to allow conda build to build the recipe, but ignoring run export on mkl-service coming from mkl-devel metadata.
24+
Change in conda-recipe to allow conda build to build the recipe, but ignoring run export on mkl-service coming from mkl-devel metadata.
2525

2626
2.0.2
2727
=====

examples/example.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,45 @@
2323
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2424
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525

26+
# pylint: disable=no-member
2627

27-
import mkl
2828
import re
2929

30+
import mkl
31+
3032

3133
def enable_best_instructions_set():
32-
for instructions_set in ['avx512', 'avx2', 'avx', 'sse4_2']:
33-
if mkl.enable_instructions(instructions_set) == 'success':
34+
for instructions_set in ["avx512", "avx2", "avx", "sse4_2"]:
35+
if mkl.enable_instructions(instructions_set) == "success":
3436
result = instructions_set
3537
break
3638
else:
37-
result = 'error'
39+
result = "error"
3840

3941
return result
4042

4143

4244
def is_max_supported_instructions_set(instructions_set):
4345
result = False
44-
if re.search(instructions_set.replace('4_2', '4.2'), mkl.get_version()['Processor'].decode(), re.IGNORECASE):
46+
if re.search(
47+
instructions_set.replace("4_2", "4.2"),
48+
mkl.get_version()["Processor"].decode(),
49+
re.IGNORECASE,
50+
):
4551
result = True
4652

4753
return result
4854

4955

50-
if __name__ == '__main__':
56+
if __name__ == "__main__":
5157
time_begin = mkl.dsecnd()
5258
print(mkl.get_version_string())
5359

5460
instructions_set = enable_best_instructions_set()
55-
print('Enable snstructions set: ' + str(instructions_set))
61+
print("Enable snstructions set: " + str(instructions_set))
5662

5763
is_max = is_max_supported_instructions_set(instructions_set)
58-
print('Is the best supported instructions set: ' + str(is_max))
64+
print("Is the best supported instructions set: " + str(is_max))
5965

6066
time_end = mkl.dsecnd()
61-
print('Execution time: ' + str(time_end - time_begin))
67+
print("Execution time: " + str(time_end - time_begin))

mkl/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@
2525

2626
import sys
2727

28-
class RTLD_for_MKL():
28+
29+
class RTLD_for_MKL:
2930
def __init__(self):
3031
self.saved_rtld = None
3132

3233
def __enter__(self):
3334
import ctypes
35+
3436
try:
3537
self.saved_rtld = sys.getdlopenflags()
36-
# python loads libraries with RTLD_LOCAL, but MKL requires RTLD_GLOBAL
37-
# pre-load MKL with RTLD_GLOBAL before loading the native extension
38+
# python loads libraries with RTLD_LOCAL, but MKL requires
39+
# RTLD_GLOBAL pre-load MKL with RTLD_GLOBAL before loading
40+
# the native extension
3841
sys.setdlopenflags(self.saved_rtld | ctypes.RTLD_GLOBAL)
3942
except AttributeError:
4043
pass
@@ -45,6 +48,7 @@ def __exit__(self, *args):
4548
sys.setdlopenflags(self.saved_rtld)
4649
self.saved_rtld = None
4750

51+
4852
with RTLD_for_MKL():
4953
from . import _mklinit
5054

0 commit comments

Comments
 (0)