From 3a1b5a21f11879f170de3e31ce8ed0730281f847 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Tue, 16 May 2023 12:27:21 -0400 Subject: [PATCH 1/2] Add env variable to Python builds to force debug builds This commit updates the setup.py for the python package to add a new env variable `RUST_DEBUG` to force the package to be built in debug mode. By default pip install will build the rust code in release mode, which is the sane default you want for publishing or installing a package. But for local development you typically want to build normally in debug mode. This increases the build speed and also adds additional runtime checking to validate the code is fully working. The tradeoff with this though is the runtime is very poor because the compiler doesn't do any optimization. As part of this commit the tox configuration is updated to default to debug builds. For unit tests the execution time is unchanged, because while it compiles faster that is offset by the slower execution of the tests. However, in general I think it's better to run tests in debug mode by default because it will do runtime validation (e.g. bounds checks overflow detection, etc) which is good to catch in testing. --- setup.py | 7 ++++++- tox.ini | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e0c73be2e..ee42919f5 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,11 @@ from setuptools_rust import Binding, RustExtension +# If RUST_DEBUG is set, force compiling in debug mode. Else, use the default behavior of whether +# it's an editable installation. +rust_debug = True if os.getenv("RUST_DEBUG") == "1" else None + + def readme(): with open('README.md') as f: return f.read() @@ -25,7 +30,7 @@ def readme(): PKG_PACKAGES = ["rustworkx", "rustworkx.visualization"] PKG_INSTALL_REQUIRES = ['numpy>=1.16.0'] RUST_EXTENSIONS = [RustExtension("rustworkx.rustworkx", "Cargo.toml", - binding=Binding.PyO3)] + binding=Binding.PyO3, debug=rust_debug)] retworkx_readme_compat = """# retworkx diff --git a/tox.ini b/tox.ini index cc246d3f1..f3c86f55f 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,7 @@ setenv = LANGUAGE=en_US LC_ALL=en_US.utf-8 ARGS="-V" + RUST_DEBUG=1 deps = setuptools-rust fixtures @@ -22,6 +23,7 @@ extras = passenv = RETWORKX_TEST_PRESERVE_IMAGES RUSTWORKX_PKG_NAME + RUST_DEBUG changedir = {toxinidir}/tests commands = stestr run {posargs} @@ -43,12 +45,14 @@ commands = basepython = python3 setenv = {[testenv]setenv} + RUST_DEBUG=1 deps = -r {toxinidir}/docs/source/requirements.txt passenv = {[testenv]passenv} RETWORKX_DEV_DOCS RETWORKX_LEGACY_DOCS + RUST_DEBUG changedir = {toxinidir}/docs commands = python -m ipykernel install --user From 24eac7b17802aa8c8bc3ae56cbe16ed41edcbdb3 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 17 May 2023 09:27:26 -0400 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com> --- setup.py | 4 ++-- tox.ini | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index ee42919f5..80d3f4364 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ # If RUST_DEBUG is set, force compiling in debug mode. Else, use the default behavior of whether # it's an editable installation. -rust_debug = True if os.getenv("RUST_DEBUG") == "1" else None +rustworkx_debug = True if os.getenv("RUSTWORKX_DEBUG") == "1" else None def readme(): @@ -30,7 +30,7 @@ def readme(): PKG_PACKAGES = ["rustworkx", "rustworkx.visualization"] PKG_INSTALL_REQUIRES = ['numpy>=1.16.0'] RUST_EXTENSIONS = [RustExtension("rustworkx.rustworkx", "Cargo.toml", - binding=Binding.PyO3, debug=rust_debug)] + binding=Binding.PyO3, debug=rustworkx_debug)] retworkx_readme_compat = """# retworkx diff --git a/tox.ini b/tox.ini index f3c86f55f..7f13c3084 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,7 @@ extras = passenv = RETWORKX_TEST_PRESERVE_IMAGES RUSTWORKX_PKG_NAME - RUST_DEBUG + RUSTWORKX_DEBUG changedir = {toxinidir}/tests commands = stestr run {posargs} @@ -45,7 +45,7 @@ commands = basepython = python3 setenv = {[testenv]setenv} - RUST_DEBUG=1 + RUSTWORKX_DEBUG=1 deps = -r {toxinidir}/docs/source/requirements.txt passenv =