Skip to content

Run tests in debug mode in an additional CI job #1145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,80 @@ jobs:
if: ${{ matrix.os == 'ubuntu' }}
uses: aio-libs/[email protected]


test_debug_mode:
name: Test in debug mode
strategy:
matrix:
pyver:
- 3.13t
- 3.13
- 3.12
- 3.11
- "3.10"
- 3.9
fail-fast: false
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Checkout project
uses: actions/checkout@v4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this to checkout from sdist instead of Git? It'll mimic what both pip and downstreams do. And this is what we really want not to crash.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was not about 'cannot build from sdist' but 'cannot build and run tests when debug mode is on'.

I don't think that the installation from sdist makes any difference here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downstreams tend to additionally package debug symbols.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What symbols? Could you please elaborate how it does related?

- name: Setup Python ${{ matrix.pyver }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.pyver }}
allow-prereleases: true
- name: Get pip cache dir
id: pip-cache
run: |
echo "dir=$(pip cache dir)" >> "${GITHUB_OUTPUT}"
shell: bash
- name: Cache PyPI
uses: actions/cache@v4
with:
key: >-
pip-ci-${{
runner.os
}}-${{
matrix.pyver
}}--${{
hashFiles('requirements/*.txt')
}}
path: ${{ steps.pip-cache.outputs.dir }}
restore-keys: >-
pip-ci-${{
runner.os
}}-${{
matrix.pyver
}}--
- name: Install dependencies
uses: py-actions/py-dependency-install@v4
with:
path: requirements/pytest.txt
- name: >-
Self-install source
Comment on lines +428 to +429
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, source is never installed. Only the contents of wheels are. I think, the following will better communicate what this does.

Suggested change
- name: >-
Self-install source
- name: Compile and install from source checkout

env:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try setting PIP_CONSTRAINT? This is so the same build deps are used here and when publishing.

MULTIDICT_DEBUG_BUILD: Y
run: >-
python -Im
pip install '.'
- name: Run unittests without coverage
run: >-
python -Im pytest tests -v
--no-cov
--c-extensions
- name: Re-run the failing tests with maximum verbosity
if: >-
!cancelled()
&& failure()
run: >- # `exit 1` makes sure that the job remains red with flaky runs
python -Im
pytest --no-cov -vvvvv --lf -rA
--c-extensions
&& exit 1
shell: bash

benchmark:
name: Benchmark
needs:
Expand Down
1 change: 1 addition & 0 deletions CHANGES/1145.packaging.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the ability to build in debug mode by setting ``MULTIDICT_DEBUG_BUILD`` in the environment -- by :user:`bdraco`.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ e.g.:
Please note, the pure Python (uncompiled) version is about 20-50 times slower depending on
the usage scenario!!!

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

.. code-block:: bash

$ MULTIDICT_DEBUG_BUILD=1 pip install multidict

Changelog
---------
Expand Down
12 changes: 12 additions & 0 deletions docs/multidict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,15 @@ Environment variables

The pure-Python (uncompiled) version is roughly 20-50 times slower than
its C counterpart, depending on the way it's used.

.. envvar:: MULTIDICT_DEBUG_BUILD

An environment variable that instructs the packaging scripts to compile
the C-extension based variant of :mod:`multidict` with debug symbols.
This is useful for debugging the C-extension code, but it will result in
a larger binary size and slower performance.

.. caution::

The debug build is not intended for production use and should only be
used for development and debugging purposes.
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from setuptools import Extension, setup

NO_EXTENSIONS = bool(os.environ.get("MULTIDICT_NO_EXTENSIONS"))
DEBUG_BUILD = bool(os.environ.get("MULTIDICT_DEBUG_BUILD"))

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

CFLAGS = ["-O3"]
# CFLAGS = ["-O0", "-g3", "-UNDEBUG"]
CFLAGS = ["-O0", "-g3", "-UNDEBUG"] if DEBUG_BUILD else ["-O3"]

if platform.system() != "Windows":
CFLAGS.extend(
[
Expand Down
Loading