Skip to content

Commit

Permalink
Propagate file path instead of file content
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann Diorcet committed Mar 21, 2017
1 parent 48cb40b commit 8f361a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pythran/tests/test_env.py
Expand Up @@ -375,7 +375,7 @@ class TestFromDir(TestEnv):
def interface(name=None, file_=None):
""" Return Pythran specs."""
default_value = {name: []}
return pyspec_parser(open(file_).read()) if file_ else default_value
return pyspec_parser(file_) if file_ else default_value

def __init__(self, *args, **kwargs):
""" Dynamically add methods for unittests, second stage. """
Expand Down
14 changes: 10 additions & 4 deletions pythran/toolchain.py
Expand Up @@ -300,7 +300,7 @@ def compile_cxxcode(module_name, cxxcode, output_binary=None, keep_temp=False,
return output_binary


def compile_pythrancode(module_name, pythrancode, specs=None,
def compile_pythrancode(module_name, path_or_text, specs=None,
opts=None, cpponly=False, output_file=None,
**kwargs):
'''Pythran code (string) -> c++ code -> native module
Expand All @@ -311,7 +311,13 @@ def compile_pythrancode(module_name, pythrancode, specs=None,
# Autodetect the Pythran spec if not given as parameter
from pythran.spec import pyspec_parser
if specs is None:
specs = pyspec_parser(pythrancode)
specs = pyspec_parser(path_or_text)

if os.path.isfile(path_or_text):
with open(path_or_text) as fd:
pythrancode = fd.read()
else:
pythrancode = path_or_text

# Generate C++, get a PythonModule object
module = generate_cxx(module_name, pythrancode, specs, opts)
Expand Down Expand Up @@ -358,9 +364,9 @@ def compile_pythranfile(file_path, output_file=None, module_name=None,
spec_file = os.path.join(os.path.dirname(file_path), os.path.splitext(file_path)[0] + ".pythran")
if os.path.isfile(spec_file):
from pythran.spec import spec_parser
specs = spec_parser(open(spec_file).read())
specs = spec_parser(spec_file)

output_file = compile_pythrancode(module_name, open(file_path).read(), specs,
output_file = compile_pythrancode(module_name, file_path, specs,
output_file=output_file,
cpponly=cpponly,
**kwargs)
Expand Down

0 comments on commit 8f361a2

Please sign in to comment.