Read about our upcoming Code of Conduct on this issue

Commit 772cb865 authored by Pierre Augier's avatar Pierre Augier
Browse files

Make behavior while using Pythran

parent 258dcdb1469f
......@@ -6,6 +6,12 @@ Future
- Alternative syntax for blocks (see `issue #29
<https://bitbucket.org/fluiddyn/fluidpythran/issues/29>`_)
0.1.6 (2018-12-14)
------------------
- Better logging and commandline (no compilation if the extension is
up-to-date)
0.1.5 (2018-12-12)
------------------
......
__version__ = "0.1.5"
__version__ = "0.1.6"
try:
from pyfiglet import figlet_format
......
......@@ -312,7 +312,7 @@ class CachedJIT:
has_to_write = False
if has_to_write and mpi.rank == 0:
logger.info(f"write code in file {path_pythran}")
logger.debug(f"write code in file {path_pythran}")
with open(path_pythran, "w") as file:
file.write(src)
file.flush()
......@@ -370,7 +370,7 @@ class CachedJIT:
mpi.barrier()
if mpi.rank == 0:
logger.info(
logger.debug(
f"write Pythran signature in file {path_pythran_header} with types\n{arg_types}"
)
with open(path_pythran_header, "w") as file:
......
......@@ -30,6 +30,8 @@ from typing import Union, Iterable, Optional
import sysconfig
import hashlib
import sys
import os
from datetime import datetime
from .compat import open, implementation
from . import mpi
......@@ -39,6 +41,23 @@ from .log import logger
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") or ".so"
def modification_date(filename):
"""Get the modification date of a file"""
return datetime.fromtimestamp(os.path.getmtime(str(filename)))
def has_to_build(output_file: Path, input_file: Path):
"""Check if a file has to be (re)built"""
output_file = PathSeq(output_file)
input_file = PathSeq(input_file)
if not output_file.exists():
return True
mod_date_output = modification_date(output_file)
if mod_date_output < modification_date(input_file):
return True
return False
def make_hex(src):
"""Produce a hash from a sting"""
return hashlib.md5(src.encode("utf8")).hexdigest()
......@@ -117,7 +136,23 @@ class SchedulerPopen:
openmp=False,
str_pythran_flags: Optional[str] = None,
parallel=True,
force=True,
):
if name_ext_file is None:
name_ext_file = name_ext_from_path_pythran(path)
if not force:
path_out = path.with_name(name_ext_file)
if not has_to_build(path_out, path):
logger.warning(
f"Do not pythranize {path} because it seems up-to-date "
"(but the compilation options may have changed). "
"You can force the compilation with the option -f.")
return
logger.info(f"Schedule pythranization of file {path}")
if str_pythran_flags is not None:
flags = str_pythran_flags.strip().split()
else:
......@@ -146,8 +181,6 @@ class SchedulerPopen:
path.name,
]
if name_ext_file is None:
name_ext_file = name_ext_from_path_pythran(path)
words_command.extend(("-o", name_ext_file))
words_command.extend(flags)
......@@ -179,12 +212,14 @@ def wait_for_all_extensions():
def compile_pythran_files(
paths: Iterable[Path], str_pythran_flags: str, parallel=True
paths: Iterable[Path], str_pythran_flags: str, parallel=True, force=True
):
for path in paths:
print("Schedule pythranization of file", path)
scheduler.compile_with_pythran(
path, str_pythran_flags=str_pythran_flags, parallel=parallel
path,
str_pythran_flags=str_pythran_flags,
parallel=parallel,
force=force,
)
......
......@@ -45,7 +45,7 @@ def run():
return
if not args.path and not args.clear_cache:
print("No python files given. Nothing to do! ✨ 🍰 ✨.")
logger.warning("No python files given. Nothing to do! ✨ 🍰 ✨.")
return
if args.clear_cache:
......@@ -94,7 +94,9 @@ def run():
if has_to_build(ext_path, pythran_path):
pythran_paths.append(pythran_path)
compile_pythran_files(pythran_paths, args.pythran_flags, parallel=True)
compile_pythran_files(
pythran_paths, args.pythran_flags, parallel=True, force=args.force
)
def parse_args():
......
......@@ -661,7 +661,7 @@ def make_pythran_file(
path_pythran = path_dir / path_py.name
if not has_to_build(path_pythran, path_py) and not force:
logger.info(f"File {path_pythran} already up-to-date.")
logger.warning(f"File {path_pythran} already up-to-date.")
return
with mock_modules(mocked_modules):
......@@ -675,7 +675,7 @@ def make_pythran_file(
code_pythran_old = file.read()
if code_pythran_old == code_pythran:
logger.info(f"Code in file {path_pythran} already up-to-date.")
logger.warning(f"Code in file {path_pythran} already up-to-date.")
return
logger.debug(f"code_pythran:\n{code_pythran}")
......
......@@ -43,7 +43,6 @@ Internal API
import os
import sys
import inspect
from datetime import datetime
import re
from pathlib import Path
import ast
......@@ -65,7 +64,15 @@ try:
except ImportError:
pass
from .pythranizer import ext_suffix, name_ext_from_path_pythran, make_hex
from .pythranizer import (
ext_suffix,
name_ext_from_path_pythran,
make_hex,
modification_date,
has_to_build,
)
__all__ = ["modification_date", "has_to_build"]
path_root = Path(
......@@ -130,23 +137,6 @@ def get_module_name(frame):
return module_name
def modification_date(filename):
"""Get the modification date of a file"""
return datetime.fromtimestamp(os.path.getmtime(str(filename)))
def has_to_build(output_file: Path, input_file: Path):
"""Check if a file has to be (re)built"""
output_file = Path(output_file)
input_file = Path(input_file)
if not output_file.exists():
return True
mod_date_output = modification_date(output_file)
if mod_date_output < modification_date(input_file):
return True
return False
def get_source_without_decorator(func: Callable):
"""Get the source of a function without its decorator"""
src = inspect.getsource(func)
......
......@@ -30,7 +30,7 @@ def main():
name = args[0]
path = Path.cwd() / name
print(f"Pythranize {path}")
print(f"Pythranizing {path}")
if "-o" in args:
index_output = args.index("-o") + 1
......@@ -85,10 +85,10 @@ def main():
path_tmp.rename(path_out)
if path_out.exists():
print(f"file {path_out.absolute()} created")
print(f"Done! File {path_out.absolute()} created")
else:
logger.error(
f"file {path_out.absolute()} has not been created by Pythran"
f"Error! File {path_out.absolute()} has not been created by Pythran"
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment