def test_sdist_hide_listing(action, hide_listing, capfd): cmd = [action, "--", "-DMY_CMAKE_VARIABLE:BOOL=1"] if hide_listing: cmd.insert(0, "--hide-listing") @project_setup_py_test("hello", cmd, verbose_git=False) def run(): pass run() out, _ = capfd.readouterr() if hide_listing: assert to_platform_path("bonjour/__init__.py") not in out else: assert to_platform_path("bonjour/__init__.py") in out if action == "sdist": what = "copied" if hasattr(os, 'link'): what = "hard-linked" assert "%s 7 files" % what in out elif action == "bdist_wheel": assert "copied 4 files" in out # build_py assert "copied 5 files" in out # install_lib assert "copied 0 files" in out # install_scripts
def test_hide_listing(action, hide_listing, capfd): cmd = [action] if hide_listing: cmd.insert(0, "--hide-listing") @project_setup_py_test("test-hide-listing", cmd, verbose_git=False, disable_languages_test=True) def run(): pass run() out, _ = capfd.readouterr() if hide_listing: assert to_platform_path("bonjour/__init__.py") not in out else: assert to_platform_path("bonjour/__init__.py") in out if action == "sdist": what = "copied" if hasattr(os, 'link'): what = "hard-linked" assert "%s 10 files" % what in out elif action == "bdist_wheel": assert "copied 6 files" in out # build_py assert "copied 9 files" in out # install_lib assert "copied 0 files" in out # install_scripts
def test_python_module_finder(): modules = PythonModuleFinder(['bonjour', 'hello'], {}, []).find_all_modules( os.path.join(SAMPLES_DIR, 'hello-cpp') ) assert sorted(modules) == sorted([ ('bonjour', '__init__', to_platform_path('bonjour/__init__.py')), ('hello', '__init__', to_platform_path('hello/__init__.py')), ('hello', '__main__', to_platform_path('hello/__main__.py'))])
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
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
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=\'{}\''.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
def test_to_platform_path(input_path, expected_path): assert to_platform_path(input_path) == expected_path