Permalink
Browse files

setuptools_wrap: Fix support for py_modules and add test_py_modules_k…

…eyword

Similarly to what is done for scripts, this commit introduces
the ivar 'new_py_modules' to keep track of which module is installed
by a CMake install rule and which one is provided by the source tree.

This commit fixes the following test:

  tests/test_setup.py::test_py_modules_keyword[skbuild]
  • Loading branch information...
jcfr committed Sep 12, 2016
1 parent a51c30e commit 671672370ee1b5f9dc5b3c0b5cdc5e4930bbf06d
Showing with 58 additions and 5 deletions.
  1. +14 −5 skbuild/setuptools_wrap.py
  2. +44 −0 tests/test_setup.py
@@ -249,6 +249,7 @@ def setup(*args, **kw):
package_data = kw.get('package_data', {}).copy()
py_modules = kw.get('py_modules', [])
new_py_modules = {py_module: False for py_module in py_modules}
scripts = kw.get('scripts', [])
new_scripts = {script: False for script in scripts}
@@ -278,8 +279,10 @@ def setup(*args, **kw):
package_prefixes = _collect_package_prefixes(package_dir, packages)
_classify_files(cmkr.install(), package_data, package_prefixes, py_modules,
scripts, new_scripts, data_files)
_classify_files(cmkr.install(), package_data, package_prefixes,
py_modules, new_py_modules,
scripts, new_scripts,
data_files)
kw['package_data'] = package_data
kw['package_dir'] = {
@@ -290,7 +293,10 @@ def setup(*args, **kw):
for prefix, package in package_prefixes
}
kw['py_modules'] = py_modules
kw['py_modules'] = [
os.path.join(cmaker.CMAKE_INSTALL_DIR, py_module) if mask else py_module
for py_module, mask in new_py_modules.items()
]
kw['scripts'] = [
os.path.join(cmaker.CMAKE_INSTALL_DIR, script) if mask else script
@@ -353,8 +359,10 @@ def _collect_package_prefixes(package_dir, packages):
))
def _classify_files(install_paths, package_data, package_prefixes, py_modules,
scripts, new_scripts, data_files):
def _classify_files(install_paths, package_data, package_prefixes,
py_modules, new_py_modules,
scripts, new_scripts,
data_files):
install_root = os.path.join(os.getcwd(), cmaker.CMAKE_INSTALL_DIR)
for path in install_paths:
found_package = False
@@ -394,6 +402,7 @@ def _classify_files(install_paths, package_data, package_prefixes, py_modules,
# check if path is a module
for module in py_modules:
if path.replace("/", ".") == ".".join((module, "py")):
new_py_modules[module] = True
found_module = True
break
@@ -240,3 +240,47 @@ def test_script_keyword(distribution_type, capsys):
out, _ = capsys.readouterr()
assert message in out
@pytest.mark.parametrize("distribution_type", ('pure', 'skbuild'))
def test_py_modules_keyword(distribution_type, capsys):
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']
)
"""
))
if distribution_type == 'skbuild':
tmp_dir.join('CMakeLists.txt').write(textwrap.dedent(
"""
cmake_minimum_required(VERSION 3.5.0)
project(foo)
file(WRITE "${CMAKE_BINARY_DIR}/foo.py" "# foo.py")
install(FILES "${CMAKE_BINARY_DIR}/foo.py" DESTINATION ".")
"""
))
message = "copying _skbuild/cmake-install/foo.py -> " \
"_skbuild/setuptools/lib".replace("/", os.path.sep)
elif distribution_type == 'pure':
tmp_dir.join('foo.py').write("# foo.py")
message = "copying foo.py -> " \
"_skbuild/setuptools/lib".replace("/", os.path.sep)
with execute_setup_py(tmp_dir, ['build']):
pass
out, _ = capsys.readouterr()
assert message in out

0 comments on commit 6716723

Please sign in to comment.