How to use cppimport - 10 common examples

To help you get started, we’ve selected a few cppimport examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tbenthompson / cppimport / tests / test_cppimport.py View on Github external
import os
import io
import sys
import copy
import subprocess
import contextlib

import cppimport
import cppimport.build_module
import cppimport.templating
import cppimport.import_hook
cppimport.set_quiet(False)

@contextlib.contextmanager
def appended(filename, text):
    orig = open(filename, 'r').read()
    open(filename, 'a').write(text)
    try:
        yield
    finally:
        open(filename, 'w').write(orig)

def subprocess_check(test_code, returncode = 0):
    p = subprocess.Popen([
        'python', '-c', test_code
    ], cwd = os.path.dirname(__file__))
    p.wait()
    assert(p.returncode == returncode)
github molpopgen / fwdpy11 / tests / test_fitness_callback_polymorphism.py View on Github external
import cppimport
cppimport.force_rebuild()
cppimport.set_quiet(False)
snowdrift = cppimport.imp("snowdrift")
test_polymorphism = cppimport.imp("test_polymorphism")
import unittest
import fwdpy11.fitness as fp11w
import re


class testFitnessPolymorphism(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.w = [
            fp11w.SlocusAdditive(),
            fp11w.SlocusMult(),
            snowdrift.SlocusSnowdrift(0.2, -0.2, 1, -2)]
        self.v = test_polymorphism.test_callback_names(self.w)

    def testCallbackNameLen(self):
        self.assertEqual(len(self.v), 3)
github tbenthompson / cppimport / tests / test_cppimport.py View on Github external
def test_package_mymodule():
    mymodule = cppimport.imp("apackage.mymodule")
    module_tester(mymodule)
github molpopgen / fwdpy11 / tests / test_fitness_callback_polymorphism.py View on Github external
import cppimport
cppimport.force_rebuild()
cppimport.set_quiet(False)
snowdrift = cppimport.imp("snowdrift")
test_polymorphism = cppimport.imp("test_polymorphism")
import unittest
import fwdpy11.fitness as fp11w
import re


class testFitnessPolymorphism(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.w = [
            fp11w.SlocusAdditive(),
            fp11w.SlocusMult(),
            snowdrift.SlocusSnowdrift(0.2, -0.2, 1, -2)]
        self.v = test_polymorphism.test_callback_names(self.w)
github tbenthompson / cppimport / tests / test_cppimport.py View on Github external
def test_find_module_cpppath():
    mymodule_loc = cppimport.find.find_module_cpppath("mymodule")
    mymodule_dir = os.path.dirname(mymodule_loc)
    assert(os.path.basename(mymodule_loc) == "mymodule.cpp")

    apackage = cppimport.find.find_module_cpppath("apackage.mymodule")
    apackage_correct = os.path.join(mymodule_dir, 'apackage', 'mymodule.cpp')
    assert(apackage == apackage_correct)

    inner = cppimport.find.find_module_cpppath("apackage.inner.mymodule")
    inner_correct = os.path.join(mymodule_dir, 'apackage', 'inner', 'mymodule.cpp')
    assert(inner == inner_correct)
github tbenthompson / cppimport / tests / test_cppimport.py View on Github external
def test_find_module_cpppath():
    mymodule_loc = cppimport.find.find_module_cpppath("mymodule")
    mymodule_dir = os.path.dirname(mymodule_loc)
    assert(os.path.basename(mymodule_loc) == "mymodule.cpp")

    apackage = cppimport.find.find_module_cpppath("apackage.mymodule")
    apackage_correct = os.path.join(mymodule_dir, 'apackage', 'mymodule.cpp')
    assert(apackage == apackage_correct)

    inner = cppimport.find.find_module_cpppath("apackage.inner.mymodule")
    inner_correct = os.path.join(mymodule_dir, 'apackage', 'inner', 'mymodule.cpp')
    assert(inner == inner_correct)
github tbenthompson / cppimport / tests / test_cppimport.py View on Github external
def test_find_module_cpppath():
    mymodule_loc = cppimport.find.find_module_cpppath("mymodule")
    mymodule_dir = os.path.dirname(mymodule_loc)
    assert(os.path.basename(mymodule_loc) == "mymodule.cpp")

    apackage = cppimport.find.find_module_cpppath("apackage.mymodule")
    apackage_correct = os.path.join(mymodule_dir, 'apackage', 'mymodule.cpp')
    assert(apackage == apackage_correct)

    inner = cppimport.find.find_module_cpppath("apackage.inner.mymodule")
    inner_correct = os.path.join(mymodule_dir, 'apackage', 'inner', 'mymodule.cpp')
    assert(inner == inner_correct)
github tbenthompson / tectosaur / tests / fmm / test_run_cpp_tests.py View on Github external
def test_run_cpp_tests():
    from cppimport import cppimport
    cppimport('test_main').run_tests()
github tbenthompson / cppimport / tests / test_cppimport.py View on Github external
def test_import_hook():
    # Force rebuild to make sure we're not just reloading the already compiled
    # module from disk
    cppimport.force_rebuild(True)
    import hook_test
    cppimport.force_rebuild(False)
github tbenthompson / cppimport / tests / test_cppimport.py View on Github external
def test_import_hook():
    # Force rebuild to make sure we're not just reloading the already compiled
    # module from disk
    cppimport.force_rebuild(True)
    import hook_test
    cppimport.force_rebuild(False)