Skip to content

Commit d0dbbee

Browse files
Merge pull request serge-sans-paille#1090 from serge-sans-paille/feature/rework-handle-import
Feature/rework handle import
2 parents 9011cf3 + 162ec87 commit d0dbbee

16 files changed

+338
-406
lines changed

pythran/analyses/argument_effects.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ def visit_Call(self, node):
163163
func_alias = self.global_declarations[bound_name]
164164
if func_alias is intrinsic.UnboundValue:
165165
continue
166+
if func_alias not in self.node_to_functioneffect:
167+
continue
168+
166169
func_alias = self.node_to_functioneffect[func_alias]
167170
predecessors = self.result.predecessors(func_alias)
168171
if self.current_function not in predecessors:

pythran/analyses/argument_read_once.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,13 @@ def visit_Call(self, node):
202202
if isinstance(func_alias, ast.Call):
203203
bound_name = func_alias.args[0].id
204204
func_alias = self.global_declarations[bound_name]
205+
205206
if func_alias is intrinsic.UnboundValue:
206207
continue
208+
209+
if func_alias not in self.node_to_functioneffect:
210+
continue
211+
207212
func_alias = self.node_to_functioneffect[func_alias]
208213
index_corres[n] = i
209214
func = func_alias

pythran/passmanager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"""
1313

1414
import gast as ast
15+
import os
1516
import re
1617

1718

@@ -185,7 +186,7 @@ class PassManager(object):
185186
'''
186187
def __init__(self, module_name, module_dir=None):
187188
self.module_name = module_name
188-
self.module_dir = module_dir
189+
self.module_dir = module_dir or os.getcwd()
189190
self._cache = {}
190191

191192
def gather(self, analysis, node, ctx=None):

pythran/tests/test_distutils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ def test_setup_build(self):
2222
cwd=os.path.join(cwd, 'test_distutils'))
2323
check_call(['python', 'setup.py', 'install', '--prefix=demo_install'],
2424
cwd=os.path.join(cwd, 'test_distutils'))
25+
26+
base = os.path.join(cwd, 'test_distutils', 'demo_install',)
27+
libdir = os.path.join(base, 'lib')
28+
if not os.path.isdir(libdir):
29+
libdir = os.path.join(base, 'lib64')
2530
check_call(['python', '-c', 'import demo'],
26-
cwd=os.path.join(cwd, 'test_distutils', 'demo_install',
27-
'lib', python_version, 'site-packages'))
31+
cwd=os.path.join(libdir, python_version, 'site-packages'))
2832
check_call(['python', 'setup.py', 'clean'],
2933
cwd=os.path.join(cwd, 'test_distutils'))
3034
shutil.rmtree(os.path.join(cwd, 'test_distutils', 'demo_install'))
@@ -59,9 +63,13 @@ def test_setup_build2(self):
5963
cwd=os.path.join(cwd, 'test_distutils_packaged'))
6064
check_call(['python', 'setup.py', 'install', '--prefix=demo_install2'],
6165
cwd=os.path.join(cwd, 'test_distutils_packaged'))
66+
67+
base = os.path.join(cwd, 'test_distutils_packaged', 'demo_install2',)
68+
libdir = os.path.join(base, 'lib')
69+
if not os.path.isdir(libdir):
70+
libdir = os.path.join(base, 'lib64')
6271
check_call(['python', '-c', 'import demo2.a'],
63-
cwd=os.path.join(cwd, 'test_distutils_packaged', 'demo_install2',
64-
'lib', python_version, 'site-packages'))
72+
cwd=os.path.join(libdir, python_version, 'site-packages'))
6573
check_call(['python', 'setup.py', 'clean'],
6674
cwd=os.path.join(cwd, 'test_distutils_packaged'))
6775
shutil.rmtree(os.path.join(cwd, 'test_distutils_packaged', 'demo_install2'))

pythran/tests/test_import_all.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ def unsupported_module():
3333
with self.assertRaises(pythran.syntax.PythranSyntaxError) as ex:
3434
pythran.compile_pythrancode("flamby", dedent(code))
3535

36-
self.assertIn("Module 'collections' unknown and not found.",
37-
str(ex.exception))
36+
self.assertIn("Module 'collections' not found.", str(ex.exception))
3837

3938
def test_complex_import_manipulation(self):
4039
"""

pythran/tests/test_optimizations.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,26 @@ def global_effects_unknown(a):
468468
self.run_test(code,
469469
1,
470470
global_effects_unknown=[int])
471+
472+
def test_argument_effects_unknown(self):
473+
code = '''
474+
def int_datatype(n):
475+
return list, str, n
476+
477+
def list_datatype(parent):
478+
def parser(value):
479+
return parent[0](value)
480+
481+
def formatter(value):
482+
return parent[1](value)
483+
484+
return parser, formatter
485+
486+
487+
def argument_effects_unknown(n):
488+
list_datatype(int_datatype(n))'''
489+
490+
self.run_test(code,
491+
1,
492+
argument_effects_unknown=[int])
493+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def dint():
2+
return int()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import builtins_in_imported
2+
from builtins_in_imported import dint
3+
4+
5+
#pythran export entry()
6+
#runas entry()
7+
def entry():
8+
return dint(), builtins_in_imported.dint()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def aa():
2+
return 3.14
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import global_init as gi
2+
3+
4+
XX = [gi.aa(), 3]
5+
6+
#pythran export bb()
7+
def bb():
8+
return XX

0 commit comments

Comments
 (0)