Skip to content

Commit

Permalink
Quick fix for Numba
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed Jan 16, 2024
1 parent 3cb4212 commit dd92a1e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion data_tests/package_for_test_meson/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ license = {text = "BSD License"}
[build-system]
build-backend = "mesonpy"
# We cannot add the local transonic as build dependency here
requires = ["meson-python", "transonic"]
requires = ["meson-python", "transonic", "pythran"]
12 changes: 7 additions & 5 deletions src/transonic/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _make_code_from_fdef_node(self, fdef):
return format_str(code)

def make_backend_files(
self, paths_py, force=False, log_level=None, analyses=None
self, paths_py, force=False, log_level=None, analyses=None, **kwargs
):
"""Create backend files from a list of Python files"""

Expand All @@ -78,7 +78,9 @@ def make_backend_files(
paths_out = []
for path in paths_py:
analysis = analyses[path]
path_out = self.make_backend_file(path, analysis, force=force)
path_out = self.make_backend_file(
path, analysis, force=force, **kwargs
)
if path_out:
paths_out.append(path_out)

Expand All @@ -98,7 +100,7 @@ def make_backend_files(
return paths_out

def make_backend_file(
self, path_py: Path, analysis=None, force=False, log_level=None
self, path_py: Path, analysis=None, force=False, log_level=None, **kwargs
):
"""Create a Python file from a Python file (if necessary)"""

Expand Down Expand Up @@ -134,7 +136,7 @@ def make_backend_file(
analysis = analyse_aot(code, path_py)

code_backend, codes_ext, code_header = self._make_backend_code(
path_py, analysis
path_py, analysis, **kwargs
)
if not code_backend:
return
Expand Down Expand Up @@ -178,7 +180,7 @@ def _make_first_lines_header(self):
def _make_beginning_code(self):
return ""

def _make_backend_code(self, path_py, analysis):
def _make_backend_code(self, path_py, analysis, **kwargs):
"""Create a backend code from a Python file"""

boosted_dicts, code_dependance, annotations, blocks, codes_ext = analysis
Expand Down
10 changes: 8 additions & 2 deletions src/transonic/backends/numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ def compile_extension(
process = None
return compiling, process

def _make_backend_code(self, path_py, analysis):
def _make_backend_code(self, path_py, analysis, **kwargs):
"""Create a backend code from a Python file"""
code, codes_ext, header = super()._make_backend_code(path_py, analysis)

if not code:
return code, codes_ext, header

return add_numba_comments(code), codes_ext, header
code = add_numba_comments(code)

for_meson = kwargs.get("for_meson", False)
if for_meson:
code = format_str(code.replace("# __protected__ ", ""))

return code, codes_ext, header
7 changes: 5 additions & 2 deletions src/transonic/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def run():


def run_1_backend(paths, backend, args, analyses):
backend.make_backend_files(paths, force=args.force, analyses=analyses)
backend.make_backend_files(
paths, force=args.force, analyses=analyses, for_meson=args.meson
)

if args.meson:
path_meson_build = Path("meson.build")
Expand Down Expand Up @@ -144,10 +146,11 @@ def run_1_backend(paths, backend, args, analyses):
if has_to_write:
meson_path.write_text(meson_code)

# special case for numba which always needs the "compilation" step
if args.no_compile:
return

if not can_import_accelerator(backend.name):
if backend.name != "numba" and not can_import_accelerator(backend.name):
logger.warning(
f"Since {backend.name_capitalized} is not importable, "
"Transonic cannot properly compile a file."
Expand Down

0 comments on commit dd92a1e

Please sign in to comment.