Skip to content

Commit a002bde

Browse files
authored
Add gitleaks and shellcheck to pre-commit configuration (#1689)
* Add gitleaks and shellcheck to pre-commit configuration * Pin gitleaks to the latest version * Use an array to build scikit-build arguments * Use an array to build wheel arguments
1 parent e7f7a7c commit a002bde

File tree

19 files changed

+1066
-1060
lines changed

19 files changed

+1066
-1060
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,11 @@ repos:
7171
hooks:
7272
- id: clang-format
7373
args: ["-i"]
74+
- repo: https://github.com/gitleaks/gitleaks
75+
rev: v8.18.2
76+
hooks:
77+
- id: gitleaks
78+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
79+
rev: 3.0.0
80+
hooks:
81+
- id: shellcheck

benchmarks/pytest_benchmark/README.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
# dpnp/benchmarks/pytest_benchmark/
2-
3-
## Prerequisites
4-
* pytest >= 6.1.1
5-
* pytest-benchmark >= 3.4.1
6-
7-
8-
## Running benchmark tests
9-
```bash
10-
pytest benchmarks/ --benchmark-json=results.json
11-
```
12-
Running tests and saving the current run into `STORAGE`, see [1]
13-
```bash
14-
pytest benchmarks/ --benchmark-json=results.json --benchmark-autosave
15-
```
16-
17-
## Creating `.csv` report
18-
```bash
19-
pytest-benchmark compare results.json --csv=results.csv --group-by='name'
20-
```
21-
22-
## Optional: creating histogram
23-
Note: make sure that `pytest-benchmark[histogram]` installed
24-
```bash
25-
# example
26-
pip install pytest-benchmark[histogram]
27-
pytest -vv benchmarks/ --benchmark-autosave --benchmark-histogram
28-
pytest-benchmark compare .benchmarks/Linux-CPython-3.7-64bit/* --histogram
29-
```
30-
31-
## Advanced running example
32-
```
33-
pytest benchmarks/ --benchmark-columns='min, max, mean, stddev, median, rounds, iterations' --benchmark-json=results.json --benchmark-autosave
34-
pytest-benchmark compare results.json --csv=results.csv --group-by='name'
35-
```
36-
37-
38-
[1] https://pytest-benchmark.readthedocs.io/en/latest/usage.html
1+
# dpnp/benchmarks/pytest_benchmark/
2+
3+
## Prerequisites
4+
* pytest >= 6.1.1
5+
* pytest-benchmark >= 3.4.1
6+
7+
8+
## Running benchmark tests
9+
```bash
10+
pytest benchmarks/ --benchmark-json=results.json
11+
```
12+
Running tests and saving the current run into `STORAGE`, see [1]
13+
```bash
14+
pytest benchmarks/ --benchmark-json=results.json --benchmark-autosave
15+
```
16+
17+
## Creating `.csv` report
18+
```bash
19+
pytest-benchmark compare results.json --csv=results.csv --group-by='name'
20+
```
21+
22+
## Optional: creating histogram
23+
Note: make sure that `pytest-benchmark[histogram]` installed
24+
```bash
25+
# example
26+
pip install pytest-benchmark[histogram]
27+
pytest -vv benchmarks/ --benchmark-autosave --benchmark-histogram
28+
pytest-benchmark compare .benchmarks/Linux-CPython-3.7-64bit/* --histogram
29+
```
30+
31+
## Advanced running example
32+
```
33+
pytest benchmarks/ --benchmark-columns='min, max, mean, stddev, median, rounds, iterations' --benchmark-json=results.json --benchmark-autosave
34+
pytest-benchmark compare results.json --csv=results.csv --group-by='name'
35+
```
36+
37+
38+
[1] https://pytest-benchmark.readthedocs.io/en/latest/usage.html
Lines changed: 117 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,117 @@
1-
# cython: language_level=3
2-
# -*- coding: utf-8 -*-
3-
# *****************************************************************************
4-
# Copyright (c) 2016-2024, Intel Corporation
5-
# All rights reserved.
6-
#
7-
# Redistribution and use in source and binary forms, with or without
8-
# modification, are permitted provided that the following conditions are met:
9-
# - Redistributions of source code must retain the above copyright notice,
10-
# this list of conditions and the following disclaimer.
11-
# - Redistributions in binary form must reproduce the above copyright notice,
12-
# this list of conditions and the following disclaimer in the documentation
13-
# and/or other materials provided with the distribution.
14-
#
15-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25-
# THE POSSIBILITY OF SUCH DAMAGE.
26-
# *****************************************************************************
27-
28-
import numpy as np
29-
import pytest
30-
31-
import dpnp
32-
33-
ROUNDS = 30
34-
ITERATIONS = 4
35-
36-
NNUMBERS = 2**26
37-
38-
39-
@pytest.mark.parametrize(
40-
"function", [dpnp.random.beta, np.random.beta], ids=["dpnp", "numpy"]
41-
)
42-
def test_beta(benchmark, function):
43-
result = benchmark.pedantic(
44-
target=function,
45-
args=(
46-
4.0,
47-
5.0,
48-
NNUMBERS,
49-
),
50-
rounds=ROUNDS,
51-
iterations=ITERATIONS,
52-
)
53-
54-
55-
@pytest.mark.parametrize(
56-
"function",
57-
[dpnp.random.exponential, np.random.exponential],
58-
ids=["dpnp", "numpy"],
59-
)
60-
def test_exponential(benchmark, function):
61-
result = benchmark.pedantic(
62-
target=function,
63-
args=(
64-
4.0,
65-
NNUMBERS,
66-
),
67-
rounds=ROUNDS,
68-
iterations=ITERATIONS,
69-
)
70-
71-
72-
@pytest.mark.parametrize(
73-
"function", [dpnp.random.gamma, np.random.gamma], ids=["dpnp", "numpy"]
74-
)
75-
def test_gamma(benchmark, function):
76-
result = benchmark.pedantic(
77-
target=function,
78-
args=(
79-
2.0,
80-
4.0,
81-
NNUMBERS,
82-
),
83-
rounds=ROUNDS,
84-
iterations=ITERATIONS,
85-
)
86-
87-
88-
@pytest.mark.parametrize(
89-
"function", [dpnp.random.normal, np.random.normal], ids=["dpnp", "numpy"]
90-
)
91-
def test_normal(benchmark, function):
92-
result = benchmark.pedantic(
93-
target=function,
94-
args=(
95-
0.0,
96-
1.0,
97-
NNUMBERS,
98-
),
99-
rounds=ROUNDS,
100-
iterations=ITERATIONS,
101-
)
102-
103-
104-
@pytest.mark.parametrize(
105-
"function", [dpnp.random.uniform, np.random.uniform], ids=["dpnp", "numpy"]
106-
)
107-
def test_uniform(benchmark, function):
108-
result = benchmark.pedantic(
109-
target=function,
110-
args=(
111-
0.0,
112-
1.0,
113-
NNUMBERS,
114-
),
115-
rounds=ROUNDS,
116-
iterations=ITERATIONS,
117-
)
1+
# cython: language_level=3
2+
# -*- coding: utf-8 -*-
3+
# *****************************************************************************
4+
# Copyright (c) 2016-2024, Intel Corporation
5+
# All rights reserved.
6+
#
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions are met:
9+
# - Redistributions of source code must retain the above copyright notice,
10+
# this list of conditions and the following disclaimer.
11+
# - Redistributions in binary form must reproduce the above copyright notice,
12+
# this list of conditions and the following disclaimer in the documentation
13+
# and/or other materials provided with the distribution.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25+
# THE POSSIBILITY OF SUCH DAMAGE.
26+
# *****************************************************************************
27+
28+
import numpy as np
29+
import pytest
30+
31+
import dpnp
32+
33+
ROUNDS = 30
34+
ITERATIONS = 4
35+
36+
NNUMBERS = 2**26
37+
38+
39+
@pytest.mark.parametrize(
40+
"function", [dpnp.random.beta, np.random.beta], ids=["dpnp", "numpy"]
41+
)
42+
def test_beta(benchmark, function):
43+
result = benchmark.pedantic(
44+
target=function,
45+
args=(
46+
4.0,
47+
5.0,
48+
NNUMBERS,
49+
),
50+
rounds=ROUNDS,
51+
iterations=ITERATIONS,
52+
)
53+
54+
55+
@pytest.mark.parametrize(
56+
"function",
57+
[dpnp.random.exponential, np.random.exponential],
58+
ids=["dpnp", "numpy"],
59+
)
60+
def test_exponential(benchmark, function):
61+
result = benchmark.pedantic(
62+
target=function,
63+
args=(
64+
4.0,
65+
NNUMBERS,
66+
),
67+
rounds=ROUNDS,
68+
iterations=ITERATIONS,
69+
)
70+
71+
72+
@pytest.mark.parametrize(
73+
"function", [dpnp.random.gamma, np.random.gamma], ids=["dpnp", "numpy"]
74+
)
75+
def test_gamma(benchmark, function):
76+
result = benchmark.pedantic(
77+
target=function,
78+
args=(
79+
2.0,
80+
4.0,
81+
NNUMBERS,
82+
),
83+
rounds=ROUNDS,
84+
iterations=ITERATIONS,
85+
)
86+
87+
88+
@pytest.mark.parametrize(
89+
"function", [dpnp.random.normal, np.random.normal], ids=["dpnp", "numpy"]
90+
)
91+
def test_normal(benchmark, function):
92+
result = benchmark.pedantic(
93+
target=function,
94+
args=(
95+
0.0,
96+
1.0,
97+
NNUMBERS,
98+
),
99+
rounds=ROUNDS,
100+
iterations=ITERATIONS,
101+
)
102+
103+
104+
@pytest.mark.parametrize(
105+
"function", [dpnp.random.uniform, np.random.uniform], ids=["dpnp", "numpy"]
106+
)
107+
def test_uniform(benchmark, function):
108+
result = benchmark.pedantic(
109+
target=function,
110+
args=(
111+
0.0,
112+
1.0,
113+
NNUMBERS,
114+
),
115+
rounds=ROUNDS,
116+
iterations=ITERATIONS,
117+
)

conda-recipe/build.sh

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,29 @@ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${BUILD_PREFIX}/lib"
55

66
# Intel LLVM must cooperate with compiler and sysroot from conda
77
echo "--gcc-toolchain=${BUILD_PREFIX} --sysroot=${BUILD_PREFIX}/${HOST}/sysroot -target ${HOST}" > icpx_for_conda.cfg
8-
export ICPXCFG="$(pwd)/icpx_for_conda.cfg"
9-
export ICXCFG="$(pwd)/icpx_for_conda.cfg"
8+
9+
ICPXCFG="$(pwd)/icpx_for_conda.cfg"
10+
export ICPXCFG
11+
12+
ICXCFG="$(pwd)/icpx_for_conda.cfg"
13+
export ICXCFG
1014

1115
export CMAKE_GENERATOR="Ninja"
1216
export TBB_ROOT_HINT=$PREFIX
1317
export DPL_ROOT_HINT=$PREFIX
1418
export MKL_ROOT_HINT=$PREFIX
15-
SKBUILD_ARGS="-- -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
16-
SKBUILD_ARGS="${SKBUILD_ARGS} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
19+
SKBUILD_ARGS=(-- "-DCMAKE_C_COMPILER:PATH=icx" "-DCMAKE_CXX_COMPILER:PATH=icpx" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON")
20+
SKBUILD_ARGS=("${SKBUILD_ARGS[@]}" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON")
1721

1822
# Build wheel package
1923
if [ "$CONDA_PY" == "36" ]; then
20-
WHEELS_BUILD_ARGS="-p manylinux1_x86_64"
24+
WHEELS_BUILD_ARGS=("-p" "manylinux1_x86_64")
2125
else
22-
WHEELS_BUILD_ARGS="-p manylinux2014_x86_64"
26+
WHEELS_BUILD_ARGS=("-p" "manylinux2014_x86_64")
2327
fi
2428
if [ -n "${WHEELS_OUTPUT_FOLDER}" ]; then
25-
$PYTHON setup.py install bdist_wheel ${WHEELS_BUILD_ARGS} ${SKBUILD_ARGS}
26-
cp dist/dpnp*.whl ${WHEELS_OUTPUT_FOLDER}
29+
$PYTHON setup.py install bdist_wheel "${WHEELS_BUILD_ARGS[@]}" "${SKBUILD_ARGS[@]}"
30+
cp dist/dpnp*.whl "${WHEELS_OUTPUT_FOLDER}"
2731
else
28-
$PYTHON setup.py install ${SKBUILD_ARGS}
32+
$PYTHON setup.py install "${SKBUILD_ARGS[@]}"
2933
fi

conda-recipe/run_test.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ fi
1010

1111
# if DPCPPROOT is specified (work with custom DPCPP)
1212
if [ -n "${DPCPPROOT}" ]; then
13-
. ${DPCPPROOT}/env/vars.sh
13+
# shellcheck source=/dev/null
14+
. "${DPCPPROOT}"/env/vars.sh
1415
fi
1516

1617
# if MKLROOT is specified (work with custom math library)
1718
if [ -n "${MKLROOT}" ]; then
18-
. ${MKLROOT}/env/vars.sh
19+
# shellcheck source=/dev/null
20+
. "${MKLROOT}"/env/vars.sh
1921
fi
2022

2123
# have to activate while SYCL CPU device/driver needs paths
2224
# if TBBROOT is specified
2325
if [ -n "${TBBROOT}" ]; then
24-
. ${TBBROOT}/env/vars.sh
26+
# shellcheck source=/dev/null
27+
. "${TBBROOT}"/env/vars.sh
2528
fi

0 commit comments

Comments
 (0)