From 3c649cf91d831bcc066ecc141975270fe7a46846 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 30 Jul 2014 22:28:03 -0300 Subject: [PATCH] guarding scripts with __main__ and doc changes tox-flakes environment tries to import the modules for checking, and that may fail because of its dependencies --HG-- branch : cx_freeze-support --- doc/en/example/simple.txt | 3 ++- testing/cx_freeze/runtests_setup.py | 19 ++++++++++--------- testing/cx_freeze/tox_run.py | 13 +++++++------ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/doc/en/example/simple.txt b/doc/en/example/simple.txt index caaf1fb56..e42d81eec 100644 --- a/doc/en/example/simple.txt +++ b/doc/en/example/simple.txt @@ -703,7 +703,8 @@ must declare them explicitly by using ``pytest.cx_freeze_support.includes()``:: import pytest setup( - name="runtests", + name="app_main", + executables=[Executable("app_main.py")], options={"build_exe": { 'includes': pytest.cx_freeze_support.includes()} diff --git a/testing/cx_freeze/runtests_setup.py b/testing/cx_freeze/runtests_setup.py index 56b39205d..fa2373890 100644 --- a/testing/cx_freeze/runtests_setup.py +++ b/testing/cx_freeze/runtests_setup.py @@ -1,14 +1,15 @@ """ Sample setup.py script that generates an executable with pytest runner embedded. """ -from cx_Freeze import setup, Executable -import pytest +if __name__ == '__main__': + from cx_Freeze import setup, Executable + import pytest -setup( - name="runtests", - version="0.1", - description="exemple of how embedding py.test into an executable using cx_freeze", - executables=[Executable("runtests_script.py")], - options={"build_exe": {'includes': pytest.cx_freeze_support.includes()}}, -) + setup( + name="runtests", + version="0.1", + description="exemple of how embedding py.test into an executable using cx_freeze", + executables=[Executable("runtests_script.py")], + options={"build_exe": {'includes': pytest.cx_freeze_support.includes()}}, + ) diff --git a/testing/cx_freeze/tox_run.py b/testing/cx_freeze/tox_run.py index 95ac1b858..e8df2684b 100644 --- a/testing/cx_freeze/tox_run.py +++ b/testing/cx_freeze/tox_run.py @@ -5,10 +5,11 @@ directory. .. note:: somehow calling "build/runtests_script" directly from tox doesn't seem to work (at least on Windows). """ -import os -import sys +if __name__ == '__main__': + import os + import sys -executable = os.path.join(os.getcwd(), 'build', 'runtests_script') -if sys.platform.startswith('win'): - executable += '.exe' -sys.exit(os.system('%s tests' % executable)) \ No newline at end of file + executable = os.path.join(os.getcwd(), 'build', 'runtests_script') + if sys.platform.startswith('win'): + executable += '.exe' + sys.exit(os.system('%s tests' % executable)) \ No newline at end of file