Skip to content

Commit 6716723

Browse files
committed
setuptools_wrap: Fix support for py_modules and add test_py_modules_keyword
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]
1 parent a51c30e commit 6716723

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

skbuild/setuptools_wrap.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def setup(*args, **kw):
249249
package_data = kw.get('package_data', {}).copy()
250250

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

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

279280
package_prefixes = _collect_package_prefixes(package_dir, packages)
280281

281-
_classify_files(cmkr.install(), package_data, package_prefixes, py_modules,
282-
scripts, new_scripts, data_files)
282+
_classify_files(cmkr.install(), package_data, package_prefixes,
283+
py_modules, new_py_modules,
284+
scripts, new_scripts,
285+
data_files)
283286

284287
kw['package_data'] = package_data
285288
kw['package_dir'] = {
@@ -290,7 +293,10 @@ def setup(*args, **kw):
290293
for prefix, package in package_prefixes
291294
}
292295

293-
kw['py_modules'] = py_modules
296+
kw['py_modules'] = [
297+
os.path.join(cmaker.CMAKE_INSTALL_DIR, py_module) if mask else py_module
298+
for py_module, mask in new_py_modules.items()
299+
]
294300

295301
kw['scripts'] = [
296302
os.path.join(cmaker.CMAKE_INSTALL_DIR, script) if mask else script
@@ -353,8 +359,10 @@ def _collect_package_prefixes(package_dir, packages):
353359
))
354360

355361

356-
def _classify_files(install_paths, package_data, package_prefixes, py_modules,
357-
scripts, new_scripts, data_files):
362+
def _classify_files(install_paths, package_data, package_prefixes,
363+
py_modules, new_py_modules,
364+
scripts, new_scripts,
365+
data_files):
358366
install_root = os.path.join(os.getcwd(), cmaker.CMAKE_INSTALL_DIR)
359367
for path in install_paths:
360368
found_package = False
@@ -394,6 +402,7 @@ def _classify_files(install_paths, package_data, package_prefixes, py_modules,
394402
# check if path is a module
395403
for module in py_modules:
396404
if path.replace("/", ".") == ".".join((module, "py")):
405+
new_py_modules[module] = True
397406
found_module = True
398407
break
399408

tests/test_setup.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,47 @@ def test_script_keyword(distribution_type, capsys):
240240

241241
out, _ = capsys.readouterr()
242242
assert message in out
243+
244+
245+
@pytest.mark.parametrize("distribution_type", ('pure', 'skbuild'))
246+
def test_py_modules_keyword(distribution_type, capsys):
247+
tmp_dir = _tmpdir('py_modules_keyword')
248+
249+
tmp_dir.join('setup.py').write(textwrap.dedent(
250+
"""
251+
from skbuild import setup
252+
setup(
253+
name="test_py_modules_keyword",
254+
version="1.2.3",
255+
description="a package testing use of py_modules keyword",
256+
author='The scikit-build team',
257+
license="MIT",
258+
py_modules=['foo']
259+
)
260+
"""
261+
))
262+
263+
if distribution_type == 'skbuild':
264+
tmp_dir.join('CMakeLists.txt').write(textwrap.dedent(
265+
"""
266+
cmake_minimum_required(VERSION 3.5.0)
267+
project(foo)
268+
file(WRITE "${CMAKE_BINARY_DIR}/foo.py" "# foo.py")
269+
install(FILES "${CMAKE_BINARY_DIR}/foo.py" DESTINATION ".")
270+
"""
271+
))
272+
273+
message = "copying _skbuild/cmake-install/foo.py -> " \
274+
"_skbuild/setuptools/lib".replace("/", os.path.sep)
275+
276+
elif distribution_type == 'pure':
277+
tmp_dir.join('foo.py').write("# foo.py")
278+
279+
message = "copying foo.py -> " \
280+
"_skbuild/setuptools/lib".replace("/", os.path.sep)
281+
282+
with execute_setup_py(tmp_dir, ['build']):
283+
pass
284+
285+
out, _ = capsys.readouterr()
286+
assert message in out

0 commit comments

Comments
 (0)