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

Merged
merged 11 commits into from
Feb 10, 2025

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 0ed925b; 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
Copy link
Contributor

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on using standard python syntax for this

vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 30, 2025
sagemathgh-39186: Remove backslash hack in doctest
    
Would fix sagemath#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

<!-- Put an `x` in all the boxes that apply. -->

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

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39186
Reported by: user202729
Reviewer(s): Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 31, 2025
sagemathgh-39186: Remove backslash hack in doctest
    
Would fix sagemath#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

<!-- Put an `x` in all the boxes that apply. -->

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

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39186
Reported by: user202729
Reviewer(s): Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 3, 2025
sagemathgh-39186: Remove backslash hack in doctest
    
Would fix sagemath#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

<!-- Put an `x` in all the boxes that apply. -->

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

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39186
Reported by: user202729
Reviewer(s): Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 4, 2025
sagemathgh-39186: Remove backslash hack in doctest
    
Would fix sagemath#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

<!-- Put an `x` in all the boxes that apply. -->

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

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39186
Reported by: user202729
Reviewer(s): Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 9, 2025
sagemathgh-39186: Remove backslash hack in doctest
    
Would fix sagemath#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

<!-- Put an `x` in all the boxes that apply. -->

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

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39186
Reported by: user202729
Reviewer(s): Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 9, 2025
sagemathgh-39186: Remove backslash hack in doctest
    
Would fix sagemath#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

<!-- Put an `x` in all the boxes that apply. -->

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

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39186
Reported by: user202729
Reviewer(s): Tobias Diez
@vbraun vbraun merged commit 9854dd3 into sagemath:develop Feb 10, 2025
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sage --fixdoctests does not work with line continuation
3 participants