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

start functionalizing make screenshots #153

Merged
merged 10 commits into from
Jul 19, 2024
Merged

start functionalizing make screenshots #153

merged 10 commits into from
Jul 19, 2024

Conversation

kweav
Copy link
Contributor

@kweav kweav commented Jul 8, 2024

This PR begins implementing #145 by functionalizing make_screenshots.R, adding it to ottrpal.

The approach I took was creating params based on the optparse options info in the script. I also carried over the functionality of the script. I'll leave a few comments with questions. Later stacked PRs will set up tests and update the base_ottr image and update render_all.yml as described in #145

#' @param git_pat default is NULL; required argument; a Git secret
#' @param repo default is NULL; required argument; GitHub repository name, e.g., jhudsl/OTTR_Template
#' @param output_dir default is "resources/chapt_screen_images"; Output directory where the chapter's screen images should be stored
#' @param base_url default is NULL; rendered bookdown URL where screenshots are taken from, if NULL, the function will use the repo_name and and git_pat to find the base_url
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to edit this description to change it from the original in the script. How is it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like all the essentials are here! Only thing you could add if you wanted to be extra nice is a link to the page in GitHub about PATs: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens

R/screenshot.R Outdated
Comment on lines 3 to 4
#' @param git_pat default is NULL; required argument; a Git secret
#' @param repo default is NULL; required argument; GitHub repository name, e.g., jhudsl/OTTR_Template
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the best way to communicate that these are required arguments, but by default NULL?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would just not have them be NULL if they are required because then it will automatically throw an error if no argument is provided. And docs wise the way you say its "required" is fine 👍

R/screenshot.R Outdated
}

if (is.null(base_url)){
base_url <- cow::get_pages_url(repo_name = repo, git_pat = git_pat) #what if these arguments are still NULL/not supplied?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to make this cow function part of ottrpal?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes! That's next up! It's mentioned in #137 but I didn't realize I didn't make it its own issue so there is one now: jhudsl/cow#27


message(paste("Image Chapter key written to: ", file.path(output_folder, "chapter_urls.tsv")))

}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do I need to return something from this function?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think returning the file path to chapter_urls.tsv makes sense.

@kweav kweav requested a review from cansavvy July 8, 2024 19:39
@kweav
Copy link
Contributor Author

kweav commented Jul 8, 2024

pkgdown is failing because of trying to import cow as expected (and slacked)

Copy link
Contributor

@cansavvy cansavvy left a comment

Choose a reason for hiding this comment

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

This is looking good! 🎉 Some minor comments!

Is the unit test for this coming in a next PR?

R/screenshot.R Outdated
Comment on lines 3 to 4
#' @param git_pat default is NULL; required argument; a Git secret
#' @param repo default is NULL; required argument; GitHub repository name, e.g., jhudsl/OTTR_Template
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just not have them be NULL if they are required because then it will automatically throw an error if no argument is provided. And docs wise the way you say its "required" is fine 👍

#' @param git_pat default is NULL; required argument; a Git secret
#' @param repo default is NULL; required argument; GitHub repository name, e.g., jhudsl/OTTR_Template
#' @param output_dir default is "resources/chapt_screen_images"; Output directory where the chapter's screen images should be stored
#' @param base_url default is NULL; rendered bookdown URL where screenshots are taken from, if NULL, the function will use the repo_name and and git_pat to find the base_url
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like all the essentials are here! Only thing you could add if you wanted to be extra nice is a link to the page in GitHub about PATs: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens

R/screenshot.R Outdated Show resolved Hide resolved
R/screenshot.R Outdated
}

if (is.null(base_url)){
base_url <- cow::get_pages_url(repo_name = repo, git_pat = git_pat) #what if these arguments are still NULL/not supplied?
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes! That's next up! It's mentioned in #137 but I didn't realize I didn't make it its own issue so there is one now: jhudsl/cow#27


message(paste("Image Chapter key written to: ", file.path(output_folder, "chapter_urls.tsv")))

}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think returning the file path to chapter_urls.tsv makes sense.

@kweav
Copy link
Contributor Author

kweav commented Jul 9, 2024

This is looking good! 🎉 Some minor comments!

Thanks! And thanks for the comments and suggestions! They're very helpful

Is the unit test for this coming in a next PR?

Yes, the unit test will be the next PR. Can you point me to any examples/guides you want me to follow for creating a good unit test?

Co-authored-by: Candace Savonen <cansav09@gmail.com>
@kweav
Copy link
Contributor Author

kweav commented Jul 9, 2024

For this PR my next steps will include addressing the suggestions/feedback here
And I will add a stacked PR that incorporates a unit test
And then I can also try to move the cow function into ottrpal in another stacked PR if you'd like?

@kweav
Copy link
Contributor Author

kweav commented Jul 9, 2024

Latest commit addressed

  • adding the git pat link to the docs
  • removing NULL as a default from the two required arguments
  • tried to add an example of running the function (is that a good way of showing getting the secret?)
  • also have it return the file path now

@kweav
Copy link
Contributor Author

kweav commented Jul 9, 2024

@cansavvy after merging #154 and removing the cow dependency, I was hoping that pkgdown wouldn't fail. But now it's failing because there is no ‘webshot2’ package

Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  there is no package called ‘webshot2’

@kweav
Copy link
Contributor Author

kweav commented Jul 10, 2024

@cansavvy after merging #154 and removing the cow dependency, I was hoping that pkgdown wouldn't fail. But now it's failing because there is no ‘webshot2’ package

Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  there is no package called ‘webshot2’

We updated the base_ottr image in jhudsl/ottr-docker#27 to include webshot2 and its various dependencies

@kweav
Copy link
Contributor Author

kweav commented Jul 10, 2024

@cansavvy Given the R-CMD-check warnings about check_git_repo get_git_auth and get_repo_info not being global functions, I need to bring over those cow functions to ottrpal sooner rather than later, right? I know check_git_repo was next on my list, but should probably add the other two as well, right?

@cansavvy
Copy link
Contributor

@cansavvy Given the R-CMD-check warnings about check_git_repo get_git_auth and get_repo_info not being global functions, I need to bring over those cow functions to ottrpal sooner rather than later, right? I know check_git_repo was next on my list, but should probably add the other two as well, right?

Yes this needs to be done. Probably transferring these at the same time makes sense. But probably in a next PR. 👍

@cansavvy
Copy link
Contributor

Fixed the description file so now this is ready to merge!

Next PR can include more unit tests for this!

@cansavvy cansavvy merged commit 3d56b9f into main Jul 19, 2024
2 checks passed
@cansavvy cansavvy deleted the ki/refactor branch July 19, 2024 16:12
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