def build_wheels(py_envs=DEFAULT_PY_ENVS):

    # Install Chemfiles
    chfl_build_dir = os.path.join(ROOT_DIR, 'chfl-build')
    os.mkdir(chfl_build_dir)
    chfl_install_dir = os.path.join(ROOT_DIR, 'chfl')
    check_call([
        'cmake',
        '-DCMAKE_INSTALL_PREFIX:PATH=%s' % chfl_install_dir,
        '-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON',
        '-DCMAKE_BUILD_TYPE:STRING=Release', '-G',
        'Visual Studio 15 2017 Win64', '../chemfiles/'
    ],
               cwd=chfl_build_dir)
    check_call([
        'cmake', '--build', '.', '--target', 'install', '--config', 'Release'
    ],
               cwd=chfl_build_dir)

    for py_env in py_envs:
        python_executable, \
                python_include_dir, \
                python_library, \
                pip, \
                path = venv_paths(py_env)

        with push_env(PATH='%s%s%s' % (path, os.pathsep, os.environ['PATH'])):

            # Install dependencies
            requirements_file = os.path.join(REPO_DIR, 'requirements-dev.txt')
            if os.path.exists(requirements_file):
                check_call(
                    [pip, 'install', '--upgrade', '-r', requirements_file])
            check_call([pip, 'install', 'cmake'])
            check_call([pip, 'install', 'scikit_build'])

            build_type = 'Release'

            # Generate wheel
            check_call([
                python_executable,
                'setup.py',
                'bdist_wheel',
                '--build-type',
                build_type,
                '-G',
                'Visual Studio 15 2017 Win64',
                '--',
                '-DPYTHON_EXECUTABLE:FILEPATH=%s' % python_executable,
                '-DPYTHON_INCLUDE_DIR:PATH=%s' % python_include_dir,
                '-DPYTHON_LIBRARY:FILEPATH=%s' % python_library,
                '-DLEMON_EXTERNAL_CHEMFILES:BOOL=ON',
                '-DCHEMFILES_ROOT:PATH=%s' % os.path.join(chfl_install_dir),
                '-Dchemfiles_DIR=:PATH=%s' %
                os.path.join(chfl_install_dir, 'lib', 'cmake', 'chemfiles'),
                '-DLEMON_BUILD_PROGS:BOOL=OFF',
            ])
            # Cleanup
            check_call([python_executable, 'setup.py', 'clean'])
def test_wheels(python_env):
    (python_executable, python_include_dir, python_library, pip,
     ninja_executable, path) = venv_paths(python_env)
    check_call(
        [pip, 'install', 'itk', '--no-cache-dir', '--no-index', '-f', 'dist'])
    print('Wheel successfully installed.')
    check_call(
        [python_executable,
         os.path.join(ROOT_DIR, "docs/code/testDriver.py")])
    print('Documentation tests passed.')
Exemple #3
0
def build_wheel(python_version,
                single_wheel=False,
                cleanup=False,
                wheel_names=None):

    python_executable, \
            python_include_dir, \
            python_library, \
            pip, \
            ninja_executable, \
            path = venv_paths(python_version)

    with push_env(PATH="%s%s%s" % (path, os.pathsep, os.environ["PATH"])):

        # Install dependencies
        check_call([
            pip, "install", "--upgrade", "-r",
            os.path.join(ROOT_DIR, "requirements-dev.txt")
        ])

        build_type = "Release"
        source_path = "%s/%s-source" % (STANDALONE_DIR, PROJECT_NAME)
        build_path = "%s/%s-win_%s" % (ROOT_DIR, PROJECT_NAME, python_version)

        # Clean up previous invocations
        if cleanup and os.path.exists(build_path):
            shutil.rmtree(build_path)

        assert single_wheel is True

        print("#")
        print("# Build single %s wheel" % PROJECT_NAME)
        print("#")

        # Generate wheel
        check_call([
            python_executable, "setup.py", "bdist_wheel", "--build-type",
            build_type, "-G", "Ninja", "--",
            "-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable,
            "-DVTK_SOURCE_DIR:PATH=%s" % source_path,
            "-DVTK_BINARY_DIR:PATH=%s" % build_path,
            "-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable,
            "-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir,
            "-DPYTHON_LIBRARY:FILEPATH=%s" % python_library
        ])
        # Cleanup
        check_call([python_executable, "setup.py", "clean"])

        # Remove unnecessary files for building against PROJECT_NAME
        if cleanup:
            for root, _, file_list in os.walk(build_path):
                for filename in file_list:
                    extension = os.path.splitext(filename)[1]
                    if extension in [".cpp", ".obj", ".o"]:
                        os.remove(os.path.join(root, filename))
def build_wheels(py_envs=DEFAULT_PY_ENVS):
    for py_env in py_envs:
        (
            python_executable,
            python_include_dir,
            python_library,
            pip,
            ninja_executable,
            path
        ) = venv_paths(py_env)

        with push_env(PATH="%s%s%s" % (path, os.pathsep, os.environ["PATH"])):

            # Install dependencies
            requirements_file = os.path.join(ROOT_DIR, "requirements-dev.txt")
            if os.path.exists(requirements_file):
                check_call([pip, "install", "--upgrade", "-r", requirements_file])
            check_call([pip, "install", "cmake"])
            check_call([pip, "install", "scikit_build"])
            check_call([pip, "install", "ninja"])

            build_type = "Release"
            itk_build_path = os.path.abspath("%s/ITK-win_%s" % (IPP_DIR, py_env))
            print('ITKDIR: %s' % itk_build_path)
            vtk_build_path = os.path.abspath("%s/VTK-win_%s" % (VPP_DIR, py_env))
            print('VTKDIR: %s' % vtk_build_path)

            # Generate wheel
            check_call([
                python_executable,
                "setup.py", "bdist_wheel",
                "--build-type", build_type, "-G", "Ninja",
                "--",
                "-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable,
                "-DITK_DIR:PATH=%s" % itk_build_path,
                "-DVTK_DIR:PATH=%s" % vtk_build_path,
                "-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel",
                "-DSWIG_EXECUTABLE:FILEPATH=%s/Wrapping/Generators/SwigInterface/swig/bin/swig.exe" % itk_build_path,
                "-DBUILD_TESTING:BOOL=OFF",
                "-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable,
                "-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir,
                "-DPYTHON_LIBRARY:FILEPATH=%s" % python_library
            ])
            # Cleanup
            check_call([python_executable, "setup.py", "clean"])
def test_wheels(python_env):
    (
        python_executable,
        python_include_dir,
        python_library,
        pip,
        ninja_executable,
        path
    ) = venv_paths(python_env)
    check_call([pip, 'install', '--pre', 'itk', 'vtk'])
    check_call([pip, 'install', 'itk-vtkglue', '--no-cache-dir', '--no-index',
        '-f', 'dist'])
    print('Wheel successfully installed.')
    check_call([
        python_executable,
        os.path.join(ROOT_DIR, "test/itkImageToVTKImageFilterTest.py")
    ])
    print('Test passed.')
Exemple #6
0
def build_wheel(python_version, single_wheel=False,
                cleanup=False, wheel_names=None):

    python_executable, \
            python_include_dir, \
            python_library, \
            pip, \
            ninja_executable, \
            path = venv_paths(python_version)

    with push_env(PATH="%s%s%s" % (path, os.pathsep, os.environ["PATH"])):

        # Install dependencies
        check_call([pip, "install", "--upgrade",
                    "-r", os.path.join(ROOT_DIR, "requirements-dev.txt")])

        build_type = "Release"
        source_path = "%s/ITK-source" % STANDALONE_DIR
        build_path = "%s/ITK-win_%s" % (ROOT_DIR, python_version)
        setup_py_configure = os.path.join(SCRIPT_DIR, "setup_py_configure.py")

        # Clean up previous invocations
        if cleanup and os.path.exists(build_path):
            shutil.rmtree(build_path)

        if single_wheel:

            print("#")
            print("# Build single ITK wheel")
            print("#")

            # Configure setup.py
            check_call([python_executable, setup_py_configure, "itk"])

            # Generate wheel
            check_call([
                python_executable,
                "setup.py", "bdist_wheel",
                "--build-type", build_type, "-G", "Ninja",
                "--",
                "-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable,
                "-DITK_SOURCE_DIR:PATH=%s" % source_path,
                "-DITK_BINARY_DIR:PATH=%s" % build_path,
                "-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable,
                "-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir,
                "-DPYTHON_LIBRARY:FILEPATH=%s" % python_library
            ])
            # Cleanup
            check_call([python_executable, "setup.py", "clean"])

        else:

            print("#")
            print("# Build multiple ITK wheels")
            print("#")

            build_wrapped_itk(
                ninja_executable, build_type, source_path, build_path,
                python_executable, python_include_dir, python_library)

            # Build wheels
            if wheel_names is None:
                with open(os.path.join(SCRIPT_DIR, "WHEEL_NAMES.txt"), "r") \
                        as content:
                    wheel_names = [wheel_name.strip()
                                   for wheel_name in content.readlines()]

            for wheel_name in wheel_names:
                # Configure setup.py
                check_call([
                    python_executable, setup_py_configure, wheel_name])

                # Generate wheel
                check_call([
                    python_executable,
                    "setup.py", "bdist_wheel",
                    "--build-type", build_type, "-G", "Ninja",
                    "--",
                    "-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable,
                    "-DITK_SOURCE_DIR:PATH=%s" % source_path,
                    "-DITK_BINARY_DIR:PATH=%s" % build_path,
                    "-DITKPythonPackage_ITK_BINARY_REUSE:BOOL=ON",
                    "-DITKPythonPackage_WHEEL_NAME:STRING=%s" % wheel_name,
                    "-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable,
                    "-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir,
                    "-DPYTHON_LIBRARY:FILEPATH=%s" % python_library
                ])

                # Cleanup
                if cleanup:
                    check_call([python_executable, "setup.py", "clean"])

        # Remove unnecessary files for building against ITK
        if cleanup:
            for root, _, file_list in os.walk(build_path):
                for filename in file_list:
                    extension = os.path.splitext(filename)[1]
                    if extension in [".cpp", ".xml", ".obj", ".o"]:
                        os.remove(os.path.join(root, filename))
            shutil.rmtree(
                os.path.join(build_path, "Wrapping", "Generators", "CastXML"))
Exemple #7
0
def build_wheels(py_envs=DEFAULT_PY_ENVS):

    # Install Eigen
    eigen_build_dir = os.path.join(ROOT_DIR, 'eigen-build')
    os.mkdir(eigen_build_dir)
    eigen_install_dir = os.path.join(ROOT_DIR, 'eigen')
    check_call([
        'cmake',
        '-DCMAKE_INSTALL_PREFIX:PATH=%s' % eigen_install_dir,
        '../eigen-eigen-b3f3d4950030/'
    ],
               cwd=eigen_build_dir)
    check_call(['cmake', '--build', '.', '--target', 'install'],
               cwd=eigen_build_dir)

    for py_env in py_envs:
        python_executable, \
                python_include_dir, \
                python_library, \
                pip, \
                ninja_executable, \
                path = venv_paths(py_env)

        with push_env(PATH='%s%s%s' % (path, os.pathsep, os.environ['PATH'])):

            # Install dependencies
            requirements_file = os.path.join(REPO_DIR, 'requirements-dev.txt')
            if os.path.exists(requirements_file):
                check_call(
                    [pip, 'install', '--upgrade', '-r', requirements_file])
            check_call([pip, 'install', 'cmake'])
            check_call([pip, 'install', 'scikit_build'])
            check_call([pip, 'install', 'ninja'])

            build_type = 'Release'

            # Install pybind
            source_dir = os.path.join(ROOT_DIR, 'pybind11-2.2.4')
            build_dir = os.path.join(ROOT_DIR, 'pybind11-build')
            shutil.rmtree(build_dir, ignore_errors=True)
            os.mkdir(build_dir)
            install_dir = os.path.join(ROOT_DIR, 'pybind11-install')
            shutil.rmtree(install_dir, ignore_errors=True)
            os.mkdir(install_dir)

            check_call([
                'cmake', '-GVisual Studio 14 2015 Win64',
                '-DPYTHON_EXECUTABLE:PATH=%s' % python_executable,
                '-DPYBIND11_TEST:BOOL=FALSE',
                '-DCMAKE_INSTALL_PREFIX:PATH=%s' % install_dir, source_dir
            ],
                       cwd=build_dir)

            check_call(['cmake', '--build', '.', '--target', 'install'],
                       cwd=build_dir)

            # Generate wheel
            check_call([
                python_executable, 'setup.py', 'bdist_wheel', '--build-type',
                build_type, '-G', 'Ninja', '--',
                '-DCMAKE_MAKE_PROGRAM:FILEPATH=%s' % ninja_executable,
                '-DBUILD_TESTING:BOOL=OFF',
                '-DPYTHON_EXECUTABLE:FILEPATH=%s' % python_executable,
                '-DPYTHON_INCLUDE_DIR:PATH=%s' % python_include_dir,
                '-DPYTHON_LIBRARY:FILEPATH=%s' % python_library,
                '-Dpybind11_DIR:PATH=%s' %
                os.path.join(install_dir, 'share', 'cmake', 'pybind11'),
                '-DEIGEN3_INCLUDE_DIR:PATH=%s' %
                os.path.join(eigen_install_dir, 'include', 'eigen3')
            ])
            # Cleanup
            check_call([python_executable, 'setup.py', 'clean'])
Exemple #8
0
def rename_wheel_init(py_env, filepath):
    """
    Rename module __init__ file in wheel.
    This is required to prevent modules to override ITK's __init__ file on install.
    If the module ships its own __init__ file, it is automatically renamed to
    __init_{module_name}__ by this function. The renamed __init__ file will be executed
    by ITK's __init__ file when loading ITK.
    """
    python_executable, python_include_dir, python_library, pip, ninja_executable, path = venv_paths(
        py_env)

    # Get module info
    install_and_import("pkginfo")
    w = pkginfo.Wheel(filepath)
    module_name = w.name.split("itk-")[-1]
    module_version = w.version

    dist_dir = os.path.dirname(filepath)
    wheel_dir = os.path.join(dist_dir,
                             "itk_" + module_name + "-" + module_version)
    init_dir = os.path.join(wheel_dir, "itk")
    init_file = os.path.join(init_dir, "__init__.py")

    # Unpack wheel and rename __init__ file if it exists.
    check_call(
        [python_executable, "-m", "wheel", "unpack", filepath, "-d", dist_dir])
    if os.path.isfile(init_file):
        shutil.move(init_file,
                    os.path.join(init_dir, "__init_" + module_name + "__.py"))
    # Pack wheel and clean wheel folder
    check_call(
        [python_executable, "-m", "wheel", "pack", wheel_dir, "-d", dist_dir])
    shutil.rmtree(wheel_dir)
def build_wheels(py_envs=DEFAULT_PY_ENVS):

    # Install Eigen
    eigen_build_dir = os.path.join(ROOT_DIR, 'eigen-build')
    os.mkdir(eigen_build_dir)
    eigen_install_dir = os.path.join(ROOT_DIR, 'eigen')
    check_call([
        'cmake', '-DCMAKE_INSTALL_PREFIX:PATH=%s' % eigen_install_dir,
        '../eigen-eigen-b3f3d4950030/'], cwd=eigen_build_dir)
    check_call(['cmake',  '--build',  '.',  '--target', 'install'], cwd=eigen_build_dir)


    for py_env in py_envs:
        python_executable, \
                python_include_dir, \
                python_library, \
                pip, \
                ninja_executable, \
                path = venv_paths(py_env)

        with push_env(PATH='%s%s%s' % (path, os.pathsep, os.environ['PATH'])):

            # Install dependencies
            requirements_file = os.path.join(REPO_DIR, 'requirements-dev.txt')
            if os.path.exists(requirements_file):
                check_call([pip, 'install', '--upgrade', '-r', requirements_file])
            check_call([pip, 'install', 'cmake'])
            check_call([pip, 'install', 'scikit_build'])
            check_call([pip, 'install', 'ninja'])

            build_type = 'Release'

            # Install pybind
            source_dir = os.path.join(ROOT_DIR, 'pybind11-2.2.4')
            build_dir = os.path.join(ROOT_DIR, 'pybind11-build')
            shutil.rmtree(build_dir, ignore_errors=True)
            os.mkdir(build_dir)
            install_dir = os.path.join(ROOT_DIR, 'pybind11-install')
            shutil.rmtree(install_dir, ignore_errors=True)
            os.mkdir(install_dir)

            check_call(['cmake',
                        '-GVisual Studio 14 2015 Win64',
                       '-DPYTHON_EXECUTABLE:PATH=%s' % python_executable,
                       '-DPYBIND11_TEST:BOOL=FALSE',
                       '-DCMAKE_INSTALL_PREFIX:PATH=%s' % install_dir,
                       source_dir], cwd=build_dir)

            check_call(['cmake',  '--build', '.', '--target', 'install'], cwd=build_dir)

            # Generate wheel
            check_call([
                python_executable,
                'setup.py', 'bdist_wheel',
                '--build-type', build_type, '-G', 'Ninja',
                '--',
                '-DCMAKE_MAKE_PROGRAM:FILEPATH=%s' % ninja_executable,
                '-DBUILD_TESTING:BOOL=OFF',
                '-DPYTHON_EXECUTABLE:FILEPATH=%s' % python_executable,
                '-DPYTHON_INCLUDE_DIR:PATH=%s' % python_include_dir,
                '-DPYTHON_LIBRARY:FILEPATH=%s' % python_library,
                '-Dpybind11_DIR:PATH=%s' % os.path.join(install_dir, 'share', 'cmake', 'pybind11'),
                '-DEIGEN3_INCLUDE_DIR:PATH=%s' % os.path.join(eigen_install_dir, 'include','eigen3')
            ])
            # Cleanup
            check_call([python_executable, 'setup.py', 'clean'])