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

Add AbstractAlgebra.doctestsetup() helper and use it, then regenerate doctests so they benefit from @show_name #1895

Merged
merged 4 commits into from
Nov 10, 2024

Conversation

fingolfin
Copy link
Member

... similar to what we do in Oscar. Arguably the test outputs in docstrings are better this way for the user, as they look more like what they would be seeing.

If successful we should probably do the same in Nemo (and Hecke?)

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.16%. Comparing base (f90e000) to head (0465fea).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1895      +/-   ##
==========================================
+ Coverage   88.14%   88.16%   +0.02%     
==========================================
  Files         120      120              
  Lines       30288    30296       +8     
==========================================
+ Hits        26697    26711      +14     
+ Misses       3591     3585       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fingolfin
Copy link
Member Author

weird, I did include("docs/make.jl") with that file modified to use doctest = :fix and put all the changes in here. Yet it seems this did not catch everything?!

@@ -15,7 +15,7 @@ as the two names really refer to the same object.
The alias also gets a special docstring that points out that it is an alias

# Examples
```jldoctest; setup = :(using AbstractAlgebra)
```jldoctest; setup = :(using AbstractAlgebra; AbstractAlgebra.set_current_module(@__MODULE__))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer if this inline setup thing would not duplicate the content of doctestsetup() into this many files. Can't you call doctestsetup() instead here? (with some interpolation magic maybe)

Copy link
Collaborator

@benlorenz benlorenz Nov 8, 2024

Choose a reason for hiding this comment

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

The inline setup should not be necessary at all when setdocmeta! is called for :DocTestSetup. We don't do any setup like this in Oscar.jl, except for some artifacts downloads.

(The DocTestSetup = AbstractAlgebra.doctestsetup() are still required for the md files as this is independent from setdocmeta!)

Copy link
Collaborator

Choose a reason for hiding this comment

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

(I was actually wondering why we need to do this for every (?) docstring.)

Copy link
Member Author

@fingolfin fingolfin Nov 8, 2024

Choose a reason for hiding this comment

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

We don't use setdocmeta! because then Nemo and Oscar would start to break. This is explained at the top of docs/make.jl, this PR slightly improves that explanation. Here it is for your convenience:

# We do *not* call `DocMeta.setdocmeta!` with value `:(using AbstractAlgebra)`
# because we want to force that each jldoctest has its individual
# `setup = :(using AbstractAlgebra)`.
# The reason is that the AbstractAlgebra doctests are run also in Nemo,
# where `using AbstractAlgebra` must be avoided, as a few symbols change
# their meaning, e.g. `QQ`.

If you inspect the final commit in this PR you'll see that I previously tried to do setup = AbstractAlgebra.doctestsetup() but it just didn't work.

Of course I'd also prefer if we could do something like this, or even better, use setdocmeta!, but any solution must keep the Nemo and Oscar doctests working.

But unless someone has a bright idea quickly, I'd still like to merge this as-is, for the improved doctest contents, and then I'll happily review someone else's review for resolving this in a better way :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

(E.g. perhaps it suffices to only apply the explicit setup block to doctests which reference ZZ or QQ or so. But I'd rather not spend more hours figuring that out just now)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, thanks for the explanation. I did see a setdocmeta! at the beginning of the diff but now realized that this is only in the CI.yml.
And the # We do *not* call `DocMeta.setdocmeta!` line was unfortunately hidden in the diff.

Fine with me for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if this can be resolved later by changing Nemo to do

DocMeta.setdocmeta!(Nemo, :DocTestSetup, :(using Nemo); recursive = true)
DocMeta.setdocmeta!(Nemo.AbstractAlgebra, :DocTestSetup, Nemo.AbstractAlgebra.doctestsetup(); recursive = true)

(And then similar in Hecke, Oscar). I'll open an issue as a reminder to figure this out.

@fingolfin fingolfin changed the title Add AbstractAlgebra.doctestsetup() helper and use it Add AbstractAlgebra.doctestsetup() helper and use it, then regenerate doctests so they benefit from @show_name Nov 8, 2024

julia> D, f = direct_sum(S1, S2, S3)
(DirectSumModule over integers, AbstractAlgebra.Generic.ModuleHomomorphism{BigInt}[Hom: submodule over integers with 2 generators and no relations -> DirectSumModule, Hom: submodule over integers with 2 generators and no relations -> DirectSumModule, Hom: submodule over integers with 2 generators and no relations -> DirectSumModule], AbstractAlgebra.Generic.ModuleHomomorphism{BigInt}[Hom: DirectSumModule -> submodule over integers with 2 generators and no relations, Hom: DirectSumModule -> submodule over integers with 2 generators and no relations, Hom: DirectSumModule -> submodule over integers with 2 generators and no relations])
(DirectSumModule over integers, AbstractAlgebra.Generic.ModuleHomomorphism{BigInt}[Hom: S1 -> D, Hom: S2 -> D, Hom: S3 -> D], AbstractAlgebra.Generic.ModuleHomomorphism{BigInt}[Hom: D -> S1, Hom: D -> S2, Hom: D -> S3])
Copy link
Member Author

Choose a reason for hiding this comment

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

This kind of change is what my true goal here is

Copy link
Collaborator

@joschmitt joschmitt left a comment

Choose a reason for hiding this comment

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

I must say that I don't fully understand what's going on here, but this gets the output in the documentation closer to reality, so it is fine by me.

@fingolfin fingolfin merged commit 2309b29 into Nemocas:master Nov 10, 2024
29 checks passed
@fingolfin fingolfin deleted the mh/doctestsetup branch November 10, 2024 09:54
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.

4 participants