Skip to content

feat: add test to detect public names without a docstring #313

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

Merged
merged 16 commits into from
May 5, 2025

Conversation

gdalle
Copy link
Contributor

@gdalle gdalle commented Nov 24, 2024

Fixes #90

Source:

  • Add a function test_undocumented_names which checks whether public names are documented or not (only on Julia 1.11 and later). It does so by verifying that Docs.undocumented_names(module) is either empty or contains only the module name itself.

Tests:

  • Add a kwarg test_undocumented_names to test_all
  • Add tests with one fully documented module and one partially documented module.

Docs:

  • Add docs page about test_undocumented_names

Chores:

  • Bump version to v0.9.0 (BREAKING CHANGE)
  • Update CHANGELOG.

Copy link

codecov bot commented Nov 24, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.

Project coverage is 75.09%. Comparing base (3e90d04) to head (9c067ba).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Aqua.jl 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #313      +/-   ##
==========================================
+ Coverage   74.90%   75.09%   +0.19%     
==========================================
  Files          11       12       +1     
  Lines         765      783      +18     
==========================================
+ Hits          573      588      +15     
- Misses        192      195       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gdalle gdalle changed the title feat: add test for undocumented public names feat: add test to detect public names without a docstring Nov 24, 2024
Copy link

@KeithWM KeithWM left a comment

Choose a reason for hiding this comment

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

Just some comments. I am not an experienced enough Julia developer to be entirely confident that everything I say is correct, but I hope you value the suggestions/questions.


!!! warning
For Julia versions before 1.11, this does not test anything.
"""
Copy link

Choose a reason for hiding this comment

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

I would prefer seeing this warning in code with an @warn rather than a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That means adding a warning for every test below Julia 1.11, not sure people will like that. The fact that it does nothing on 1.10 can already be seen from the fact that the relevant @testset is empty

Copy link

@KeithWM KeithWM Nov 24, 2024

Choose a reason for hiding this comment

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

I realize now that this implementation relies heavily on the "new" public keyword, which was not actually in the original issue (as it predated the keyword). Given that a main reason for introducing the public keyword was that previously something being documented was used to show it was part of the API, I think the proposed implementation is a good idea. But I'm not quite sure how to deal with the expectations towards <1.11 users. It could help to change the name of the check to something like test_undocumented_api, test_undocumented_public or something else that include the word "public" without being as verbose as test_undocumented_public_names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that Docs.undocumented_names is not defined on 1.10, I'm not sure we can do anything meaningful before 1.11 (unless that function is added to Compat.jl)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, let me think loudly about this a bit ....

If we are concerned about people accidentally not running this test because they have their CI configured to run Aqua only with, say, Julia 1.10 (as LTS release), then it would indeed make sense to be more aggressive about flagging this. But I am not sure a @warn is that much more likely to be seen, esp. in a CI runner. If we want to ensure that, we'd ought to raise an error that suggests two options: either run Aqua in Julia >= 1.11, or else (for those of us who run tests in multiple Julia versions, like e.g. most projects I am involved in do) use a workaround, like

... pass the option undocumented_names = VERSION >= v"1.11" to Aqua.test_all.

Alas, we have not done that for other tests. In the end, I don't think this inconvenience (be it a warning or an error) for most people is worth it or necessary: the problem will solve itself over time, either by projects eventually switching to newer Julia versions, at which point they'll get the test; or by projects being ended and thus never getting this, but also never needing it.

That leaves the people who desperately try to get undocumented_names = true to do something but somehow missed that their Julia is to old. For them a @warn might be helpful.

To restrict it to those folks, we could also change the default for undocumented_names to something like this: undocumented_names = VERSION >= v"1.11", and then change test_undocumented_names to raise an error (or at least a warning) if it is called in Julia < 1.11.

This way, anyone using test_all with default arguments gets the test in >= 1.11 and otherwise not, without a warning; but someone who desperately tries to enable the test by passing test_undocumented_names = true will get a helpful message as to why the test is not turning on despite their efforts.

Anyway: I am also perfectly fine with the code as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can merge this as it is, and then possibly add a warning on 1.10 in a later release.

@gdalle gdalle requested a review from ericphanson November 24, 2024 12:04
Copy link
Member

@ericphanson ericphanson left a comment

Choose a reason for hiding this comment

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

the feature and implementation look good to me, but I think it is breaking to add a new default-on check (both on the principle that it would be very annoying to start failing CI "out of nowhere" and precedent, e.g. #174).

I think this could start off-by-default or just be v0.9.0.

@gdalle
Copy link
Contributor Author

gdalle commented Nov 24, 2024

I think this could start off-by-default or just be v0.9.0.

Either is fine by me. I guess it depends whether there are other pending breaking changes which might benefit from tagging v0.9.0 for this one.

Also I'm worried that if we leave this test off at first we'll never remember to turn it on at the next breaking release.

@ericphanson
Copy link
Member

Personally I think doing a breaking release whenever there's a new check is alright, and just have all checks opt-out by default. I'm not an Aqua maintainer, but I've used aqua in a lot of repos with varying levels of activity, and I haven't found breaking releases of Aqua particularly annoying. No other packages (should) depend on Aqua so being on an old release doesn't hold back other packages, and it's fine to just stay on an older release until the next maintenance pass. I think mixing opt-in and opt-out is a bit more confusing and requires more attention for users.

@gdalle
Copy link
Contributor Author

gdalle commented Nov 24, 2024

Tentatively bumping the version to v0.9.0, we'll see what the maintainers think

@KeithWM
Copy link

KeithWM commented Nov 24, 2024

Tentatively bumping the version to v0.9.0, we'll see what the maintainers think

I think the whole point of semver falls to bits if packages start cutting corners on what is and what is not breaking. I'm not sure what I usually see happening in practice, what kind of compat (caret, fixed, free) package developers have with their Aqua (test) dependency. A suggestion might be that Aqua warns users of newer versions, without actually breaking anything. Or that the documentation recommends dependents do not use a compat for Aqua, to avoid Aqua-clearance giving a false sense of security that all is well.

Copy link

@KeithWM KeithWM left a comment

Choose a reason for hiding this comment

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

I'm happy with this, but I wouldn't take my approval as a sufficient proof that the PR is good.


!!! warning
For Julia versions before 1.11, this does not test anything.
"""
Copy link

@KeithWM KeithWM Nov 24, 2024

Choose a reason for hiding this comment

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

I realize now that this implementation relies heavily on the "new" public keyword, which was not actually in the original issue (as it predated the keyword). Given that a main reason for introducing the public keyword was that previously something being documented was used to show it was part of the API, I think the proposed implementation is a good idea. But I'm not quite sure how to deal with the expectations towards <1.11 users. It could help to change the name of the check to something like test_undocumented_api, test_undocumented_public or something else that include the word "public" without being as verbose as test_undocumented_public_names.

@j-fu
Copy link

j-fu commented Nov 25, 2024

LGTM

@j-fu j-fu mentioned this pull request Nov 25, 2024
28 tasks
@gdalle
Copy link
Contributor Author

gdalle commented Nov 28, 2024

@lgoettgens would you mind taking a look? I got several reviews but none of them from maintainers I think?

@gdalle
Copy link
Contributor Author

gdalle commented Dec 1, 2024

gentle bump on this one, perhaps @fingolfin would be open to reviewing?

@lgoettgens
Copy link
Collaborator

I am very busy right now, but I'll try to squeeze looking at this in sometime the upcoming week or the one after. Sorry for not having time earlier for a proper review

@gdalle
Copy link
Contributor Author

gdalle commented Dec 1, 2024

No worries, I completely understand. As a maintainer I know that things sometimes slip under the radar so I thought I'd bump, but there is no rush.

@lgoettgens lgoettgens self-requested a review January 26, 2025 12:42
@ufechner7
Copy link

Any update?

@gdalle
Copy link
Contributor Author

gdalle commented Apr 22, 2025

@lgoettgens from my end this is good to go

@fingolfin
Copy link
Member

Sorry for the long time.

Needs a rebase in the meantime :-/ but hopefully an easy one.

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Thank you very much for this PR, and so sorry for not tending to it for so long.

Needs a rebase, and a few things should be clarified in the documentation. Otherwise it seems good.


!!! warning
For Julia versions before 1.11, this does not test anything.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, let me think loudly about this a bit ....

If we are concerned about people accidentally not running this test because they have their CI configured to run Aqua only with, say, Julia 1.10 (as LTS release), then it would indeed make sense to be more aggressive about flagging this. But I am not sure a @warn is that much more likely to be seen, esp. in a CI runner. If we want to ensure that, we'd ought to raise an error that suggests two options: either run Aqua in Julia >= 1.11, or else (for those of us who run tests in multiple Julia versions, like e.g. most projects I am involved in do) use a workaround, like

... pass the option undocumented_names = VERSION >= v"1.11" to Aqua.test_all.

Alas, we have not done that for other tests. In the end, I don't think this inconvenience (be it a warning or an error) for most people is worth it or necessary: the problem will solve itself over time, either by projects eventually switching to newer Julia versions, at which point they'll get the test; or by projects being ended and thus never getting this, but also never needing it.

That leaves the people who desperately try to get undocumented_names = true to do something but somehow missed that their Julia is to old. For them a @warn might be helpful.

To restrict it to those folks, we could also change the default for undocumented_names to something like this: undocumented_names = VERSION >= v"1.11", and then change test_undocumented_names to raise an error (or at least a warning) if it is called in Julia < 1.11.

This way, anyone using test_all with default arguments gets the test in >= 1.11 and otherwise not, without a warning; but someone who desperately tries to enable the test by passing test_undocumented_names = true will get a helpful message as to why the test is not turning on despite their efforts.

Anyway: I am also perfectly fine with the code as it is.

@gdalle gdalle requested review from fingolfin and lgoettgens May 3, 2025 08:15
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Looks good to me

@fingolfin fingolfin closed this May 4, 2025
@fingolfin fingolfin reopened this May 4, 2025
@fingolfin fingolfin added enhancement New feature or request changelog: added labels May 4, 2025
@gdalle
Copy link
Contributor Author

gdalle commented May 5, 2025

Anything more needed here?

Copy link
Collaborator

@lgoettgens lgoettgens left a comment

Choose a reason for hiding this comment

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

I would like to release this as a patch release with this test disabled by default to not disrupt the whole ecosystem, as there are many packages that don't declare a compat bound on Aqua. Thus, I'll apply the few suggestions here and will go ahead with the release later today

function test_undocumented_names(m::Module)
@static if VERSION >= v"1.11"
# exclude the module name itself because it has the README as auto-generated docstring (https://github.com/JuliaLang/julia/pull/39093)
undocumented_names = filter(n -> n != nameof(m), Docs.undocumented_names(m))
Copy link
Collaborator

Choose a reason for hiding this comment

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

When having a final look at this, I stumbled over something:

IMO, this should iterate over submodules as well, but only over submodules that are part of the same package. There should be some helper functions to do that already somewhere in Aqua (e.g.

Aqua.jl/src/exports.jl

Lines 26 to 30 in b7d973f

walkmodules(m) do x
for n in names(x)
isdefined(x, n) || push!(undefined, Symbol(join([fullname(x)...; n], '.')))
end
end
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in the latest commit

@gdalle
Copy link
Contributor Author

gdalle commented May 5, 2025

I would like to release this as a patch release with this test disabled by default to not disrupt the whole ecosystem, as there are many packages that don't declare a compat bound on Aqua.

What is the difference? One day there will be a breaking release switching this on, and people without a compat bound on Aqua will get surprised in exactly the same way.

Maybe we could add a warning telling people to switch to true for this setting, that way at least they catch it if they look at the test output? Otherwise I'm not sure anyone is actively monitoring release notes for Aqua's patch releases.

Thus if you use continuous integration tests, make sure those are configured
to use Julia >= 1.11 in order to benefit from this test.
"""
function test_undocumented_names(m::Module)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should also accept a broken kwarg, with the same semantics as for e.g. test_undefined_exports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in the latest commit

@lgoettgens lgoettgens merged commit 590a4e1 into JuliaTesting:master May 5, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test if all exported names has a docstring
8 participants