Skip to content

Commit dce14dd

Browse files
committed
add pre-commit hooks to the project
1 parent e612350 commit dce14dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4707
-3184
lines changed

.flake8

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[flake8]
2+
extend-ignore =
3+
# whitespace before ':' (currently conflicts with black formatting):
4+
E203,
5+
# missing docstring in public module:
6+
D100,
7+
# missing docstring in public class:
8+
D101,
9+
# missing docstring in public method:
10+
D103,
11+
# missing docstring in public package:
12+
D104,
13+
# missing docstring in magic method:
14+
D105,
15+
# missing docstring in __init__:
16+
D107,
17+
# 1 blank line required between summary line and description:
18+
D205,
19+
# first line should end with a period:
20+
D400,
21+
# first line should be in imperative mood:
22+
D401,
23+
# first line should not be the function's "signature":
24+
D402,
25+
26+
per-file-ignores =
27+
mkl_random/__init__.py: F401
28+
mkl_random/interfaces/__init__.py: F401
29+
30+
filename = *.py, *.pyx, *.pxi, *.pxd
31+
max_line_length = 80
32+
max-doc-length = 80
33+
show-source = True
34+
35+
# Print detailed statistic if any issue detected
36+
count = True
37+
statistics = True

.github/workflows/build-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
run: |
5454
# Ensure that SYCL libraries are on LD_LIBRARY_PATH
5555
source /opt/intel/oneapi/setvars.sh
56-
pip install --no-deps --no-build-isolation -e . --verbose
56+
pip install --no-deps --no-build-isolation -e . --verbose
5757
python -c "import mkl_random; print(mkl_random.__version__)" || exit 1
5858
sphinx-build -M html docs/source docs/build
5959
mkdir -p ~/rendered_docs

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ jobs:
109109
- name: Install conda-build
110110
run: conda install conda-build
111111
- name: Setup MSVC
112-
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
112+
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
113113
- name: Build conda package
114114
run: conda build --no-test --python ${{ matrix.python }} --numpy ${{ matrix.numpy }} -c conda-forge --override-channels conda-recipe-cf
115115
- name: Upload artifact

.github/workflows/pre-commit.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
18+
- name: Set up python
19+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
20+
with:
21+
python-version: '3.13'
22+
23+
- name: Set up pip packages
24+
uses: BSFishy/pip-action@8f2d471d809dc20b6ada98c91910b6ae6243f318 # v1
25+
with:
26+
packages: |
27+
codespell
28+
pylint
29+
30+
- name: Run pre-commit checks
31+
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ __pycache__/
88
mkl_random/src/mklrand.c
99
mkl_random/mklrand.cpp
1010
mkl_random/mklrand.cpython*.so
11-

.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: v6.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+
args: ["-L", "nd,hart,elemente,wirth"]
37+
additional_dependencies:
38+
- tomli
39+
40+
- repo: https://github.com/psf/black
41+
rev: 26.1.0
42+
hooks:
43+
- id: black
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.19.0
53+
hooks:
54+
- id: cython-lint
55+
- id: double-quote-cython-strings
56+
57+
- repo: https://github.com/pycqa/flake8
58+
rev: 7.3.0
59+
hooks:
60+
- id: flake8
61+
args: ["--config=.flake8"]
62+
additional_dependencies:
63+
- flake8-docstrings==1.7.0
64+
- flake8-bugbear==25.11.29
65+
66+
- repo: https://github.com/pycqa/isort
67+
rev: 8.0.0
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.16.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

conda-recipe/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ read -r GLIBC_MAJOR GLIBC_MINOR <<<"$(conda list '^sysroot_linux-64$' \
1111
if [ -n "${WHEELS_OUTPUT_FOLDER}" ]; then
1212
$PYTHON -m pip wheel --no-build-isolation --no-deps .
1313
${PYTHON} -m wheel tags --remove --platform-tag "manylinux_${GLIBC_MAJOR}_${GLIBC_MINOR}_x86_64" mkl_random*.whl
14-
cp mkl_random*.whl ${WHEELS_OUTPUT_FOLDER}
14+
cp mkl_random*.whl "${WHEELS_OUTPUT_FOLDER}"
1515
else
1616
# Build conda package
1717
$PYTHON -m pip install --no-build-isolation --no-deps .

docs/source/conf.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
# -- Project information -----------------------------------------------------
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

9-
project = 'mkl_random'
10-
copyright = '2017-2025, Intel Corp.'
11-
author = 'Intel Corp.'
12-
release = '1.4.0dev1'
9+
project = "mkl_random"
10+
copyright = "2017-2025, Intel Corp."
11+
author = "Intel Corp."
12+
release = "1.4.0dev1"
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -26,16 +26,15 @@
2626
"sphinx.ext.viewcode",
2727
"sphinxcontrib.programoutput",
2828
# "sphinxcontrib.googleanalytics",
29-
'sphinx_design',
29+
"sphinx_design",
3030
]
3131

32-
templates_path = ['_templates']
32+
templates_path = ["_templates"]
3333
exclude_patterns = []
3434

3535

36-
3736
# -- Options for HTML output -------------------------------------------------
3837
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
3938

40-
html_theme = 'furo'
41-
html_static_path = ['_static']
39+
html_theme = "furo"
40+
html_static_path = ["_static"]

docs/source/how_to.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ the internal state of the pseudo-random number generators.
2323
# draw some numbers as if computation were to continue
2424
post_draw = rs.gamma(5, 1, size=100)
2525
26-
# restore random state, and continue from
26+
# restore random state, and continue from
2727
restored_rs = pickle.loads(saved)
2828
resumed_draw = restored_rs.gamma(5, 1, size=100)
29-
30-
# sample from restored stated is the same as sample
29+
30+
# sample from restored stated is the same as sample
3131
# from the original one
3232
assert np.array_equal(restored_rs, resumed_draw)
3333
@@ -47,14 +47,14 @@ indistinguishable from independent.
4747
.. py:method:: skipahead(nskips)
4848
:canonical: mkl_random.RandomState.skipahead
4949

50-
Advance the state of the generator using skip-ahead method, or raise :code:`ValueError`
51-
exception if not supported.
50+
Advance the state of the generator using skip-ahead method, or raise :code:`ValueError`
51+
exception if not supported.
5252

5353
The argument `nskips` must be a positive Python integer.
5454

55-
The method is supported for :ref:`"philox4x32x10" <philox4x32x10_brng>`, :ref:`"mrg32k3a" <mrg32k3a_brng>`,
55+
The method is supported for :ref:`"philox4x32x10" <philox4x32x10_brng>`, :ref:`"mrg32k3a" <mrg32k3a_brng>`,
5656
:ref:`"mcg31m1" <mcg31m1_brng>`, :ref:`"mcg59" <mcg59_brng>`, :ref:`"wh" <wh_brng>`,
57-
:ref:`"mt19937" <mt19937_brng>`, :ref:`"sfmt19937" <sfmt19937_brng>`, and :ref:`"ars5" <ars5_brng>`
57+
:ref:`"mt19937" <mt19937_brng>`, :ref:`"sfmt19937" <sfmt19937_brng>`, and :ref:`"ars5" <ars5_brng>`
5858
basic random number generators.
5959

6060
.. note::
@@ -68,20 +68,20 @@ indistinguishable from independent.
6868
Initialize the state of the generator using leap-frog method, or raise :code:`ValueError`
6969
exception if not supported.
7070

71-
The leap-frog method partitions state trajectory into :code:`nstream` interleaved non-overlapping
71+
The leap-frog method partitions state trajectory into :code:`nstream` interleaved non-overlapping
7272
sub-sequences, and argument :code:`k` identifies the subsequence.
7373

74-
The method is supported for :ref:`"mcg31m1" <mcg31m1_brng>`, :ref:`"mcg59" <mcg59_brng>`, and :ref:`"wh" <wh_brng>`
74+
The method is supported for :ref:`"mcg31m1" <mcg31m1_brng>`, :ref:`"mcg59" <mcg59_brng>`, and :ref:`"wh" <wh_brng>`
7575
basic pseudo-random number generators.
7676

7777
.. note::
78-
When using :meth:`leapfrog` or :meth:`skipahead` methods one must remember that parallel tasks partition
79-
generators period and choose a generator with sufficiently long period to avoid cycling over the period
78+
When using :meth:`leapfrog` or :meth:`skipahead` methods one must remember that parallel tasks partition
79+
generators period and choose a generator with sufficiently long period to avoid cycling over the period
8080
more than once, as doing so also breaks the assumption of statistical independence and may compromise
8181
correctness of the simulation.
8282

8383
:mod:`mkl_random` also provides two families of basic pseudo-random number generators, :ref:`"mt2203" <mt2203_brng>` and
84-
:ref:`"wh" <wh_brng>`, with property that members from particular family, initialized equally, produce streams of
84+
:ref:`"wh" <wh_brng>`, with property that members from particular family, initialized equally, produce streams of
8585
randomness stasistically indistunguishable from independent. To use such families in parallel computation, assign
8686
difference family generators to different parallel workers and sample those assigned generators in each parallel worker.
87-
Please refer to "examples/" folder in the `GitHub repo <https://github.com/IntelPython/mkl_random>`_ for more details.
87+
Please refer to "examples/" folder in the `GitHub repo <https://github.com/IntelPython/mkl_random>`_ for more details.

docs/source/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
:mod:`mkl_random`: random numbers fast
22
======================================
33

4-
:mod:`mkl_random` is Python package exposing :ref:`pseudo-random <pseudorandom_vs_truerandom>` and
5-
:ref:`non-deterministic <pseudorandom_vs_truerandom>`
6-
random number generators and sampling from continuous and discrete distribution available in
7-
Intel(R) oneAPI Math Kernel Library
4+
:mod:`mkl_random` is Python package exposing :ref:`pseudo-random <pseudorandom_vs_truerandom>` and
5+
:ref:`non-deterministic <pseudorandom_vs_truerandom>`
6+
random number generators and sampling from continuous and discrete distribution available in
7+
Intel(R) oneAPI Math Kernel Library
88
(`oneMKL <https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html>`_).
99

1010
.. grid:: 2

0 commit comments

Comments
 (0)