Skip to content

Commit

Permalink
setuptools_wrap: Fix support for py_modules and add test_py_modules_k…
Browse files Browse the repository at this point in the history
…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 6716723
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
19 changes: 14 additions & 5 deletions skbuild/setuptools_wrap.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def setup(*args, **kw):
package_data = kw.get('package_data', {}).copy() package_data = kw.get('package_data', {}).copy()


py_modules = kw.get('py_modules', []) py_modules = kw.get('py_modules', [])
new_py_modules = {py_module: False for py_module in py_modules}


scripts = kw.get('scripts', []) scripts = kw.get('scripts', [])
new_scripts = {script: False for script in scripts} new_scripts = {script: False for script in scripts}
Expand Down Expand Up @@ -278,8 +279,10 @@ def setup(*args, **kw):


package_prefixes = _collect_package_prefixes(package_dir, packages) package_prefixes = _collect_package_prefixes(package_dir, packages)


_classify_files(cmkr.install(), package_data, package_prefixes, py_modules, _classify_files(cmkr.install(), package_data, package_prefixes,
scripts, new_scripts, data_files) py_modules, new_py_modules,
scripts, new_scripts,
data_files)


kw['package_data'] = package_data kw['package_data'] = package_data
kw['package_dir'] = { kw['package_dir'] = {
Expand All @@ -290,7 +293,10 @@ def setup(*args, **kw):
for prefix, package in package_prefixes 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'] = [ kw['scripts'] = [
os.path.join(cmaker.CMAKE_INSTALL_DIR, script) if mask else script os.path.join(cmaker.CMAKE_INSTALL_DIR, script) if mask else script
Expand Down Expand Up @@ -353,8 +359,10 @@ def _collect_package_prefixes(package_dir, packages):
)) ))




def _classify_files(install_paths, package_data, package_prefixes, py_modules, def _classify_files(install_paths, package_data, package_prefixes,
scripts, new_scripts, data_files): py_modules, new_py_modules,
scripts, new_scripts,
data_files):
install_root = os.path.join(os.getcwd(), cmaker.CMAKE_INSTALL_DIR) install_root = os.path.join(os.getcwd(), cmaker.CMAKE_INSTALL_DIR)
for path in install_paths: for path in install_paths:
found_package = False found_package = False
Expand Down Expand Up @@ -394,6 +402,7 @@ def _classify_files(install_paths, package_data, package_prefixes, py_modules,
# check if path is a module # check if path is a module
for module in py_modules: for module in py_modules:
if path.replace("/", ".") == ".".join((module, "py")): if path.replace("/", ".") == ".".join((module, "py")):
new_py_modules[module] = True
found_module = True found_module = True
break break


Expand Down
44 changes: 44 additions & 0 deletions tests/test_setup.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -240,3 +240,47 @@ def test_script_keyword(distribution_type, capsys):


out, _ = capsys.readouterr() out, _ = capsys.readouterr()
assert message in out 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.