Skip to content

Commit 28b7b4b

Browse files
bdracowebknjaz
andauthored
Run tests in debug mode as well (#1146)
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
1 parent cf690d5 commit 28b7b4b

File tree

5 files changed

+56
-14
lines changed

5 files changed

+56
-14
lines changed

.github/workflows/ci-cd.yml

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ jobs:
158158
dists-artifact-name: ${{ needs.pre-setup.outputs.dists-artifact-name }}
159159

160160
test:
161-
name: Test
161+
name: >-
162+
Test ${{ matrix.os }}
163+
${{ matrix.pyver }}
164+
${{ matrix.no-extensions == 'Y' && ' ' || 'ext' }}
165+
${{ matrix.debug == 'Y' && 'debug' || '' }}
162166
needs:
163167
- build-pure-python-dists # transitive, for accessing settings
164168
- build-wheels-for-tested-arches
@@ -174,7 +178,10 @@ jobs:
174178
- 3.9
175179
no-extensions: ['', 'Y']
176180
os: [ubuntu, macos, windows]
181+
debug: ['', 'Y']
177182
exclude:
183+
- no-extensions: Y
184+
debug: Y
178185
- os: macos
179186
no-extensions: Y
180187
- os: windows
@@ -183,10 +190,13 @@ jobs:
183190
pyver: 3.13-freethreading # this is still tested within cibuildwheel
184191
- os: windows
185192
pyver: 3.13-freethreading # this is still tested within cibuildwheel
193+
- no-extensions: Y
194+
debug: Y
186195
include:
187196
- pyver: pypy-3.9
188197
no-extensions: Y
189198
os: ubuntu
199+
debug: ''
190200
fail-fast: false
191201
runs-on: ${{ matrix.os }}-latest
192202
timeout-minutes: 15
@@ -199,6 +209,14 @@ jobs:
199209
}}
200210
201211
steps:
212+
- name: Determine build type
213+
id: build_type
214+
run: |
215+
echo "build_type=${{
216+
(contains(matrix.pyver, '-dev') || matrix.debug == 'Y') &&
217+
'source' || 'wheel'
218+
}}" >> "$GITHUB_OUTPUT"
219+
shell: sh
202220
- name: Retrieve the project source from an sdist inside the GHA artifact
203221
uses: re-actors/checkout-python-sdist@release/v2
204222
with:
@@ -207,7 +225,7 @@ jobs:
207225
workflow-artifact-name: >-
208226
${{ needs.pre-setup.outputs.dists-artifact-name }}
209227
- name: Download distributions
210-
if: ${{ !endsWith(matrix.pyver, '-dev') && true || false }}
228+
if: steps.build_type.outputs.build_type == 'wheel'
211229
uses: actions/download-artifact@v4
212230
with:
213231
pattern: ${{ needs.pre-setup.outputs.dists-artifact-name }}*
@@ -268,6 +286,8 @@ jobs:
268286
matrix.pyver
269287
}}-${{
270288
matrix.no-extensions
289+
}}-${{
290+
matrix.debug
271291
}}-${{
272292
hashFiles('requirements/*.txt')
273293
}}
@@ -279,13 +299,15 @@ jobs:
279299
matrix.pyver
280300
}}-${{
281301
matrix.no-extensions
282-
}}-
302+
}}-${{
303+
matrix.debug
304+
}}
283305
- name: Install dependencies
284306
uses: py-actions/py-dependency-install@v4
285307
with:
286308
path: requirements/pytest.txt
287309
- name: Determine pre-compiled compatible wheel
288-
if: ${{ !endsWith(matrix.pyver, '-dev') && true || false }}
310+
if: steps.build_type.outputs.build_type == 'wheel'
289311
env:
290312
# NOTE: When `pip` is forced to colorize output piped into `jq`,
291313
# NOTE: the latter can't parse it. So we're overriding the color
@@ -324,18 +346,18 @@ jobs:
324346
| jq --raw-output .install[].download_info.url
325347
| tee -a "${GITHUB_OUTPUT}"
326348
shell: bash
327-
- name: >-
328-
Self-install (from ${{
329-
endsWith(matrix.pyver, '-dev')
330-
&& 'source'
331-
|| 'wheel'
332-
}})
349+
- name: Ensure clean for source build
350+
if: steps.build_type.outputs.build_type == 'source'
351+
run: >-
352+
make clean
353+
shell: bash
354+
- name: Self-install (from ${{ steps.build_type.outputs.build_type }})
333355
env:
334356
MULTIDICT_NO_EXTENSIONS: ${{ matrix.no-extensions }}
357+
MULTIDICT_DEBUG_BUILD: 1 # Always on for source builds
335358
run: >-
336-
python -Im
337359
pip install '${{
338-
endsWith(matrix.pyver, '-dev')
360+
steps.build_type.outputs.build_type == 'source'
339361
&& '.'
340362
|| steps.wheel-file.outputs.path
341363
}}'
@@ -374,6 +396,7 @@ jobs:
374396
if: ${{ matrix.os == 'ubuntu' }}
375397
uses: aio-libs/[email protected]
376398

399+
377400
benchmark:
378401
name: Benchmark
379402
needs:

CHANGES/1145.packaging.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added the ability to build in debug mode by setting :envvar:`MULTIDICT_DEBUG_BUILD` in the environment -- by :user:`bdraco`.

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ e.g.:
104104
Please note, the pure Python (uncompiled) version is about 20-50 times slower depending on
105105
the usage scenario!!!
106106

107+
For extension development, set the ``MULTIDICT_DEBUG_BUILD`` environment variable to compile
108+
the extensions in debug mode:
107109

110+
.. code-block:: console
111+
112+
$ MULTIDICT_DEBUG_BUILD=1 pip install multidict
108113
109114
Changelog
110115
---------

docs/multidict.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,15 @@ Environment variables
442442

443443
The pure-Python (uncompiled) version is roughly 20-50 times slower than
444444
its C counterpart, depending on the way it's used.
445+
446+
.. envvar:: MULTIDICT_DEBUG_BUILD
447+
448+
An environment variable that instructs the packaging scripts to compile
449+
the C-extension based variant of :mod:`multidict` with debug symbols.
450+
This is useful for debugging the C-extension code, but it will result in
451+
a larger binary size and worse performance.
452+
453+
.. caution::
454+
455+
The debug build is not intended for production use and should only be
456+
used for development and debugging purposes.

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
from setuptools import Extension, setup
66

77
NO_EXTENSIONS = bool(os.environ.get("MULTIDICT_NO_EXTENSIONS"))
8+
DEBUG_BUILD = bool(os.environ.get("MULTIDICT_DEBUG_BUILD"))
89

910
if sys.implementation.name != "cpython":
1011
NO_EXTENSIONS = True
1112

12-
CFLAGS = ["-O3"]
13-
# CFLAGS = ["-O0", "-g3", "-UNDEBUG"]
13+
CFLAGS = ["-O0", "-g3", "-UNDEBUG"] if DEBUG_BUILD else ["-O3"]
14+
1415
if platform.system() != "Windows":
1516
CFLAGS.extend(
1617
[

0 commit comments

Comments
 (0)