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

Throw an error for @importFrom unknown export #1458

Merged
merged 11 commits into from Nov 10, 2023
Merged

Conversation

MichaelChirico
Copy link
Contributor

@MichaelChirico MichaelChirico commented Jan 16, 2023

Closes #1409.

This is a rough / off-the-cuff version. Wanted to checkpoint here to get high-level feedback, there's still TODO:

  • Adapt to internal package style (e.g. cli)
  • Add tests
  • Add NEWS

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me.

@MichaelChirico
Copy link
Contributor Author

I can't make snapshots from my current machine, so I'll try and pull them from the GHA artifacts.

Should be ready for review anyway.

R/namespace.R Outdated Show resolved Hide resolved
R/namespace.R Outdated Show resolved Hide resolved
R/namespace.R Outdated Show resolved Hide resolved
@hadley hadley merged commit 38166f0 into r-lib:main Nov 10, 2023
12 checks passed
@hadley
Copy link
Member

hadley commented Nov 10, 2023

Thanks!

pkg <- x$val[1L]
if (requireNamespace(pkg, quietly = TRUE)) {
importing <- x$val[-1L]
unknown_idx <- !importing %in% getNamespaceExports(pkg)
Copy link
Contributor Author

@MichaelChirico MichaelChirico Jan 15, 2024

Choose a reason for hiding this comment

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

two issues with this PR in retrospect as surfaced by #1570:

  1. importing can be like "%>%" or `%>%` or '%>%' but getNamespaceExports() will always just be the plain symbol (%>%)
  2. importing[!unknown_idx] might drop everything --> output becomes importFrom($PKG,)

How would you recommend approaching these?

  1. Is a bit tricky because we have to normalize the quotes, I guess we can do gsub("^(`|'|\")(.*)\\1$", "\\1", importing). This could be a helper alongside has_quotes() Initially, I was worried about collision where you try and import a really weirdly-named object like as.name("'%>%'"), but I guess {roxygen2} has always made that difficult. And a quick search doesn't turn up any usage of this anyway: https://github.com/search?q=lang%3AR+%2F%5Cn%5Cs*%28%22%27.*%27%22%7C%27%22.*%22%27%7C%60%22.*%22%60%7C%60%27.*%27%60%7C%22%60.*%60%22%7C%27%60.*%60%27%29%5Cs*%3C-%2F+-path%3A.Rd&type=code
  2. Should this method just return(NULL) if all(unknown_idx)?

Copy link
Member

@hadley hadley Jan 16, 2024

Choose a reason for hiding this comment

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

  1. Yeah, I think strip_quotes() seems reasonable.
  2. Yes, I think so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks! that's basically how I did #1574 so let's continue there.

@MichaelChirico MichaelChirico deleted the patch-1 branch January 16, 2024 15:36
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.

Check imports when generating the NAMESPACE file
2 participants