Exemple #1
0
def build_wrapped_itk(ninja_executable, build_type, source_path, build_path,
                      python_executable, python_include_dir, python_library):

    try:
        # Because of python issue #14243, we set "delete=False" and
        # delete manually after process execution.
        script_file = tempfile.NamedTemporaryFile(delete=False, suffix=".py")
        script_file.write(
            bytearray(
                textwrap.dedent("""
            import json
            from skbuild.platform_specifics.windows import WindowsPlatform
            # Instantiate
            build_platform = WindowsPlatform()
            generator = build_platform.default_generators[0]
            assert generator.name == "Ninja"
            print(json.dumps(generator.env))
            """

                                # noqa: E501
                                ),
                "utf-8"))
        script_file.file.flush()
        output = check_output([python_executable, script_file.name])
        build_env = json.loads(output.decode("utf-8").strip())
    finally:
        script_file.close()
        os.remove(script_file.name)

    tbb_dir = os.path.join(ROOT_DIR, 'oneTBB-prefix', 'lib', 'cmake', 'TBB')

    # Build ITK python
    with push_dir(directory=build_path, make_directory=True), \
            push_env(**build_env):

        check_call([
            "cmake",
            "-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable,
            "-DCMAKE_BUILD_TYPE:STRING=%s" % build_type,
            "-DITK_SOURCE_DIR:PATH=%s" % source_path,
            "-DITK_BINARY_DIR:PATH=%s" % build_path,
            "-DBUILD_TESTING:BOOL=OFF",
            "-DPython3_EXECUTABLE:FILEPATH=%s" % python_executable,
            "-DITK_WRAP_unsigned_short:BOOL=ON", "-DITK_WRAP_double:BOOL=ON",
            "-DITK_WRAP_complex_double:BOOL=ON",
            "-DITK_WRAP_IMAGE_DIMS:STRING=2;3;4",
            "-DPython3_INCLUDE_DIR:PATH=%s" % python_include_dir,
            "-DPython3_INCLUDE_DIRS:PATH=%s" % python_include_dir,
            "-DPython3_LIBRARY:FILEPATH=%s" % python_library,
            "-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel",
            "-DWRAP_ITK_INSTALL_COMPONENT_PER_MODULE:BOOL=ON",
            "-DPY_SITE_PACKAGES_PATH:PATH=.", "-DITK_LEGACY_SILENT:BOOL=ON",
            "-DITK_WRAP_PYTHON:BOOL=ON", "-DITK_WRAP_DOC:BOOL=ON",
            "-DDOXYGEN_EXECUTABLE:FILEPATH=C:/P/doxygen/doxygen.exe",
            "-DModule_ITKTBB:BOOL=ON",
            "-DTBB_DIR:PATH=%s" % tbb_dir, "-G", "Ninja", source_path
        ])
        check_call([ninja_executable])
Exemple #2
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 build_wheel(python_version, cleanup=False):

    py_exe, \
    py_inc_dir, \
    py_lib, \
    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'
        build_path = "%s/%s-osx_%s" % (ROOT_DIR, PROJECT_NAME, python_version)
        osx_target = "10.9"

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

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

        # Generate wheel
        check_call([
            py_exe, "setup.py", "bdist_wheel", "--build-type", build_type,
            "-G", "Ninja", "--plat-name",
            "macosx-%s-x86_64" % osx_target, "--",
            "-DPYTHON_EXECUTABLE:FILEPATH=%s" % py_exe,
            "-DPYTHON_INCLUDE_DIR:PATH=%s" % py_inc_dir,
            "-DPYTHON_LIBRARY:FILEPATH=%s" % py_lib
        ])

        # Cleanup
        check_call([py_exe, "setup.py", "clean"])
Exemple #5
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 #6
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'])
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'])