Skip to content

Commit b8aa01f

Browse files
authored
Add pre-commit hooks (#71)
* add precommit hooks * update .git-blame-ignore-revs * update pre-commit workflow * update CHANGELOG
1 parent 366a860 commit b8aa01f

14 files changed

+794
-543
lines changed

.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: 4 additions & 0 deletions
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+
9c1fb5bd9b946c2eaaf1ea882e789efcccf66b53

.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/[email protected]
8888
with:
8989
access_token: ${{ github.token }}
90-
90+
9191
- uses: actions/[email protected]
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/[email protected]
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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/[email protected]
17+
18+
- name: Set up python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.12'
22+
23+
- name: Set up pip packages
24+
uses: BSFishy/pip-action@v1
25+
with:
26+
packages: |
27+
codespell
28+
pylint
29+
30+
- name: Set up clang-format
31+
run: |
32+
sudo apt-get install -y clang-format-14
33+
sudo unlink /usr/bin/clang-format
34+
sudo ln -s /usr/bin/clang-format-14 /usr/bin/clang-format
35+
clang-format --version
36+
37+
- name: Run pre-commit checks
38+
uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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/pre-commit/pygrep-hooks
19+
rev: v1.10.0
20+
hooks:
21+
- id: python-check-blanket-noqa
22+
- id: python-check-blanket-type-ignore
23+
- id: python-check-mock-methods
24+
- id: python-no-eval
25+
- id: python-no-log-warn
26+
- id: python-use-type-annotations
27+
- id: rst-backticks
28+
- id: rst-directive-colons
29+
- id: rst-inline-touching-normal
30+
- id: text-unicode-replacement-char
31+
32+
- repo: https://github.com/codespell-project/codespell
33+
rev: v2.4.1
34+
hooks:
35+
- id: codespell
36+
additional_dependencies:
37+
- tomli
38+
39+
- repo: https://github.com/psf/black
40+
rev: 25.1.0
41+
hooks:
42+
- id: black
43+
exclude: "_vendored/conv_template.py"
44+
45+
- repo: https://github.com/pocc/pre-commit-hooks
46+
rev: v1.3.5
47+
hooks:
48+
- id: clang-format
49+
args: ["-i"]
50+
51+
- repo: https://github.com/MarcoGorelli/cython-lint
52+
rev: v0.16.6
53+
hooks:
54+
- id: cython-lint
55+
- id: double-quote-cython-strings
56+
57+
- repo: https://github.com/pycqa/flake8
58+
rev: 7.1.2
59+
hooks:
60+
- id: flake8
61+
args: ["--config=.flake8"]
62+
additional_dependencies:
63+
- flake8-docstrings==1.7.0
64+
- flake8-bugbear==24.4.26
65+
66+
- repo: https://github.com/pycqa/isort
67+
rev: 6.0.1
68+
hooks:
69+
- id: isort
70+
name: isort (python)
71+
- id: isort
72+
name: isort (cython)
73+
types: [cython]
74+
- id: isort
75+
name: isort (pyi)
76+
types: [pyi]
77+
78+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
79+
rev: v2.14.0
80+
hooks:
81+
- id: pretty-format-toml
82+
args: [--autofix]
83+
84+
- repo: local
85+
hooks:
86+
- id: pylint
87+
name: pylint
88+
entry: pylint
89+
language: system
90+
types: [python]
91+
require_serial: true
92+
args:
93+
[
94+
"-rn", # Only display messages
95+
"-sn", # Don't display the score
96+
"--errors-only",
97+
"--disable=import-error",
98+
]
99+
100+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
101+
rev: 3.0.0
102+
hooks:
103+
- id: shellcheck

CHANGELOG.md

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,51 @@
1-
`mkl-service` changelog
2-
=======================
1+
# changelog
2+
All notable changes to this project will be documented in this file.
33

4-
[dev] (MM/DD/YY)
5-
================
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
Migrated from `setup.py` to `pyproject.toml`
7+
## [dev] (MM/DD/YY)
88

9-
Added support for python 3.13
9+
### Added
10+
* Added support for python 3.13 [gh-72](github.com/IntelPython/mkl-service/pull/72)
1011

11-
2.3.0
12-
=====
12+
### Changed
13+
* Migrated from `setup.py` to `pyproject.toml` [gh-66](github.com/IntelPython/mkl-service/pull/66)
14+
15+
16+
## [2.3.0]
1317

1418
Fixed CI to actually execute tests. Populated CBWR constants to match MKL headers.
1519

1620
Added tests checking that `cbwr_set` and `cbwr_get` round-trip.
1721

18-
2.2.0
19-
=====
22+
## [2.2.0]
2023

21-
Closed issues #8, #7 and #5.
24+
Closed issues #8, #7 and #5.
2225

2326
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)).
2427

2528
Extended `mkl.cbwrt_get()` to mean `mkl.cbwr('all')`.
2629

27-
2.1.0
28-
=====
30+
## [2.1.0]
2931

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

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

34-
2.0.2
35-
=====
36+
## [2.0.2]
3637

3738
Correction to `setup.py` to not require Cython at the installation time.
3839

39-
2.0.1
40-
=====
40+
## [2.0.1]
4141

4242
Re-release, with some changes necessary for public CI builds to work.
4343

44-
2.0.0
45-
=====
44+
## [2.0.0]
4645

4746
Work-around for VS 9.0 not having `inline` keyword, allowing the package to build on Windows for Python 2.7
4847

49-
2.0.0
50-
=====
48+
## [2.0.0]
5149

5250
Rerelease of `mkl-service` package with version bumped to 2.0.0 to avoid version clash with `mkl-service` package from Anaconda.
5351

@@ -57,7 +55,6 @@ Loading the package with `import mkl` initializes Intel(R) MKL library to use LP
5755

5856
The choice of threading layer can be controlled with environment variable `MKL_THREADING_LAYER`. However the unset variable is interpreted differently that in Intel(R) MKL itself. If `mkl-service` detects that Gnu OpenMP has been loaded in Python space, the threading layer of Intle(R) MKL will be set to Gnu OpenMP, instead of Intel(R) OpenMP.
5957

60-
1.0.0
61-
=====
58+
## [1.0.0]
6259

6360
Initial release of `mkl-service` package.

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))

0 commit comments

Comments
 (0)