Skip to content

Commit

Permalink
Add env variable to Python builds to force debug builds (#876)
Browse files Browse the repository at this point in the history
* 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.

* Apply suggestions from code review

Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com>

---------

Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com>
  • Loading branch information
mtreinish and IvanIsCoding authored May 17, 2023
1 parent 32ea6c7 commit 171aa31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
rustworkx_debug = True if os.getenv("RUSTWORKX_DEBUG") == "1" else None


def readme():
with open('README.md') as f:
return f.read()
Expand All @@ -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=rustworkx_debug)]

retworkx_readme_compat = """# retworkx
Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ setenv =
LANGUAGE=en_US
LC_ALL=en_US.utf-8
ARGS="-V"
RUST_DEBUG=1
deps =
setuptools-rust
fixtures
Expand All @@ -22,6 +23,7 @@ extras =
passenv =
RETWORKX_TEST_PRESERVE_IMAGES
RUSTWORKX_PKG_NAME
RUSTWORKX_DEBUG
changedir = {toxinidir}/tests
commands =
stestr run {posargs}
Expand All @@ -43,12 +45,14 @@ commands =
basepython = python3
setenv =
{[testenv]setenv}
RUSTWORKX_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
Expand Down

0 comments on commit 171aa31

Please sign in to comment.