Skip to content

Commit

Permalink
Allow passing view_annotate=True to Cython compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
user202729 committed Nov 9, 2024
1 parent 1b3f398 commit 9af8bee
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/sage/misc/cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import re
import sys
import shutil
import webbrowser

from sage.env import (SAGE_LOCAL, cython_aliases,
sage_include_directories)
Expand Down Expand Up @@ -79,8 +80,8 @@ def _standard_libs_libdirs_incdirs_aliases():


def cython(filename, verbose=0, compile_message=False,
use_cache=False, create_local_c_file=False, annotate=True, sage_namespace=True,
create_local_so_file=False):
use_cache=False, create_local_c_file=False, annotate=True, view_annotate=False,
sage_namespace=True, create_local_so_file=False):
r"""
Compile a Cython file. This converts a Cython file to a C (or C++ file),
and then compiles that. The .c file and the .so file are
Expand Down Expand Up @@ -110,6 +111,9 @@ def cython(filename, verbose=0, compile_message=False,
in the temporary directory, but if ``create_local_c_file`` is also True,
then save a copy of the .html file in the current directory.
- ``view_annotate`` -- boolean (default: ``False``); if ``True``, open the
annotated html file in a web browser using :func:`webbrowser.open`
- ``sage_namespace`` -- boolean (default: ``True``); if ``True``, import
``sage.all``
Expand Down Expand Up @@ -392,6 +396,11 @@ def cython(filename, verbose=0, compile_message=False,
shutil.copy(os.path.join(target_dir, name + ".html"),
os.curdir)

if view_annotate:
if not annotate:
raise ValueError("Cannot view annotated file without creating it")
webbrowser.open(os.path.join(target_dir, name + ".html"))

Check warning on line 402 in src/sage/misc/cython.py

View check run for this annotation

Codecov / codecov/patch

src/sage/misc/cython.py#L400-L402

Added lines #L400 - L402 were not covered by tests

# This emulates running "setup.py build" with the correct options
#
# setuptools plugins considered harmful:
Expand Down

0 comments on commit 9af8bee

Please sign in to comment.