Skip to content

include _quarto.yml if available - #11201

Merged
kevinushey merged 7 commits into
rstudio:mainfrom
romainfrancois:bugfix/include_quarto_yml_10995
May 24, 2022
Merged

kevinushey merged 7 commits into
rstudio:mainfrom
romainfrancois:bugfix/include_quarto_yml_10995

Conversation

@romainfrancois

Copy link
Copy Markdown
Contributor

Intent

addresses #10995

Approach

If a _quarto.yml file is found in the same directory as the .qmd file, then add it:

      if (file.exists(file.path(dirname(quartoSrcFile), "_quarto.yml"))) {
        file_list <- c(file_list, "_quarto.yml")
      }

Automated Tests

added this:

test_that(".rs.rsconnectDeployList() includes _quarto.yml file (#10995 )", {
   dir.create(tf <- tempfile()); on.exit(unlink(tf, TRUE, TRUE))

   target <- file.path(tf, "test.qmd")
   writeLines("---\ntitle: quarto document\n---\n", target)
   writeLines('project:\n  title: "test"\n', file.path(tf, "_quarto.yml"))

   res <- .rs.rsconnectDeployList(target, FALSE, target)[[1L]]
   expect_true("_quarto.yml" %in% res)
})

QA Notes

Add additional information for QA on how to validate the change, paying special attention to the level of risk, adjacent areas that could be affected by the change, and any important contextual information not present in the linked issues.

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

@romainfrancois

Copy link
Copy Markdown
Contributor Author

cc @toph-allen, should this rather be the _quarto.yml file in the project directory, instead of the _quarto.yml file in the same directory as the .qmd ?

@romainfrancois

Copy link
Copy Markdown
Contributor Author

Alternatively, it could be a job for rs_quartoFileResources() ? cc @jjallaire

SEXP rs_quartoFileResources(SEXP targetSEXP)
{
   std::vector<std::string> resources;
   std::string target = r::sexp::safeAsString(targetSEXP);
   if (!target.empty())
   {
      FilePath qmdPath = module_context::resolveAliasedPath(target);
      json::Object jsonInspect;
      Error error = quartoInspect(
        string_utils::utf8ToSystem(qmdPath.getAbsolutePath()), &jsonInspect
      );
      if (!error)
      {
         jsonInspect["resources"].getArray().toVectorString(resources);
      }
      else
      {
         LOG_ERROR(error);
      }
   }

   r::sexp::Protect protect;
   return r::sexp::create(resources, &protect);
}

@romainfrancois
romainfrancois requested a review from jjallaire May 13, 2022 12:32
@jgutman
jgutman self-requested a review May 13, 2022 15:13
@jgutman

jgutman commented May 16, 2022

Copy link
Copy Markdown
Contributor

cc @toph-allen, should this rather be the _quarto.yml file in the project directory, instead of the _quarto.yml file in the same directory as the .qmd ?

Haven't seen an answer yet from @toph-allen, but I believe it should always be _quarto.yml in the root of the project directory, regardless of the exact location of the qmd file. I think even if your project has subfolders with quarto docs, you have just the one _quarto.yml with all the project level metadata at the root

@toph-allen

Copy link
Copy Markdown

@jgutman I don't have an authoritative answer to this, sorry. I'd check the quarto.org docs maybe, or find ask closer to the Quarto project?

The closest thing I can see to a section on _quarto.yml is this: https://quarto.org/docs/projects/quarto-projects.html#shared-metadata

Seems like it is at project level, rather than dir.

Comment thread src/cpp/tests/testthat/test-rsconnect.R Resolved
@jgutman

jgutman commented May 16, 2022

Copy link
Copy Markdown
Contributor

@jgutman I don't have an authoritative answer to this, sorry. I'd check the quarto.org docs maybe, or find ask closer to the Quarto project?

The closest thing I can see to a section on _quarto.yml is this: https://quarto.org/docs/projects/quarto-projects.html#shared-metadata

Seems like it is at project level, rather than dir.

Thanks for the link! That seems to confirm my understanding that _quarto.yml is project level metadata and there should be only 1 per project. However, that link also reveals that there can be a directory level metadata file called _metadata.yml, which does live in the same subdirectly as the quarto doc to be published, and can contain additional metadata.

@romainfrancois I think we should update this PR to 1) look for _quarto.yml in the project root, not the source file subdirectory, and 2) also look for a file called _metadata.yml in the source file subdirectory, and add that to the file list if it exists as well

@romainfrancois
romainfrancois force-pushed the bugfix/include_quarto_yml_10995 branch from ccd3cf7 to b596f65 Compare May 17, 2022 07:00
@romainfrancois

Copy link
Copy Markdown
Contributor Author

Thanks @jgutman. Modified now so that it relies on quarto to tell what the project is, with quarto inspect because IIUC this is orthogonal to rstudio projects.

With this hierarchy:

<rstudio_project>
  |--  _quarto.yml
  |--  main.qmd
  |-- sub
      |--  _metadata.yml
      |--  sub.qmd

I'm getting:

image

image

The tests do stress more cases.

@romainfrancois

This comment was marked as resolved.

@romainfrancois
romainfrancois requested review from jgutman and kevinushey and removed request for jjallaire May 17, 2022 12:05
@romainfrancois

Copy link
Copy Markdown
Contributor Author

cc @kevinushey because you might have some views on rs_quartoFileProject re the json and the output SEXP.

@jjallaire

Copy link
Copy Markdown
Member

If the _quarto.yml file is in a parent directory, is that properly handled during bundling/deployment? (i.e. how does it handle the relative path to something outside of the content directory)

@jgutman jgutman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM although I'm not super familiar with the runQuarto({"inspect"...) part of it

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.

5 participants