Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove backslash hack in doctest #39186

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

user202729
Copy link
Contributor

@user202729 user202729 commented Dec 22, 2024

Would fix #39058 . I think it's cleaner to remove this thing anyway (given that it doesn't work in the real Sage command prompt either)

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Copy link

github-actions bot commented Dec 22, 2024

Documentation preview for this PR (built with commit 1a9b002; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@user202729
Copy link
Contributor Author

user202729 commented Dec 22, 2024

There's a little issue e.g. with the book_stein_ent file…

This file contains all the example code from the published book
'Elementary Number Theory: Primes, Congruences, and Secrets' by
William Stein, Springer-Verlag, 2009.

This modifies the code however. Is it a problem (factually incorrect)?

Then there are other cases where the file is autogenerated… (I don't know where the source is)

This file (./integration_doctest.sage) was *autogenerated* from ./integration.tex,
with sagetex.sty version 2011/05/27 v2.3.1.

Helper script:

from pathlib import Path
import re

backslash_replacer = re.compile(r"^( *)sage:(.*)\\\ *\n((?:\ *\.\.\.\.\:.*\\\ *\n)*)(\ *)(.*)", flags=re.MULTILINE)

def do_replace(string):
    m = backslash_replacer.search(string)
    while m is not None:
        g = m.groups()
        if g[4].startswith(("sage:", "....:")):
            m = backslash_replacer.search(string, m.start()+1)
        else:
            string = (string[:m.start()] + g[0] + "sage:" + g[1] + "\\\n" + g[2] + 
            g[0] + "....: " +
            " " * max(0, len(g[3])-len(g[0])-6) + 
            g[4] + string[m.end():])
            m = backslash_replacer.search(string)  # may have exponential complexity
    return string

for f in """
src/doc/en/developer/coding_basics.rst
src/doc/en/thematic_tutorials/lie/crystals.rst
src/doc/en/thematic_tutorials/lie/branching_rules.rst
src/doc/en/thematic_tutorials/sandpile.rst
src/sage/coding/delsarte_bounds.py
src/sage/coding/extended_code.py
src/sage/coding/information_set_decoder.py
src/sage/coding/linear_code.py
src/sage/coding/linear_code_no_metric.py
src/sage/combinat/designs/gen_quadrangles_with_spread.pyx
src/sage/doctest/parsing.py
src/sage/dynamics/arithmetic_dynamics/affine_ds.py
src/sage/dynamics/arithmetic_dynamics/wehlerK3.py
src/sage/doctest/forker.py
src/sage/features/__init__.py
src/sage/dynamics/arithmetic_dynamics/projective_ds.py
src/sage/geometry/polyhedron/base4.py
src/sage/graphs/graph.py
src/sage/groups/conjugacy_classes.py
src/sage/groups/group.pyx
src/sage/interfaces/qepcad.py
src/sage/knots/knotinfo.py
src/sage/libs/ntl/ntl_mat_GF2.pyx
src/sage/manifolds/differentiable/affine_connection.py
src/sage/matrix/matrix_polynomial_dense.pyx
src/sage/numerical/backends/interactivelp_backend.pyx
src/sage/numerical/backends/glpk_backend.pyx
src/sage/rings/multi_power_series_ring.py
src/sage/rings/multi_power_series_ring_element.py
src/sage/rings/polynomial/multi_polynomial.pyx
src/sage/rings/polynomial/multi_polynomial_ideal.py
src/sage/rings/polynomial/pbori/gbcore.py
src/sage/schemes/jacobians/abstract_jacobian.py
src/sage/schemes/product_projective/rational_point.py
src/sage/schemes/product_projective/subscheme.py
src/sage/schemes/projective/projective_space.py
src/sage/symbolic/expression.pyx
src/sage/tensor/modules/tensor_with_indices.py
src/sage/tests/book_stein_ent.py
src/sage/tests/books/computational-mathematics-with-sagemath/float_doctest.py
src/sage/tests/books/computational-mathematics-with-sagemath/integration_doctest.py
src/sage/topology/simplicial_complex.py
""".strip().splitlines():
    f = Path("~/sage").expanduser()/f
    if f.is_file() and f.suffix not in (".pyc",):
        string = f.read_text(errors="ignore")
        string1 = do_replace(string)
        if string1 != string:
            #print(string)
            f.write_text(string1)
            print("Changed:", f)
        else: print("No changes:", f)
    else: assert False

@user202729 user202729 marked this pull request as ready for review December 22, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sage --fixdoctests does not work with line continuation
1 participant