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

Enable detection and deployment of Quarto scripts #2424

Merged
merged 9 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/configuration.md
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the type section under General settings also needs an update

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Indicates the type of content being deployed. Valid values are:
- `python-shiny`
- `python-streamlit`
- `quarto-shiny`
- `quarto`
- `quarto-static`
- `quarto` (Deprecated use `quarto-static` instead)
- `r-plumber`
- `r-shiny`
- `rmd-shiny`
Expand Down Expand Up @@ -76,7 +77,7 @@ Example:

```toml
"$schema" = "https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json"
type = "quarto"
type = "quarto-static"
entrypoint = "report.qmd"
title = "Regional Quarterly Sales Report"
description = "This is the quarterly sales report, broken down by region."
Expand Down
3 changes: 3 additions & 0 deletions extensions/vscode/src/api/types/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export enum ContentType {
PYTHON_STREAMLIT = "python-streamlit",
QUARTO_SHINY = "quarto-shiny",
QUARTO = "quarto",
QUARTO_STATIC = "quarto-static",
R_PLUMBER = "r-plumber",
R_SHINY = "r-shiny",
RMD_SHINY = "rmd-shiny",
Expand All @@ -74,6 +75,7 @@ export const allValidContentTypes: ContentType[] = [
ContentType.PYTHON_STREAMLIT,
ContentType.QUARTO_SHINY,
ContentType.QUARTO,
ContentType.QUARTO_STATIC,
ContentType.R_PLUMBER,
ContentType.R_SHINY,
ContentType.RMD_SHINY,
Expand All @@ -92,6 +94,7 @@ export const contentTypeStrings = {
[ContentType.PYTHON_STREAMLIT]: "run with Streamlit",
[ContentType.QUARTO_SHINY]: "render with Quarto and run embedded Shiny app",
[ContentType.QUARTO]: "render with Quarto",
[ContentType.QUARTO_STATIC]: "render with Quarto",
[ContentType.R_PLUMBER]: "run with Plumber",
[ContentType.R_SHINY]: "run with R Shiny",
[ContentType.RMD_SHINY]:
Expand Down
31 changes: 16 additions & 15 deletions internal/clients/connect/apptypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,22 @@ func (t AppMode) Description() string {
}

var connectContentTypeMap = map[config.ContentType]AppMode{
config.ContentTypeHTML: StaticMode,
config.ContentTypeJupyterNotebook: StaticJupyterMode,
config.ContentTypeJupyterVoila: JupyterVoilaMode,
config.ContentTypePythonBokeh: PythonBokehMode,
config.ContentTypePythonDash: PythonDashMode,
config.ContentTypePythonFastAPI: PythonFastAPIMode,
config.ContentTypePythonFlask: PythonAPIMode,
config.ContentTypePythonShiny: PythonShinyMode,
config.ContentTypePythonStreamlit: PythonStreamlitMode,
config.ContentTypeQuartoShiny: ShinyQuartoMode,
config.ContentTypeQuarto: StaticQuartoMode,
config.ContentTypeRPlumber: PlumberAPIMode,
config.ContentTypeRShiny: ShinyMode,
config.ContentTypeRMarkdownShiny: ShinyRmdMode,
config.ContentTypeRMarkdown: StaticRmdMode,
config.ContentTypeHTML: StaticMode,
config.ContentTypeJupyterNotebook: StaticJupyterMode,
config.ContentTypeJupyterVoila: JupyterVoilaMode,
config.ContentTypePythonBokeh: PythonBokehMode,
config.ContentTypePythonDash: PythonDashMode,
config.ContentTypePythonFastAPI: PythonFastAPIMode,
config.ContentTypePythonFlask: PythonAPIMode,
config.ContentTypePythonShiny: PythonShinyMode,
config.ContentTypePythonStreamlit: PythonStreamlitMode,
config.ContentTypeQuartoShiny: ShinyQuartoMode,
config.ContentTypeQuartoDeprecated: StaticQuartoMode,
config.ContentTypeQuarto: StaticQuartoMode,
config.ContentTypeRPlumber: PlumberAPIMode,
config.ContentTypeRShiny: ShinyMode,
config.ContentTypeRMarkdownShiny: ShinyRmdMode,
config.ContentTypeRMarkdown: StaticRmdMode,
}

func AppModeFromType(t config.ContentType) AppMode {
Expand Down
9 changes: 4 additions & 5 deletions internal/clients/connect/client_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,10 @@ func (c *ConnectClient) ValidateDeploymentTarget(contentID types.ContentID, cfg
}

// Verify content type has not changed
log.Info("Verifying content type is the same")
existingType := ContentTypeFromAppMode(content.AppMode)
configType := cfg.Type
if existingType != configType && existingType != config.ContentTypeUnknown {
msg := fmt.Sprintf("Content was previously deployed as '%s' but your configuration is set to '%s'.", existingType, configType)
log.Info("Verifying app mode is the same")
configAppType := AppModeFromType(cfg.Type)
if content.AppMode != configAppType && content.AppMode != UnknownMode {
msg := fmt.Sprintf("Content was previously deployed as '%s' but your configuration is set to '%s'.", ContentTypeFromAppMode(content.AppMode), cfg.Type)
return types.NewAgentError(events.AppModeNotModifiableCode, errors.New(msg), nil)
}

Expand Down
34 changes: 18 additions & 16 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ package config
type ContentType string

const (
ContentTypeHTML ContentType = "html"
ContentTypeJupyterNotebook ContentType = "jupyter-notebook"
ContentTypeJupyterVoila ContentType = "jupyter-voila"
ContentTypePythonBokeh ContentType = "python-bokeh"
ContentTypePythonDash ContentType = "python-dash"
ContentTypePythonFastAPI ContentType = "python-fastapi"
ContentTypePythonFlask ContentType = "python-flask"
ContentTypePythonShiny ContentType = "python-shiny"
ContentTypePythonStreamlit ContentType = "python-streamlit"
ContentTypeQuartoShiny ContentType = "quarto-shiny"
ContentTypeQuarto ContentType = "quarto"
ContentTypeRPlumber ContentType = "r-plumber"
ContentTypeRShiny ContentType = "r-shiny"
ContentTypeRMarkdownShiny ContentType = "rmd-shiny"
ContentTypeRMarkdown ContentType = "rmd"
ContentTypeUnknown ContentType = "unknown"
ContentTypeHTML ContentType = "html"
ContentTypeJupyterNotebook ContentType = "jupyter-notebook"
ContentTypeJupyterVoila ContentType = "jupyter-voila"
ContentTypePythonBokeh ContentType = "python-bokeh"
ContentTypePythonDash ContentType = "python-dash"
ContentTypePythonFastAPI ContentType = "python-fastapi"
ContentTypePythonFlask ContentType = "python-flask"
ContentTypePythonShiny ContentType = "python-shiny"
ContentTypePythonStreamlit ContentType = "python-streamlit"
ContentTypeQuartoShiny ContentType = "quarto-shiny"
ContentTypeQuartoDeprecated ContentType = "quarto"
ContentTypeQuarto ContentType = "quarto-static"
ContentTypeRPlumber ContentType = "r-plumber"
ContentTypeRShiny ContentType = "r-shiny"
ContentTypeRMarkdownShiny ContentType = "rmd-shiny"
ContentTypeRMarkdown ContentType = "rmd"
ContentTypeUnknown ContentType = "unknown"
)

func AllValidContentTypeNames() []string {
Expand All @@ -35,6 +36,7 @@ func AllValidContentTypeNames() []string {
string(ContentTypePythonShiny),
string(ContentTypePythonStreamlit),
string(ContentTypeQuartoShiny),
string(ContentTypeQuartoDeprecated),
string(ContentTypeQuarto),
string(ContentTypeRPlumber),
string(ContentTypeRShiny),
Expand Down
2 changes: 1 addition & 1 deletion internal/inspect/detectors/quarto.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (d *QuartoDetector) getTitle(inspectOutput *quartoInspectOutput, entrypoint
return ""
}

var quartoSuffixes = []string{".qmd", ".Rmd", ".ipynb"}
var quartoSuffixes = []string{".qmd", ".Rmd", ".ipynb", ".R", ".py", ".jl"}

func (d *QuartoDetector) findEntrypoints(base util.AbsolutePath) ([]util.AbsolutePath, error) {
allPaths := []util.AbsolutePath{}
Expand Down
42 changes: 42 additions & 0 deletions internal/inspect/detectors/quarto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,45 @@ func (s *QuartoDetectorSuite) TestInferTypeRevalJSQuartoShiny() {
R: &config.R{},
}, configs[0])
}

func (s *QuartoDetectorSuite) TestInferTypeQuartoScriptPy() {
if runtime.GOOS == "windows" {
s.T().Skip("This test does not run on Windows")
}
configs := s.runInferType("quarto-script-py")
s.Len(configs, 1)
s.Equal(&config.Config{
Schema: schema.ConfigSchemaURL,
Type: config.ContentTypeQuarto,
Entrypoint: "script.py",
Title: "Penguin data transformations",
Validate: true,
Files: []string{"/script.py", "/_quarto.yml"},
Python: &config.Python{},
Quarto: &config.Quarto{
Version: "1.5.54",
Engines: []string{"jupyter"},
},
}, configs[0])
}

func (s *QuartoDetectorSuite) TestInferTypeQuartoScriptR() {
if runtime.GOOS == "windows" {
s.T().Skip("This test does not run on Windows")
}
configs := s.runInferType("quarto-script-r")
s.Len(configs, 1)
s.Equal(&config.Config{
Schema: schema.ConfigSchemaURL,
Type: config.ContentTypeQuarto,
Entrypoint: "script.R",
Title: "Penguin data transformations",
Validate: true,
Files: []string{"/script.R", "/_quarto.yml"},
Quarto: &config.Quarto{
Version: "1.5.54",
Engines: []string{"knitr"},
},
R: &config.R{},
}, configs[0])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
project:
title: "Penguin data transformations"
Loading