Skip to content

Commit

Permalink
patch for numba#4739
Browse files Browse the repository at this point in the history
Nothing fancy, do not allow dots.
  • Loading branch information
tolysz committed Jan 31, 2020
1 parent d7953a1 commit 5acc6ba
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
4 changes: 2 additions & 2 deletions numba/pycc/cc.py
Expand Up @@ -246,7 +246,7 @@ def distutils_extension(self, **kwargs):
library_dirs = (kwargs.pop('library_dirs', [])
+ self._toolchain.get_python_library_dirs())

ext = _CCExtension(name=self._basename,
ext = _CCExtension(name=self._source_module[:self._source_module.rfind('.')+1] + self._basename,
sources=self._get_mixin_sources(),
depends=depends,
define_macros=macros,
Expand All @@ -272,7 +272,7 @@ class _CCExtension(Extension):

def _prepare_object_files(self, build_ext):
cc = self._cc
dir_util.mkpath(build_ext.build_temp)
dir_util.mkpath(os.path.join(build_ext.build_temp, *self.name.split('.')[:-1]))
objects, _ = cc._compile_object_files(build_ext.build_temp)
# Add generated object files for linking
self.extra_objects = objects
Expand Down
18 changes: 18 additions & 0 deletions numba/tests/pycc_distutils_usecase/nested/source_module.py
@@ -0,0 +1,18 @@
import numpy as np

from numba.pycc import CC


cc = CC('pycc_compiled_module')

_const = 42

# This ones references a global variable at compile time
@cc.export('get_const', 'i8()')
def get_const():
return _const

# This one needs NRT and an environment
@cc.export('ones', 'f8[:](i4)')
def ones(n):
return np.ones(n)
15 changes: 15 additions & 0 deletions numba/tests/pycc_distutils_usecase/setup_distutils_nested.py
@@ -0,0 +1,15 @@
from distutils.core import setup

from nested.source_module import cc

from numba.pycc.platform import _patch_exec_command


def run_setup():
# Avoid sporadic crashes on Windows due to MSVCRT spawnve()
_patch_exec_command()
setup(ext_modules=[cc.distutils_extension()])


if __name__ == '__main__':
run_setup()
15 changes: 15 additions & 0 deletions numba/tests/pycc_distutils_usecase/setup_setuptools_nested.py
@@ -0,0 +1,15 @@
from setuptools import setup

from nested.source_module import cc

from numba.pycc.platform import _patch_exec_command


def run_setup():
# Avoid sporadic crashes on Windows due to MSVCRT spawnve()
_patch_exec_command()
setup(ext_modules=[cc.distutils_extension()])


if __name__ == '__main__':
run_setup()
39 changes: 39 additions & 0 deletions numba/tests/test_pycc.py
Expand Up @@ -353,13 +353,52 @@ def run_python(args):
"""
run_python(["-c", code])

def check_setup_nested_py(self, setup_py_file):
# Compute PYTHONPATH to ensure the child processes see this Numba
import numba
numba_path = os.path.abspath(os.path.dirname(
os.path.dirname(numba.__file__)))
env = dict(os.environ)
if env.get('PYTHONPATH', ''):
env['PYTHONPATH'] = numba_path + os.pathsep + env['PYTHONPATH']
else:
env['PYTHONPATH'] = numba_path

def run_python(args):
p = subprocess.Popen([sys.executable] + args,
cwd=self.usecase_dir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=env)
out, _ = p.communicate()
rc = p.wait()
if rc != 0:
self.fail("python failed with the following output:\n%s"
% out.decode('utf-8', 'ignore'))

run_python([setup_py_file, "build_ext", "--inplace"])
code = """if 1:
import nested.pycc_compiled_module as lib
assert lib.get_const() == 42
res = lib.ones(3)
assert list(res) == [1.0, 1.0, 1.0]
"""
run_python(["-c", code])

def test_setup_py_distutils(self):
self.check_setup_py("setup_distutils.py")

def test_setup_py_distutils_nested(self):
self.check_setup_nested_py("setup_distutils_nested.py")

@unittest.skipIf(setuptools is None, "test needs setuptools")
def test_setup_py_setuptools(self):
self.check_setup_py("setup_setuptools.py")

@unittest.skipIf(setuptools is None, "test needs setuptools")
def test_setup_py_setuptools_nested(self):
self.check_setup_nested_py("setup_setuptools_nested.py")


if __name__ == "__main__":
unittest.main()

0 comments on commit 5acc6ba

Please sign in to comment.