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

improve documentation, add doctests, fix bugs found on the way #11

Merged
merged 15 commits into from
Dec 9, 2020

Conversation

ericphanson
Copy link
Member

I realized that after #8 some docstrings I didn't want to include (e.g. _findmin, which hopefully will be gone soon, ref #9) were there, and others didn't exist (e.g. match and explain). So here I've tried to fix that.


```
"""
explain
Copy link
Contributor

Choose a reason for hiding this comment

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

This explain kinda comes out of nowhere, eh?

src/core.jl Outdated
Looks for a match for `query` in the text. Returns either `nothing`
if no match is found, or a [`QueryMatch`](@ref) object.
"""
Base.match(query::AbstractQuery, text::Union{Document,Corpus})
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm missing something obvious, but where's the function definition?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, so in all these I'm on-purpose not attaching the docstring to the specific methods, because the existing methods are more narrow than where I want the docstring to apply. E.g. here I want the docstring to apply to any method of Base.match that fits that signature (instead of sticking it on just one of the match methods, or copying it by hand to all of them). For the explain one, I want it to apply to any method of explain.

Why does it matter? if for example you do ? + then you get all the docstrings for any method of +. But if you do ? +(1,1), you get just 1 docstring, the most specific one that applies to those arguments.

Copy link
Contributor

Choose a reason for hiding this comment

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

😮 TIL!

src/core.jl Outdated
Looks for all matches for `query` in the text. Returns either a
`Vector` `QueryMatch` objects corresponding to all of the matches found.
"""
match_all(query::AbstractQuery, text::Union{Document,Corpus})
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@ericphanson
Copy link
Member Author

ericphanson commented Dec 9, 2020

preview is at https://beacon-biosignals.github.io/KeywordSearch.jl/previews/PR11/, which you can get from clicking the "details" button in the "documenter/deploy" check

@ericphanson ericphanson marked this pull request as draft December 9, 2020 13:18
@ericphanson
Copy link
Member Author

Marking as draft since I want to do some more doc changes

@ericphanson
Copy link
Member Author

Ok, I made a bunch of changes, which I tried to group into clear commits. I found two bugs when improving the docs:

  • fix_punct wasn't removing \n's, which meant the test in the docstring for word_boundary wasn't passing-- but since it was just a docstring instead of a doctest, I didn't know. I changed fix_punct to catch this, and made the test into a doctest
  • match_all wasn't defined for NamedQuerys, so I added that and added tests

I decided to embrace doctests, in particular for testing printing, because it's easy to update them if the printing changes (see docs/fix_doctests.jl. I've added a bunch, and added them to runtests.jl so that they get tested as part of CI.

I think the codecov drop is spurious; the lines it says that are not covered are line 31-34 in printing.jl (https://app.codecov.io/gh/beacon-biosignals/KeywordSearch.jl/compare/11/changes#D1L31), but those are covered by the doctests for the show method for Or etc. I think maybe that print_tree_rstrip function is getting inlined and then codecov doesn't see coverage for it?

@ericphanson ericphanson marked this pull request as ready for review December 9, 2020 14:36
@ericphanson ericphanson changed the title fix up docs improve documentation, add doctests, fix bugs found on the way Dec 9, 2020
@testset "Doctests" begin
DocMeta.setdocmeta!(KeywordSearch, :DocTestSetup, :(using KeywordSearch);
recursive=true)
Documenter.doctest(KeywordSearch)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, cool.

Copy link
Contributor

@hannahilea hannahilea left a comment

Choose a reason for hiding this comment

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

I didn't know about Documenter.doctest! Niiice.

@ericphanson
Copy link
Member Author

I rebased after merging the others and fixed an issue with the printing. Not totally sure what happened, but I think doctests are very sensitive to whitespace, i.e. you need to start with the julia> line right after the ```jldoctest line.

I also learned from https://discourse.julialang.org/t/show-and-showcompact-on-custom-types/8493/4 that 3-argument show is preferred over checking compact as I was doing-- that's good to know, because compact wasn't triggering for arrays, only things like Sets An array of Corpuss will use the 2-argument show to print the entries, but a corpus alone will use the 3-argument one, so I use a 1-liner in the 2-argument version and add more details in the 3-argument one.

@ericphanson ericphanson merged commit f01fc4a into main Dec 9, 2020
@ericphanson ericphanson deleted the eph/betterdocs branch December 9, 2020 17:06
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.

2 participants