Skip to content

Commit 2a1d411

Browse files
authored
Merge pull request #282 from IntelPython/add-more-pre-commit-checks
Add more pre-commit checks
2 parents e782c52 + 71ee582 commit 2a1d411

7 files changed

Lines changed: 102 additions & 68 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
- name: Build mkl_fft
6666
run: |
6767
source ${{ env.ONEAPI_ROOT }}/setvars.sh
68-
echo $CMPLR_ROOT
68+
echo "$CMPLR_ROOT"
6969
export CC=$CMPLR_ROOT/bin/icx
7070
export CFLAGS="${CFLAGS} -fno-fast-math -O2"
7171
pip install -e . --no-build-isolation --no-deps --verbose

.github/workflows/build_pip.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ jobs:
5757
pip install --no-cache-dir numpy ${{ matrix.use_pre }}
5858
echo "CONDA_PREFFIX is '${CONDA_PREFIX}'"
5959
export MKLROOT=${CONDA_PREFIX}
60-
pip install -e .[test] --no-build-isolation --verbose
60+
pip install -e ".[test]" --no-build-isolation --verbose
6161
pip list
6262
python -m pytest -v mkl_fft/tests

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ jobs:
5656
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
5757
5858
- name: Add conda to system path
59-
run: echo $CONDA/bin >> $GITHUB_PATH
59+
run: echo "$CONDA"/bin >> "$GITHUB_PATH"
6060

6161
- name: Install conda-build
6262
run: conda install conda-build
6363

6464
- name: Build conda package with NumPy 2.x
6565
run: |
66-
CHANNELS="-c conda-forge --override-channels"
67-
VERSIONS="--python ${{ matrix.python }} --numpy ${{ matrix.numpy }}"
68-
TEST="--no-test"
66+
CHANNELS=(-c conda-forge --override-channels)
67+
VERSIONS=(--python "${{ matrix.python }}" --numpy "${{ matrix.numpy }}")
68+
TEST=(--no-test)
6969
7070
conda build \
71-
$TEST \
72-
$VERSIONS \
73-
$CHANNELS \
71+
"${TEST[@]}" \
72+
"${VERSIONS[@]}" \
73+
"${CHANNELS[@]}" \
7474
conda-recipe-cf
7575
7676
- name: Upload artifact
@@ -100,23 +100,23 @@ jobs:
100100
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python_ver }}
101101

102102
- name: Add conda to system path
103-
run: echo $CONDA/bin >> $GITHUB_PATH
103+
run: echo "$CONDA"/bin >> "$GITHUB_PATH"
104104

105105
- name: Install conda-build
106106
run: conda install conda-build
107107

108108
- name: Create conda channel
109109
run: |
110-
mkdir -p $GITHUB_WORKSPACE/channel/linux-64
111-
mv ${PACKAGE_NAME}-*.conda $GITHUB_WORKSPACE/channel/linux-64
112-
conda index $GITHUB_WORKSPACE/channel
110+
mkdir -p "$GITHUB_WORKSPACE"/channel/linux-64
111+
mv "$PACKAGE_NAME"-*.conda "$GITHUB_WORKSPACE"/channel/linux-64
112+
conda index "$GITHUB_WORKSPACE"/channel
113113
# Test channel
114-
conda search $PACKAGE_NAME -c $GITHUB_WORKSPACE/channel --override-channels
114+
conda search "$PACKAGE_NAME" -c "$GITHUB_WORKSPACE"/channel --override-channels
115115
116116
- name: Collect dependencies
117117
run: |
118-
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
119-
conda create -n ${{ env.TEST_ENV_NAME }} $PACKAGE_NAME python=${{ matrix.python_ver }} ${{ matrix.numpy }} $CHANNELS --only-deps --dry-run > lockfile
118+
CHANNELS=(-c "$GITHUB_WORKSPACE"/channel ${{ env.CHANNELS }})
119+
conda create -n ${{ env.TEST_ENV_NAME }} "$PACKAGE_NAME" python=${{ matrix.python_ver }} ${{ matrix.numpy }} "${CHANNELS[@]}" --only-deps --dry-run > lockfile
120120
121121
- name: Display lockfile
122122
run: cat lockfile
@@ -139,16 +139,16 @@ jobs:
139139
140140
- name: Install mkl_fft
141141
run: |
142-
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
143-
conda create -n ${{ env.TEST_ENV_NAME }} python=${{ matrix.python_ver }} ${{ matrix.numpy }} $PACKAGE_NAME pytest scipy $CHANNELS
142+
CHANNELS=(-c "$GITHUB_WORKSPACE"/channel ${{ env.CHANNELS }})
143+
conda create -n ${{ env.TEST_ENV_NAME }} python=${{ matrix.python_ver }} ${{ matrix.numpy }} "$PACKAGE_NAME" pytest scipy "${CHANNELS[@]}"
144144
# Test installed packages
145145
conda list -n ${{ env.TEST_ENV_NAME }}
146146
147147
- name: Run tests
148148
run: |
149-
source $CONDA/etc/profile.d/conda.sh
149+
source "$CONDA"/etc/profile.d/conda.sh
150150
conda activate ${{ env.TEST_ENV_NAME }}
151-
pytest -v --pyargs $MODULE_NAME
151+
pytest -v --pyargs "$MODULE_NAME"
152152
153153
build_windows:
154154
runs-on: windows-latest
@@ -208,7 +208,7 @@ jobs:
208208
- name: Store conda paths as envs
209209
shell: bash -l {0}
210210
run: |
211-
echo "CONDA_BLD=$CONDA/conda-bld/win-64/" | tr "\\\\" '/' >> $GITHUB_ENV
211+
echo "CONDA_BLD=$CONDA/conda-bld/win-64/" | tr "\\\\" '/' >> "$GITHUB_ENV"
212212
213213
- name: Upload artifact
214214
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
@@ -244,7 +244,7 @@ jobs:
244244
with:
245245
miniforge-version: latest
246246
activate-environment: ${{ env.TEST_ENV_NAME }}
247-
python-version: ${{ matrix.python }}
247+
python-version: ${{ matrix.python_ver }}
248248
channels: conda-forge
249249
conda-remove-defaults: 'true'
250250

@@ -315,7 +315,7 @@ jobs:
315315
SET PACKAGE_VERSION=%%F
316316
)
317317
SET "TEST_DEPENDENCIES=pytest scipy"
318-
conda install -n ${{ env.TEST_ENV_NAME }} ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% %TEST_DEPENDENCIES% python=${{ matrix.python }} ${{ matrix.numpy }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }}
318+
conda install -n ${{ env.TEST_ENV_NAME }} ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% %TEST_DEPENDENCIES% python=${{ matrix.python_ver }} ${{ matrix.numpy }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }}
319319
320320
- name: Report content of test environment
321321
shell: cmd /C CALL {0}

.github/workflows/conda-package.yml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ jobs:
4848
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
4949
5050
- name: Add conda to system path
51-
run: echo $CONDA/bin >> $GITHUB_PATH
51+
run: echo "$CONDA"/bin >> "$GITHUB_PATH"
5252

5353
- name: Install conda-build
5454
run: conda install conda-build
5555

5656
- name: Build conda package
5757
run: |
58-
CHANNELS="-c https://software.repos.intel.com/python/conda -c conda-forge --override-channels"
59-
VERSIONS="--python ${{ matrix.python }}"
60-
TEST="--no-test"
58+
CHANNELS=(-c https://software.repos.intel.com/python/conda -c conda-forge --override-channels)
59+
VERSIONS=(--python "${{ matrix.python }}")
60+
TEST=(--no-test)
6161
6262
conda build \
63-
$TEST \
64-
$VERSIONS \
65-
$CHANNELS \
63+
"${TEST[@]}" \
64+
"${VERSIONS[@]}" \
65+
"${CHANNELS[@]}" \
6666
conda-recipe
6767
6868
- name: Upload artifact
@@ -91,32 +91,34 @@ jobs:
9191
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
9292

9393
- name: Add conda to system path
94-
run: echo $CONDA/bin >> $GITHUB_PATH
94+
run: echo "$CONDA"/bin >> "$GITHUB_PATH"
9595

9696
- name: Install conda-build
9797
run: conda install conda-build
9898

9999
- name: Create conda channel
100100
run: |
101-
mkdir -p $GITHUB_WORKSPACE/channel/linux-64
102-
mv ${PACKAGE_NAME}-*.conda $GITHUB_WORKSPACE/channel/linux-64
103-
conda index $GITHUB_WORKSPACE/channel
101+
mkdir -p "$GITHUB_WORKSPACE"/channel/linux-64
102+
mv "$PACKAGE_NAME"-*.conda "$GITHUB_WORKSPACE"/channel/linux-64
103+
conda index "$GITHUB_WORKSPACE"/channel
104104
105105
- name: Test conda channel
106106
run: |
107-
conda search $PACKAGE_NAME -c $GITHUB_WORKSPACE/channel --override-channels --info --json > $GITHUB_WORKSPACE/ver.json
108-
cat $GITHUB_WORKSPACE/ver.json
107+
conda search "$PACKAGE_NAME" -c "$GITHUB_WORKSPACE"/channel --override-channels --info --json > "$GITHUB_WORKSPACE"/ver.json
108+
cat "$GITHUB_WORKSPACE"/ver.json
109109
110110
- name: Get package version
111111
run: |
112-
export PACKAGE_VERSION=$(python -c "${{ env.VER_SCRIPT1 }} ${{ env.VER_SCRIPT2 }}")
113-
echo PACKAGE_VERSION=${PACKAGE_VERSION}
114-
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
112+
PACKAGE_VERSION=$(python -c "${{ env.VER_SCRIPT1 }} ${{ env.VER_SCRIPT2 }}")
113+
export PACKAGE_VERSION
114+
115+
echo PACKAGE_VERSION="${PACKAGE_VERSION}"
116+
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> "$GITHUB_ENV"
115117
116118
- name: Collect dependencies
117119
run: |
118-
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
119-
conda create -n ${{ env.TEST_ENV_NAME }} $PACKAGE_NAME python=${{ matrix.python }} $CHANNELS --only-deps --dry-run > lockfile
120+
CHANNELS=(-c "$GITHUB_WORKSPACE"/channel ${{ env.CHANNELS }})
121+
conda create -n ${{ env.TEST_ENV_NAME }} "$PACKAGE_NAME" python=${{ matrix.python }} "${CHANNELS[@]}" --only-deps --dry-run > lockfile
120122
121123
- name: Display lockfile
122124
run: cat lockfile
@@ -139,17 +141,17 @@ jobs:
139141
140142
- name: Install mkl_fft
141143
run: |
142-
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
143-
conda create -n ${{ env.TEST_ENV_NAME }} $PACKAGE_NAME=${{ env.PACKAGE_VERSION }} python=${{ matrix.python }} pytest $CHANNELS
144-
conda install -n ${{ env.TEST_ENV_NAME }} "scipy>=1.10" $CHANNELS
144+
CHANNELS=(-c "$GITHUB_WORKSPACE"/channel ${{ env.CHANNELS }})
145+
conda create -n ${{ env.TEST_ENV_NAME }} "$PACKAGE_NAME"=${{ env.PACKAGE_VERSION }} python=${{ matrix.python }} pytest "${CHANNELS[@]}"
146+
conda install -n ${{ env.TEST_ENV_NAME }} "scipy>=1.10" "${CHANNELS[@]}"
145147
# Test installed packages
146148
conda list -n ${{ env.TEST_ENV_NAME }}
147149
148150
- name: Run tests
149151
run: |
150-
source $CONDA/etc/profile.d/conda.sh
152+
source "$CONDA"/etc/profile.d/conda.sh
151153
conda activate ${{ env.TEST_ENV_NAME }}
152-
pytest -v --pyargs $MODULE_NAME
154+
pytest -v --pyargs "$MODULE_NAME"
153155
154156
build_windows:
155157
runs-on: windows-latest
@@ -203,7 +205,7 @@ jobs:
203205
- name: Store conda paths as envs
204206
shell: bash -l {0}
205207
run: |
206-
echo "CONDA_BLD=$CONDA/conda-bld/win-64/" | tr "\\\\" '/' >> $GITHUB_ENV
208+
echo "CONDA_BLD=$CONDA/conda-bld/win-64/" | tr "\\\\" '/' >> "$GITHUB_ENV"
207209
208210
- name: Upload artifact
209211
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0

.github/workflows/pre-commit.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ jobs:
1414
steps:
1515
- name: Checkout repo
1616
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
with:
18+
# use commit hash to make "no-commit-to-branch" check passing
19+
ref: ${{ github.sha }}
1720

1821
- name: Set up python
1922
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
2023
with:
21-
python-version: '3.13'
24+
python-version: '3.14'
2225

2326
- name: Set up pip packages
2427
uses: BSFishy/pip-action@8f2d471d809dc20b6ada98c91910b6ae6243f318 # v1
@@ -29,9 +32,9 @@ jobs:
2932
3033
- name: Set up clang-format
3134
run: |
32-
sudo apt-get install -y clang-format-14
35+
sudo apt-get install -y clang-format-15
3336
sudo unlink /usr/bin/clang-format
34-
sudo ln -s /usr/bin/clang-format-14 /usr/bin/clang-format
37+
sudo ln -s /usr/bin/clang-format-15 /usr/bin/clang-format
3538
clang-format --version
3639
3740
- name: Run pre-commit checks

.pre-commit-config.yaml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v6.0.0
44
hooks:
5+
# Git
6+
- id: check-added-large-files
7+
- id: no-commit-to-branch
8+
name: "ensure no direct commit to master/maintenance branches"
9+
args: [--branch, "master", --pattern, "maintenance/.*"]
10+
- id: check-case-conflict
11+
- id: check-illegal-windows-names
12+
# Contents
513
- id: check-ast
614
- id: check-builtin-literals
715
- id: check-case-conflict
@@ -15,19 +23,19 @@ repos:
1523
- id: mixed-line-ending
1624
- id: trailing-whitespace
1725

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
26+
- repo: https://github.com/pre-commit/pygrep-hooks
27+
rev: v1.10.0
28+
hooks:
29+
- id: python-check-blanket-noqa
30+
- id: python-check-blanket-type-ignore
31+
- id: python-check-mock-methods
32+
- id: python-no-eval
33+
- id: python-no-log-warn
34+
- id: python-use-type-annotations
35+
- id: rst-backticks
36+
- id: rst-directive-colons
37+
- id: rst-inline-touching-normal
38+
- id: text-unicode-replacement-char
3139

3240
- repo: https://github.com/codespell-project/codespell
3341
rev: v2.4.1
@@ -62,7 +70,7 @@ repos:
6270
args: ["--config=.flake8"]
6371
additional_dependencies:
6472
- flake8-docstrings==1.7.0
65-
- flake8-bugbear==24.4.26
73+
- flake8-bugbear==25.11.29
6674

6775
- repo: https://github.com/pycqa/isort
6876
rev: 8.0.0
@@ -102,3 +110,14 @@ repos:
102110
rev: 3.0.0
103111
hooks:
104112
- id: shellcheck
113+
114+
- repo: https://github.com/gitleaks/gitleaks
115+
rev: v8.30.0
116+
hooks:
117+
- id: gitleaks
118+
119+
- repo: https://github.com/rhysd/actionlint
120+
rev: v1.7.11
121+
hooks:
122+
- id: actionlint
123+
args: ["-ignore", "SC2317"]

mkl_fft/interfaces/_scipy_fft.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,31 @@ def workers(self):
8686

8787
@workers.setter
8888
def workers(self, workers_val):
89-
self.workerks_ = operator.index(workers_val)
89+
self.workers_ = operator.index(workers_val)
9090

9191

92+
# Use an immutable default (i.e. None) and create the object when needed
9293
_workers_global_settings = contextvars.ContextVar(
93-
"scipy_backend_workers", default=_workers_data()
94+
"scipy_backend_workers", default=None
9495
)
9596

9697

98+
def _get_workers_settings():
99+
"""Lazy initialization"""
100+
value = _workers_global_settings.get()
101+
if value is None:
102+
value = _workers_data()
103+
_workers_global_settings.set(value)
104+
return value
105+
106+
97107
def _workers_to_num_threads(w):
98108
"""
99109
Handle conversion of workers to a positive number of threads in the
100110
same way as scipy.fft._pocketfft.helpers._workers.
101111
"""
102112
if w is None:
103-
return _workers_global_settings.get().workers
113+
return _get_workers_settings().workers
104114
_w = operator.index(w)
105115
if _w == 0:
106116
raise ValueError("Number of workers must not be zero")
@@ -707,7 +717,7 @@ def get_workers():
707717
For full documentation refer to `scipy.fft.get_workers`.
708718
709719
"""
710-
return _workers_global_settings.get().workers
720+
return _get_workers_settings().workers
711721

712722

713723
@contextlib.contextmanager

0 commit comments

Comments
 (0)