Skip to content

New hook to check contents of _pkgdown.yaml contains all topics #378

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

Closed
gravesti opened this issue Mar 3, 2022 · 10 comments · Fixed by #393
Closed

New hook to check contents of _pkgdown.yaml contains all topics #378

gravesti opened this issue Mar 3, 2022 · 10 comments · Fixed by #393

Comments

@gravesti
Copy link
Contributor

gravesti commented Mar 3, 2022

I'd like to propose a new hook that checks if _pkgdown.yaml contains all of the topics in man/. I'm not sure if this is a general enough issue but currently we are wasting a lot of time with commits failing the upstream checks when pkgdown tries to rebuild the site.
Errors like:
* Topics missing from index: my_new_function

My prototype hook simply reads in each of the .Rd files and checks that one of the \alias{} entries is included in a contents section of _pkgdown.yaml. It might be interesting to check the other direction too.

@lorenzwalthert
Copy link
Owner

Thanks @gravesti for raising this. I think indeed it could be useful. However, I'd not try to emulate what {pkgdown} does as a check, as this is less reliable than using the {pkgdown} functionality directly and may also change in the future. Steps involved to leverage existing infra:

  • Find the relevant code in {pkgdown}. E.g. from the error / warning message you mention, one could do a full text search in the source code of {pkgdown} to find it.
  • Create a hook with it.
  • Ask the maintainers of {pkgdown} to export that functionality if not already the case.

Are you interested in contributing that?

@gravesti
Copy link
Contributor Author

gravesti commented Mar 3, 2022

Hi @lorenzwalthert, yes I'm interested in looking at this further. I'm hoping to avoid having to run too much of the pkgdown process each commit though.

@gravesti
Copy link
Contributor Author

gravesti commented Mar 4, 2022

It seems it would be enough to test if generating the indexes completes without error, ie to run

pkgdown::build_reference_index()
pkgdown::build_articles_index()

Unfortunately this brings a dependency on Pandoc as it does actually builds the html index pages. Is it possible within pre-commit checks? Otherwise I'll ask if the pkgdown devs can export some of the internal functions.

@lorenzwalthert
Copy link
Owner

Pandoc dependency sounds like trouble, in particular in pre-commit.ci settings. Did you find the internal functions in {pkgdown} that are responsible to trigger * Topics missing from index: my_new_function. It would be nice if they exported it, but we can possibly also rely on internal methods as a strategy of last resort.

@gravesti
Copy link
Contributor Author

gravesti commented Mar 4, 2022

Yes, I could find the functions which generate the errors.

build_reference_index() calls data_reference_index() which has the logic we don't want to reimplement to process everything and it calls a fairly trivial check_missing_topics() which generates the actual warning.

For vignettes, there's just build_articles_index() which calls data_articles_index() which does the processing and gives the warning.

The build_*_index() functions have the call to render_page() which is where the Pandoc stuff comes in. The data_*_index() functions would be good to use I think but are not exported.

One idea I had is to define a dummy render_page(), but would allow us to use the build_*_index() functions as-is.
https://github.com/r-lib/pkgdown/blob/f85cfa24fbf0c809c4ca9dbd23a53742165367cb/R/build-reference.R#L243

@lorenzwalthert
Copy link
Owner

lorenzwalthert commented May 3, 2022

Do you need assistance in proceeding? I think your approach makes sense. We can also monky patch our dummy render_page() into build_*_index(), e.g. with {mockr} or {mockery}.

@gravesti
Copy link
Contributor Author

gravesti commented May 5, 2022

Good idea. I submitted an issue and pull request to pkgdown but didn't get a response. I wasn't aware of those mock packages. I'll prepare something today.

@gravesti
Copy link
Contributor Author

gravesti commented May 5, 2022

I'm wondering about the tests for this hook. I think it will need a minimal package folder structure.
Is the idea to put all the files in tests/test_that/reference and pass them to run_test artifacts?

@lorenzwalthert
Copy link
Owner

lorenzwalthert commented Dec 6, 2022

Should be added to the template for packages.

@lorenzwalthert
Copy link
Owner

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants