def test_make(configure_with_cmake_source_dir, capfd):
    tmp_dir = _tmpdir('test_make')
    with push_dir(str(tmp_dir)):

        src_dir = tmp_dir.ensure('SRC', dir=1)
        src_dir.join('CMakeLists.txt').write(textwrap.dedent(
            """
            cmake_minimum_required(VERSION 3.5.0)
            project(foobar NONE)
            file(WRITE "${CMAKE_BINARY_DIR}/foo.txt" "# foo")
            install(FILES "${CMAKE_BINARY_DIR}/foo.txt" DESTINATION ".")
            install(CODE "message(STATUS \\"Project has been installed\\")")
            message(STATUS "CMAKE_SOURCE_DIR:${CMAKE_SOURCE_DIR}")
            message(STATUS "CMAKE_BINARY_DIR:${CMAKE_BINARY_DIR}")
            """
        ))
        src_dir.ensure(CMAKE_BUILD_DIR(), dir=1)

        with push_dir(str(src_dir)
                      if not configure_with_cmake_source_dir
                      else str(tmp_dir.ensure('BUILD', dir=1))):
            cmkr = CMaker()
            config_kwargs = {}
            if configure_with_cmake_source_dir:
                config_kwargs['cmake_source_dir'] = str(src_dir)
            env = cmkr.configure(**config_kwargs)
            cmkr.make(env=env)

        messages = ["Project has been installed"]

        if configure_with_cmake_source_dir:
            messages += [
                "/SRC",
                "/BUILD/{}".format(to_unix_path(CMAKE_BUILD_DIR())),
                "/BUILD/{}/./foo.txt".format(to_unix_path(CMAKE_INSTALL_DIR()))
            ]
        else:
            messages += [
                "/SRC",
                "/SRC/{}".format(to_unix_path(CMAKE_BUILD_DIR())),
                "/SRC/{}/./foo.txt".format(to_unix_path(CMAKE_INSTALL_DIR())),
            ]

        out, _ = capfd.readouterr()
        for message in messages:
            assert message in out
def test_hello_cleans(capfd):
    with push_dir():

        tmp_dir = _tmpdir("test_hello_cleans")

        _copy_dir(tmp_dir, os.path.join(SAMPLES_DIR, "hello-cpp"))

        @project_setup_py_test("hello-cpp", ["build"], tmp_dir=tmp_dir)
        def run_build():
            pass

        @project_setup_py_test("hello-cpp", ["clean"], tmp_dir=tmp_dir)
        def run_clean():
            pass

        # Check that a project can be cleaned twice in a row
        run_build()
        print("<<-->>")
        run_clean()
        print("<<-->>")
        run_clean()

    _, clean1_out, clean2_out = \
        capfd.readouterr()[0].split('<<-->>')

    clean1_out = clean1_out.strip()
    clean2_out = clean2_out.strip()

    assert "running clean" == clean1_out.splitlines()[0]
    assert "removing '{}'".format(
        CMAKE_INSTALL_DIR()) == clean1_out.splitlines()[1]
    assert "removing '{}'".format(
        CMAKE_BUILD_DIR()) == clean1_out.splitlines()[2]
    assert "removing '{}'".format(SKBUILD_DIR()) == clean1_out.splitlines()[3]

    assert "running clean" == clean2_out
Exemple #3
0
setup_requires = []
try:
    cmake_version = LegacyVersion(get_cmake_version())
    if cmake_version < LegacyVersion("3.5") or cmake_version >= LegacyVersion(
            "3.15"):
        setup_requires.append('cmake<3.15')
except SKBuildError:
    setup_requires.append('cmake<3.15')

# If you want to re-build the cython cpp file (DracoPy.cpp), run:
# cython --cplus -3 -I./_skbuild/linux-x86_64-3.7/cmake-install/include/draco/ ./src/TrakoDracoPy.pyx
# Replace "linux-x86_64-3.6" with the directory under _skbuild in your system
# Draco must already be built/setup.py already be run before running the above command

src_dir = './src'
lib_dir = os.path.abspath(os.path.join(CMAKE_INSTALL_DIR(), 'lib/'))
cmake_args = []
if sys.platform == 'darwin':
    plat_name = skbuild_plat_name()
    sep = [pos for pos, char in enumerate(plat_name) if char == '-']
    assert len(sep) == 2
    cmake_args = [
        '-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=' + plat_name[sep[0] + 1:sep[1]],
        '-DCMAKE_OSX_ARCHITECTURES:STRING=' + plat_name[sep[1] + 1:]
    ]
    library_link_args = [
        '-l{0}'.format(lib) for lib in ('dracoenc', 'draco', 'dracodec')
    ]
else:
    library_link_args = [
        '-l:{0}'.format(lib)
Exemple #4
0
class CleanUp(set_build_base_mixin, new_style(_clean)):
    """Custom implementation of ``clean`` setuptools command.

    Overriding clean in order to get rid if "dist" folder and etc
    """

    skroot = dirname(SKBUILD_DIR())

    CLEANFOLDERS = (
        CMAKE_INSTALL_DIR(),
        CMAKE_BUILD_DIR(),
        SKBUILD_DIR(),
        skroot,
        "TMP",
        "__pycache__",
        "pip-wheel-metadata",
        ".eggs",
        "dist",
        "sdist",
        "wheel",
        ".pytest_cache",
        "docs/apiref",
        "docs/_build",
        "docs/_static",
        "docs/_templates",
        "htmlcov",
    )

    CLEANFOLDERSRECURSIVE = ["__pycache__", "_tmp_*", "xtgeo.egg-info"]
    CLEANFILESRECURSIVE = ["*.pyc", "*.pyo", ".coverage", "coverage.xml"]

    CLEANFILES = glob("src/xtgeo/cxtgeo/cxtgeo*")
    CLEANFILES.extend(glob("src/xtgeo/cxtgeo/_cxtgeo*"))

    @staticmethod
    def ffind(pattern, path):
        result = []
        for root, dirs, files in os.walk(path):
            for name in files:
                if fnmatch.fnmatch(name, pattern):
                    result.append(os.path.join(root, name))
        return result

    @staticmethod
    def dfind(pattern, path):
        result = []
        for root, dirs, files in os.walk(path):
            for name in dirs:
                if fnmatch.fnmatch(name, pattern):
                    result.append(os.path.join(root, name))
        return result

    def run(self):
        """After calling the super class implementation, this function removes
        the directories specific to scikit-build ++."""
        super(CleanUp, self).run()

        for dir_ in CleanUp.CLEANFOLDERS:
            if exists(dir_):
                print("Removing: {}".format(dir_))
            if not self.dry_run and exists(dir_):
                rmtree(dir_)

        for dir_ in CleanUp.CLEANFOLDERSRECURSIVE:
            for pd in self.dfind(dir_, "."):
                print("Remove folder {}".format(pd))
                rmtree(pd)

        for fil_ in CleanUp.CLEANFILESRECURSIVE:
            for pf in self.ffind(fil_, "."):
                print("Remove file {}".format(pf))
                os.unlink(pf)

        for fil_ in CleanUp.CLEANFILES:
            if exists(fil_):
                print("Removing: {}".format(fil_))
            if not self.dry_run and exists(fil_):
                os.remove(fil_)
Exemple #5
0
# read the version number from the library
pattern = r"[0-9]\.[0-9]\.[0-9]"
version = None
with open('./bindings/rascal/__init__.py', 'r') as fp:
    for line in fp.readlines():
        if '__version__' in line:
            version = re.findall(pattern, line)[0]
if version is None:
    raise ValueError("Version number not found.")

with open('./requirements_pip.txt', 'r') as fp:
    requirements = list(filter(lambda x: '#' not in x, (line.strip() for line in fp)))

setup(
    name="rascal",
    version=version,
    description="""A versatile and scalable computation of representations of
atomic structures for machine learning.""",
    author='librascal developers',
    license="LGPL-3.0-or-later",
    cmake_args=[
      '-DINSTALL_PATH:STRING='+join(os.getcwd(),CMAKE_INSTALL_DIR()),
      '-DBUILD_EXAMPLES:BOOL=OFF'
    ],
    package_dir={"": "bindings"},
    packages=find_packages(where='bindings'),
    install_requires=requirements,
    # include_package_data=True,
    package_data={'': ['lib/librascal.*']},
    zip_safe=False
)
Exemple #6
0
def test_cmake_install_into_pure_package(with_cmake_source_dir, capsys):

    # -------------------------------------------------------------------------
    # "SOURCE" tree layout:
    #
    # (1) with_cmake_source_dir == 0
    #
    # ROOT/
    #
    #     CMakeLists.txt
    #     setup.py
    #
    #     fruits/
    #         __init__.py
    #
    #
    # (2) with_cmake_source_dir == 1
    #
    # ROOT/
    #
    #     setup.py
    #
    #     fruits/
    #         __init__.py
    #
    #     src/
    #
    #         CMakeLists.txt
    #
    # -------------------------------------------------------------------------
    # "BINARY" distribution layout:
    #
    # ROOT/
    #
    #     fruits/
    #
    #         __init__.py
    #         apple.py
    #         banana.py
    #
    #             data/
    #
    #                 apple.dat
    #                 banana.dat
    #

    tmp_dir = _tmpdir('cmake_install_into_pure_package')

    cmake_source_dir = 'src' if with_cmake_source_dir else ''

    tmp_dir.join('setup.py').write(
        textwrap.dedent("""
        from skbuild import setup
        setup(
            name="test_py_modules_keyword",
            version="1.2.3",
            description="a package testing use of py_modules keyword",
            author='The scikit-build team',
            license="MIT",
            packages=['fruits'],
            cmake_install_dir='fruits',
            cmake_source_dir='{cmake_source_dir}',
        )
        """.format(cmake_source_dir=cmake_source_dir)))

    cmake_src_dir = tmp_dir.ensure(cmake_source_dir, dir=1)
    cmake_src_dir.join('CMakeLists.txt').write(
        textwrap.dedent("""
        cmake_minimum_required(VERSION 3.5.0)
        project(test NONE)
        file(WRITE "${CMAKE_BINARY_DIR}/apple.py" "# apple.py")
        file(WRITE "${CMAKE_BINARY_DIR}/banana.py" "# banana.py")
        install(
            FILES
                "${CMAKE_BINARY_DIR}/apple.py"
                "${CMAKE_BINARY_DIR}/banana.py"
            DESTINATION "."
            )
        file(WRITE "${CMAKE_BINARY_DIR}/apple.dat" "# apple.dat")
        file(WRITE "${CMAKE_BINARY_DIR}/banana.dat" "# banana.dat")
        install(
            FILES
                "${CMAKE_BINARY_DIR}/apple.dat"
                "${CMAKE_BINARY_DIR}/banana.dat"
            DESTINATION "data"
            )
        """))

    tmp_dir.ensure('fruits/__init__.py')

    with execute_setup_py(tmp_dir, ['build'], disable_languages_test=True):
        pass

    messages = [
        "copying {}/{} -> "
        "{}/setuptools/lib".format(CMAKE_INSTALL_DIR(), module, SKBUILD_DIR())
        for module in [
            'fruits/__init__.py',
            'fruits/apple.py',
            'fruits/banana.py',
            'fruits/data/apple.dat',
            'fruits/data/banana.dat',
        ]
    ]

    out, _ = capsys.readouterr()
    for message in messages:
        assert to_platform_path(message) in out
Exemple #7
0
def test_setup_inputs(has_cmake_package, has_cmake_module, has_hybrid_package,
                      has_pure_package, has_pure_module, with_package_base,
                      mocker):
    """This test that a project can have a package with some modules
    installed using setup.py and some other modules installed using CMake.
    """

    tmp_dir = _tmpdir('test_setup_inputs')

    package_base = 'to/the/base' if with_package_base else ''
    package_base_dir = package_base + '/' if package_base else ''
    cmake_source_dir = package_base

    if cmake_source_dir and (has_cmake_package or has_cmake_module):
        pytest.skip(
            "unsupported configuration: "
            "python package fully generated by CMake does *NOT* work. "
            "At least __init__.py should be in the project source tree")

    # -------------------------------------------------------------------------
    # Here is the "SOURCE" tree layout:
    #
    # ROOT/
    #
    #     setup.py
    #
    #     [<base>/]
    #
    #         pureModule.py
    #
    #         pure/
    #             __init__.py
    #             pure.py
    #
    #             data/
    #                 pure.dat
    #
    #     [<cmake_src_dir>/]
    #
    #         hybrid/
    #             CMakeLists.txt
    #             __init__.py
    #             hybrid_pure.dat
    #             hybrid_pure.py
    #
    #             data/
    #                 hybrid_data_pure.dat
    #
    #             hybrid_2/
    #                 __init__.py
    #                 hybrid_2_pure.py
    #
    #             hybrid_2_pure/
    #                 __init__.py
    #                 hybrid_2_pure_1.py
    #                 hybrid_2_pure_2.py
    #
    #
    # -------------------------------------------------------------------------
    # and here is the "BINARY" distribution layout:
    #
    # The comment "CMake" or "Setuptools" indicates which tool is responsible
    # for placing the file in the tree used to create the binary distribution.
    #
    # ROOT/
    #
    #     cmakeModule.py                 # CMake
    #
    #     cmake/
    #         __init__.py                # CMake
    #         cmake.py                   # CMake
    #
    #     hybrid/
    #         hybrid_cmake.dat           # CMake
    #         hybrid_cmake.py            # CMake
    #         hybrid_pure.dat            # Setuptools
    #         hybrid_pure.py             # Setuptools
    #
    #         data/
    #             hybrid_data_pure.dat   # CMake or Setuptools
    #             hybrid_data_cmake.dat  # CMake                  *NO TEST*
    #
    #         hybrid_2/
    #             __init__.py            # CMake or Setuptools
    #             hybrid_2_pure.py       # CMake or Setuptools
    #             hybrid_2_cmake.py      # CMake
    #
    #         hybrid_2_pure/
    #             __init__.py            # CMake or Setuptools
    #             hybrid_2_pure_1.py     # CMake or Setuptools
    #             hybrid_2_pure_2.py     # CMake or Setuptools
    #
    #     pureModule.py                  # Setuptools
    #
    #     pure/
    #         __init__.py                # Setuptools
    #         pure.py                    # Setuptools
    #
    #         data/
    #             pure.dat               # Setuptools

    tmp_dir.join('setup.py').write(
        textwrap.dedent("""
        from skbuild import setup
        #from setuptools import setup
        setup(
            name="test_hybrid_project",
            version="1.2.3",
            description=("an hybrid package mixing files installed by both "
                        "CMake and setuptools"),
            author='The scikit-build team',
            license="MIT",
            cmake_source_dir='{cmake_source_dir}',
            cmake_install_dir='{cmake_install_dir}',
            # Arbitrary order of packages
            packages=[
        {p_off}    'pure',
        {h_off}    'hybrid.hybrid_2',
        {h_off}    'hybrid',
        {c_off}    'cmake',
        {p_off}    'hybrid.hybrid_2_pure',
            ],
            py_modules=[
        {pm_off}   '{package_base}pureModule',
        {cm_off}   '{package_base}cmakeModule',
            ],
            package_data={{
        {p_off}        'pure': ['data/pure.dat'],
        {h_off}        'hybrid': ['hybrid_pure.dat', 'data/hybrid_data_pure.dat'],
            }},
            # Arbitrary order of package_dir
            package_dir = {{
        {p_off}    'hybrid.hybrid_2_pure': '{package_base}hybrid/hybrid_2_pure',
        {p_off}    'pure': '{package_base}pure',
        {h_off}    'hybrid': '{package_base}hybrid',
        {h_off}    'hybrid.hybrid_2': '{package_base}hybrid/hybrid_2',
        {c_off}    'cmake': '{package_base}cmake',
            }}
        )
        """.format(cmake_source_dir=cmake_source_dir,
                   cmake_install_dir=package_base,
                   package_base=package_base_dir,
                   c_off='' if has_cmake_package else '#',
                   cm_off='' if has_cmake_module else '#',
                   h_off='' if has_hybrid_package else '#',
                   p_off='' if has_pure_package else '#',
                   pm_off='' if has_pure_module else '#')))

    src_dir = tmp_dir.ensure(package_base, dir=1)

    src_dir.join('CMakeLists.txt').write(
        textwrap.dedent("""
        cmake_minimum_required(VERSION 3.5.0)
        project(hybrid NONE)
        set(build_dir ${{CMAKE_BINARY_DIR}})

        {c_off} file(WRITE ${{build_dir}}/__init__.py "")
        {c_off} file(WRITE ${{build_dir}}/cmake.py "")
        {c_off} install(
        {c_off}     FILES
        {c_off}         ${{build_dir}}/__init__.py
        {c_off}         ${{build_dir}}/cmake.py
        {c_off}     DESTINATION cmake
        {c_off}     )

        {cm_off} file(WRITE ${{build_dir}}/cmakeModule.py "")
        {cm_off} install(
        {cm_off}     FILES ${{build_dir}}/cmakeModule.py
        {cm_off}     DESTINATION .)

        {h_off} file(WRITE ${{build_dir}}/hybrid_cmake.dat "")
        {h_off} install(
        {h_off}     FILES ${{build_dir}}/hybrid_cmake.dat
        {h_off}     DESTINATION hybrid)

        {h_off} file(WRITE ${{build_dir}}/hybrid_cmake.py "")
        {h_off} install(
        {h_off}     FILES ${{build_dir}}/hybrid_cmake.py
        {h_off}     DESTINATION hybrid)

        {h_off} file(WRITE ${{build_dir}}/hybrid_data_cmake.dat "")
        {h_off} install(
        {h_off}     FILES ${{build_dir}}/hybrid_data_cmake.dat
        {h_off}     DESTINATION hybrid/data)

        {h_off} file(WRITE ${{build_dir}}/hybrid_2_cmake.py "")
        {h_off} install(
        {h_off}     FILES ${{build_dir}}/hybrid_2_cmake.py
        {h_off}     DESTINATION hybrid/hybrid_2)

        install(CODE "message(STATUS \\\"Installation complete\\\")")
        """.format(c_off='' if has_cmake_package else '#',
                   cm_off='' if has_cmake_module else '#',
                   h_off='' if has_hybrid_package else '#',
                   p_off='' if has_pure_package else '#')))

    # List path types: 'c', 'cm', 'h', 'p' or 'pm'
    try:
        path_types = list(
            zip(*filter(lambda i: i[1], [(
                'c', has_cmake_package), (
                    'cm', has_cmake_module), (
                        'h', has_hybrid_package), (
                            'p', has_pure_package), ('pm',
                                                     has_pure_module)])))[0]
    except IndexError:
        path_types = []

    def select_paths(annotated_paths):
        """Return a filtered list paths considering ``path_types``.

        `annotated_paths`` is list of tuple ``(type, path)`` where type
        is either `c`, 'cm', `h`, `p` or 'pm'.

        """
        return filter(lambda i: i[0] in path_types, annotated_paths)

    # Commented paths are the one expected to be installed by CMake. For
    # this reason, corresponding files should NOT be created in the source
    # tree.
    for (_type, path) in select_paths([
            # ('c', 'cmake/__init__.py'),
            # ('c', 'cmake/cmake.py'),

            # ('cm', 'cmakeModule.py'),
        ('h', 'hybrid/__init__.py'),
            # ('h', 'hybrid/hybrid_cmake.dat'),
            # ('h', 'hybrid/hybrid_cmake.py'),
        ('h', 'hybrid/hybrid_pure.dat'),
        ('h', 'hybrid/hybrid_pure.py'),

            # ('h', 'hybrid/data/hybrid_data_cmake.dat'),
        ('h', 'hybrid/data/hybrid_data_pure.dat'),
        ('h', 'hybrid/hybrid_2/__init__.py'),
            # ('h', 'hybrid/hybrid_2/hybrid_2_cmake.py'),
        ('h', 'hybrid/hybrid_2/hybrid_2_pure.py'),
        ('p', 'hybrid/hybrid_2_pure/__init__.py'),
        ('p', 'hybrid/hybrid_2_pure/hybrid_2_pure_1.py'),
        ('p', 'hybrid/hybrid_2_pure/hybrid_2_pure_2.py'),
        ('pm', 'pureModule.py'),
        ('p', 'pure/__init__.py'),
        ('p', 'pure/pure.py'),
        ('p', 'pure/data/pure.dat'),
    ]):
        assert _type in ['p', 'pm', 'h']
        root = (package_base if
                (_type == 'p' or _type == 'pm') else cmake_source_dir)
        tmp_dir.ensure(os.path.join(root, path))

    # Do not call the real setup function. Instead, replace it with
    # a MagicMock allowing to check with which arguments it was invoked.
    mock_setup = mocker.patch('skbuild.setuptools_wrap.upstream_setup')

    # Convenience print function
    def _pprint(desc, value=None):
        print("-----------------\n"
              "{}:\n"
              "\n"
              "{}\n".format(
                  desc,
                  pprint.pformat(
                      setup_kw.get(desc, {}) if value is None else value,
                      indent=2)))

    with execute_setup_py(tmp_dir, ['build'], disable_languages_test=True):

        assert mock_setup.call_count == 1
        setup_kw = mock_setup.call_args[1]

        # packages
        expected_packages = []
        if has_cmake_package:
            expected_packages += ['cmake']
        if has_hybrid_package:
            expected_packages += ['hybrid', 'hybrid.hybrid_2']
        if has_pure_package:
            expected_packages += ['hybrid.hybrid_2_pure', 'pure']

        _pprint('expected_packages', expected_packages)
        _pprint('packages')

        # package dir
        expected_package_dir = {
            package: (os.path.join(CMAKE_INSTALL_DIR(), package_base,
                                   package.replace('.', '/')))
            for package in expected_packages
        }
        _pprint('expected_package_dir', expected_package_dir)
        _pprint('package_dir')

        # package data
        expected_package_data = {}

        if has_cmake_package:
            expected_package_data['cmake'] = ['__init__.py', 'cmake.py']

        if has_hybrid_package:
            expected_package_data['hybrid'] = [
                '__init__.py',
                'hybrid_cmake.dat',
                'hybrid_cmake.py',
                'hybrid_pure.dat',
                'hybrid_pure.py',
                'data/hybrid_data_cmake.dat',
                'data/hybrid_data_pure.dat',
            ]
            expected_package_data['hybrid.hybrid_2'] = [
                '__init__.py', 'hybrid_2_cmake.py', 'hybrid_2_pure.py'
            ]

        if has_pure_package:
            expected_package_data['hybrid.hybrid_2_pure'] = \
                [
                    '__init__.py',
                    'hybrid_2_pure_1.py',
                    'hybrid_2_pure_2.py'
                ]
            expected_package_data['pure'] = [
                '__init__.py',
                'pure.py',
                'data/pure.dat',
            ]

        if has_cmake_module or has_pure_module:
            expected_modules = []
            if has_cmake_module:
                expected_modules.append(package_base_dir + 'cmakeModule.py')
            if has_pure_module:
                expected_modules.append(package_base_dir + 'pureModule.py')
            expected_package_data[''] = expected_modules

        _pprint('expected_package_data', expected_package_data)
        package_data = {
            p: sorted(files)
            for p, files in setup_kw['package_data'].items()
        }

        _pprint('package_data', package_data)

        # py_modules (corresponds to files associated with empty package)
        expected_py_modules = []
        if '' in expected_package_data:
            expected_py_modules = [
                os.path.splitext(module_file)[0]
                for module_file in expected_package_data['']
            ]
        _pprint('expected_py_modules', expected_py_modules)
        _pprint('py_modules')

        # scripts
        expected_scripts = []
        _pprint('expected_scripts', expected_scripts)
        _pprint('scripts')

        # data_files
        expected_data_files = []
        _pprint('expected_data_files', expected_data_files)
        _pprint('data_files')

        assert sorted(setup_kw['packages']) == sorted(expected_packages)
        assert sorted(setup_kw['package_dir']) == sorted(expected_package_dir)
        assert package_data == {
            p: sorted(files)
            for p, files in expected_package_data.items()
        }
        assert sorted(setup_kw['py_modules']) == sorted(expected_py_modules)
        assert sorted(setup_kw['scripts']) == sorted([])
        assert sorted(setup_kw['data_files']) == sorted([])
Exemple #8
0
def test_py_modules_keyword(distribution_type, capsys):

    # -------------------------------------------------------------------------
    #
    # "SOURCE" tree layout for "pure" distribution:
    #
    # ROOT/
    #     setup.py
    #     foo.py
    #     bar.py
    #
    # "SOURCE" tree layout for "skbuild" distribution:
    #
    # ROOT/
    #     setup.py
    #     CMakeLists.txt
    #
    # -------------------------------------------------------------------------
    # "BINARY" distribution layout is identical for both
    #
    # ROOT/
    #     foo.py
    #     bar.py
    #

    tmp_dir = _tmpdir('py_modules_keyword')

    tmp_dir.join('setup.py').write(
        textwrap.dedent("""
        from skbuild import setup
        setup(
            name="test_py_modules_keyword",
            version="1.2.3",
            description="a package testing use of py_modules keyword",
            author='The scikit-build team',
            license="MIT",
            py_modules=['foo', 'bar']
        )
        """))

    if distribution_type == 'skbuild':
        tmp_dir.join('CMakeLists.txt').write(
            textwrap.dedent("""
            cmake_minimum_required(VERSION 3.5.0)
            project(foobar NONE)
            file(WRITE "${CMAKE_BINARY_DIR}/foo.py" "# foo.py")
            file(WRITE "${CMAKE_BINARY_DIR}/bar.py" "# bar.py")
            install(
                FILES
                    "${CMAKE_BINARY_DIR}/foo.py"
                    "${CMAKE_BINARY_DIR}/bar.py"
                DESTINATION "."
                )
            """))

        messages = [
            "copying {}/{}.py -> "
            "{}/setuptools/lib".format(CMAKE_INSTALL_DIR(), module,
                                       SKBUILD_DIR())
            for module in ['foo', 'bar']
        ]

    elif distribution_type == 'pure':
        tmp_dir.join('foo.py').write("# foo.py")
        tmp_dir.join('bar.py').write("# bar.py")

        messages = [
            "copying {}.py -> "
            "{}/setuptools/lib".format(module, SKBUILD_DIR())
            for module in ['foo', 'bar']
        ]

    with execute_setup_py(tmp_dir, ['build'], disable_languages_test=True):
        pass

    out, _ = capsys.readouterr()
    for message in messages:
        assert to_platform_path(message) in out
Exemple #9
0
def test_cmake_install_dir_keyword(cmake_install_dir, expected_failed,
                                   error_code_type, capsys):

    # -------------------------------------------------------------------------
    # "SOURCE" tree layout:
    #
    # ROOT/
    #
    #     CMakeLists.txt
    #     setup.py
    #
    #     apple/
    #         __init__.py
    #
    # -------------------------------------------------------------------------
    # "BINARY" distribution layout
    #
    # ROOT/
    #
    #     apple/
    #         __init__.py
    #

    tmp_dir = _tmpdir('cmake_install_dir_keyword')

    setup_kwarg = ''
    if cmake_install_dir is not None:
        setup_kwarg = 'cmake_install_dir=r\'{}\''.format(cmake_install_dir)

    tmp_dir.join('setup.py').write(
        textwrap.dedent("""
        from skbuild import setup
        setup(
            name="test_cmake_install_dir",
            version="1.2.3",
            description="a package testing use of cmake_install_dir",
            author='The scikit-build team',
            license="MIT",
            packages=['apple', 'banana'],
            {setup_kwarg}
        )
        """.format(setup_kwarg=setup_kwarg)))

    # Install location purposely set to "." so that we can test
    # usage of "cmake_install_dir" skbuild.setup keyword.
    tmp_dir.join('CMakeLists.txt').write(
        textwrap.dedent("""
        cmake_minimum_required(VERSION 3.5.0)
        project(banana NONE)
        file(WRITE "${CMAKE_BINARY_DIR}/__init__.py" "")
        install(FILES "${CMAKE_BINARY_DIR}/__init__.py" DESTINATION ".")
        """))

    tmp_dir.ensure('apple', '__init__.py')

    failed = False
    message = ""
    try:
        with execute_setup_py(tmp_dir, ['build'], disable_languages_test=True):
            pass
    except SystemExit as e:
        # Error is not of type SKBuildError, it is expected to be
        # raised by distutils.core.setup
        failed = isinstance(e.code, error_code_type)
        message = str(e)

    out, _ = capsys.readouterr()

    assert failed == expected_failed
    if failed:
        if error_code_type == str:
            assert message == "error: package directory " \
                              "'{}' does not exist".format(
                                    os.path.join(CMAKE_INSTALL_DIR(), 'banana'))
        else:
            assert message.strip().startswith(
                "setup parameter 'cmake_install_dir' "
                "is set to an absolute path.")
    else:
        init_py = to_platform_path("{}/banana/__init__.py".format(
            CMAKE_INSTALL_DIR()))
        assert "copying {}".format(init_py) in out