Skip to content

Commit

Permalink
Merge pull request #401 from rstudio/mm-map-types
Browse files Browse the repository at this point in the history
Map schema content types to Connect ones
  • Loading branch information
mmarchetti authored Nov 29, 2023
2 parents 4225f09 + fbd5a5b commit 211d236
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 64 deletions.
11 changes: 5 additions & 6 deletions cmd/connect-client/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package commands
import (
"fmt"

"github.com/rstudio/connect-client/internal/apptypes"
"github.com/rstudio/connect-client/internal/bundles"
"github.com/rstudio/connect-client/internal/cli_types"
"github.com/rstudio/connect-client/internal/config"
Expand All @@ -22,7 +21,7 @@ func (cmd *InitCommand) inspectProjectType(log logging.Logger) (*inspect.Content
if err != nil {
return nil, fmt.Errorf("error detecting content type: %w", err)
}
log.Info("Deployment type", "Entrypoint", contentType.Entrypoint, "AppMode", contentType.AppMode)
log.Info("Deployment type", "Entrypoint", contentType.Entrypoint, "AppMode", contentType.Type)
return contentType, nil
}

Expand All @@ -33,8 +32,8 @@ type InitCommand struct {
config *config.Config
}

func (cmd *InitCommand) requiresPython(appMode apptypes.AppMode) (bool, error) {
if appMode.IsPythonContent() {
func (cmd *InitCommand) requiresPython(contentType config.ContentType) (bool, error) {
if contentType.IsPythonContent() {
return true, nil
}
if cmd.Python.Path() != "" {
Expand Down Expand Up @@ -79,10 +78,10 @@ func (cmd *InitCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContex
if err != nil {
return err
}
cmd.config.Type = contentType.AppMode
cmd.config.Type = contentType.Type
cmd.config.Entrypoint = contentType.Entrypoint

requiresPython, err := cmd.requiresPython(contentType.AppMode)
requiresPython, err := cmd.requiresPython(contentType.Type)
if err != nil {
return err
}
Expand Down
30 changes: 26 additions & 4 deletions internal/bundles/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,33 @@ func NewManifest() *Manifest {
}
}

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

func NewManifestFromConfig(cfg *config.Config) *Manifest {
contentType, ok := connectContentTypeMap[cfg.Type]
if !ok {
contentType = apptypes.UnknownMode
}
m := &Manifest{
Version: 1,
Metadata: Metadata{
AppMode: cfg.Type,
AppMode: contentType,
Entrypoint: cfg.Entrypoint,
},
Jupyter: nil,
Expand All @@ -185,10 +207,10 @@ func NewManifestFromConfig(cfg *config.Config) *Manifest {
}
}
switch cfg.Type {
case apptypes.StaticRmdMode:
case apptypes.ShinyRmdMode:
case config.ContentTypeRMarkdown:
case config.ContentTypeRMarkdownShiny:
m.Metadata.PrimaryRmd = cfg.Entrypoint
case apptypes.StaticMode:
case config.ContentTypeHTML:
m.Metadata.PrimaryHtml = cfg.Entrypoint
}
return m
Expand Down
3 changes: 1 addition & 2 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io/fs"
"testing"

"github.com/rstudio/connect-client/internal/apptypes"
"github.com/rstudio/connect-client/internal/util"
"github.com/rstudio/connect-client/internal/util/utiltest"
"github.com/spf13/afero"
Expand Down Expand Up @@ -60,7 +59,7 @@ func (s *ConfigSuite) TestFromFile() {
cfg, err := FromFile(path)
s.NoError(err)
s.NotNil(cfg)
s.Equal(apptypes.AppMode("python-dash"), cfg.Type)
s.Equal(ContentTypePythonDash, cfg.Type)
}

func (s *ConfigSuite) TestFromFileErr() {
Expand Down
65 changes: 48 additions & 17 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,57 @@ package config

// Copyright (C) 2023 by Posit Software, PBC.

import (
"github.com/rstudio/connect-client/internal/apptypes"
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"
)

func (t ContentType) IsPythonContent() bool {
switch t {
case ContentTypeJupyterNotebook:
case ContentTypeJupyterVoila:
case ContentTypePythonBokeh:
case ContentTypePythonDash:
case ContentTypePythonFastAPI:
case ContentTypePythonFlask:
case ContentTypePythonShiny:
case ContentTypePythonStreamlit:
return true
}
return false
}

type Config struct {
Schema SchemaURL `toml:"$schema" json:"$schema"`
Type apptypes.AppMode `toml:"type" json:"type"`
Entrypoint string `toml:"entrypoint,omitempty" json:"entrypoint,omitempty"`
Title string `toml:"title,omitempty" json:"title,omitempty"`
Description string `toml:"description,multiline,omitempty" json:"description,omitempty"`
ThumbnailFile string `toml:"thumbnail,omitempty" json:"thumbnail,omitempty"`
Tags []string `toml:"tags,omitempty" json:"tags,omitempty"`
Python *Python `toml:"python,omitempty" json:"python,omitempty"`
R *R `toml:"r,omitempty" json:"r,omitempty"`
Quarto *Quarto `toml:"quarto,omitempty" json:"quarto,omitempty"`
Environment Environment `toml:"environment,omitempty" json:"environment,omitempty"`
Secrets []string `toml:"secrets,omitempty" json:"secrets,omitempty"`
Schedules []Schedule `toml:"schedules,omitempty" json:"schedules,omitempty"`
Access *Access `toml:"access,omitempty" json:"access,omitempty"`
Connect *Connect `toml:"connect,omitempty" json:"connect,omitempty"`
Schema SchemaURL `toml:"$schema" json:"$schema"`
Type ContentType `toml:"type" json:"type"`
Entrypoint string `toml:"entrypoint,omitempty" json:"entrypoint,omitempty"`
Title string `toml:"title,omitempty" json:"title,omitempty"`
Description string `toml:"description,multiline,omitempty" json:"description,omitempty"`
ThumbnailFile string `toml:"thumbnail,omitempty" json:"thumbnail,omitempty"`
Tags []string `toml:"tags,omitempty" json:"tags,omitempty"`
Python *Python `toml:"python,omitempty" json:"python,omitempty"`
R *R `toml:"r,omitempty" json:"r,omitempty"`
Quarto *Quarto `toml:"quarto,omitempty" json:"quarto,omitempty"`
Environment Environment `toml:"environment,omitempty" json:"environment,omitempty"`
Secrets []string `toml:"secrets,omitempty" json:"secrets,omitempty"`
Schedules []Schedule `toml:"schedules,omitempty" json:"schedules,omitempty"`
Access *Access `toml:"access,omitempty" json:"access,omitempty"`
Connect *Connect `toml:"connect,omitempty" json:"connect,omitempty"`
}

type SchemaURL string
Expand Down
10 changes: 5 additions & 5 deletions internal/inspect/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

"github.com/rstudio/connect-client/internal/apptypes"
"github.com/rstudio/connect-client/internal/config"
"github.com/rstudio/connect-client/internal/util"
"github.com/rstudio/connect-client/internal/util/utiltest"
"github.com/spf13/afero"
Expand Down Expand Up @@ -35,7 +35,7 @@ func (s *AllSuite) TestInferTypeDirectory() {
t, err := detector.InferType(path)
s.Nil(err)
s.Equal(&ContentType{
AppMode: apptypes.PythonDashMode,
Type: config.ContentTypePythonDash,
Entrypoint: appFilename,
RequiresPython: true,
}, t)
Expand All @@ -57,7 +57,7 @@ func (s *AllSuite) TestInferTypeFileLowerPriority() {
t, err := detector.InferType(htmlPath)
s.Nil(err)
s.Equal(&ContentType{
AppMode: apptypes.StaticMode,
Type: config.ContentTypeHTML,
Entrypoint: htmlFilename,
}, t)
}
Expand All @@ -78,7 +78,7 @@ func (s *AllSuite) TestInferTypeFileHigherPriority() {
t, err := detector.InferType(appPath)
s.Nil(err)
s.Equal(&ContentType{
AppMode: apptypes.PythonDashMode,
Type: config.ContentTypePythonDash,
Entrypoint: appFilename,
RequiresPython: true,
}, t)
Expand All @@ -99,7 +99,7 @@ func (s *AllSuite) TestInferTypeDirectoryPriority() {
t, err := detector.InferType(path)
s.Nil(err)
s.Equal(&ContentType{
AppMode: apptypes.PythonDashMode,
Type: config.ContentTypePythonDash,
Entrypoint: appFilename,
RequiresPython: true,
}, t)
Expand Down
4 changes: 2 additions & 2 deletions internal/inspect/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package inspect
// Copyright (C) 2023 by Posit Software, PBC.

import (
"github.com/rstudio/connect-client/internal/apptypes"
"github.com/rstudio/connect-client/internal/config"
"github.com/rstudio/connect-client/internal/util"
)

Expand All @@ -30,7 +30,7 @@ func (d *StaticHTMLDetector) InferType(path util.Path) (*ContentType, error) {
}
if entrypoint != "" {
return &ContentType{
AppMode: apptypes.StaticMode,
Type: config.ContentTypeHTML,
Entrypoint: entrypoint,
}, nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/inspect/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"errors"
"testing"

"github.com/rstudio/connect-client/internal/apptypes"
"github.com/rstudio/connect-client/internal/config"
"github.com/rstudio/connect-client/internal/util"
"github.com/rstudio/connect-client/internal/util/utiltest"
"github.com/spf13/afero"
Expand All @@ -32,7 +32,7 @@ func (s *StaticHTMLDetectorSuite) TestInferTypeSpecifiedFile() {
t, err := detector.InferType(path)
s.Nil(err)
s.Equal(&ContentType{
AppMode: apptypes.StaticMode,
Type: config.ContentTypeHTML,
Entrypoint: filename,
}, t)
}
Expand All @@ -47,7 +47,7 @@ func (s *StaticHTMLDetectorSuite) TestInferTypePreferredFilename() {
t, err := detector.InferType(path)
s.Nil(err)
s.Equal(&ContentType{
AppMode: apptypes.StaticMode,
Type: config.ContentTypeHTML,
Entrypoint: filename,
}, t)
}
Expand All @@ -62,7 +62,7 @@ func (s *StaticHTMLDetectorSuite) TestInferTypeOnlyHTMLFile() {
t, err := detector.InferType(path)
s.Nil(err)
s.Equal(&ContentType{
AppMode: apptypes.StaticMode,
Type: config.ContentTypeHTML,
Entrypoint: filename,
}, t)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/inspect/infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package inspect
import (
"io"

"github.com/rstudio/connect-client/internal/apptypes"
"github.com/rstudio/connect-client/internal/config"
"github.com/rstudio/connect-client/internal/util"
)

type ContentType struct {
AppMode apptypes.AppMode
Type config.ContentType
Entrypoint string
RequiresR bool
RequiresPython bool
Expand Down
6 changes: 3 additions & 3 deletions internal/inspect/notebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io"
"strings"

"github.com/rstudio/connect-client/internal/apptypes"
"github.com/rstudio/connect-client/internal/config"
"github.com/rstudio/connect-client/internal/util"
)

Expand Down Expand Up @@ -53,9 +53,9 @@ func (d *NotebookDetector) InferType(path util.Path) (*ContentType, error) {
RequiresPython: true,
}
if isVoila {
t.AppMode = apptypes.JupyterVoilaMode
t.Type = config.ContentTypeJupyterVoila
} else {
t.AppMode = apptypes.StaticJupyterMode
t.Type = config.ContentTypeJupyterNotebook
}
return t, nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/inspect/notebook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"testing"

"github.com/rstudio/connect-client/internal/apptypes"
"github.com/rstudio/connect-client/internal/config"
"github.com/rstudio/connect-client/internal/util"
"github.com/rstudio/connect-client/internal/util/utiltest"
"github.com/spf13/afero"
Expand Down Expand Up @@ -100,7 +100,7 @@ func (s *NotebookDetectorSuite) TestInferTypePlainNotebook() {
t, err := detector.InferType(path)
s.Nil(err)
s.Equal(&ContentType{
AppMode: apptypes.StaticJupyterMode,
Type: config.ContentTypeJupyterNotebook,
Entrypoint: filename,
RequiresPython: true,
}, t)
Expand All @@ -116,7 +116,7 @@ func (s *NotebookDetectorSuite) TestInferTypeVoilaNotebook() {
t, err := detector.InferType(path)
s.Nil(err)
s.Equal(&ContentType{
AppMode: apptypes.JupyterVoilaMode,
Type: config.ContentTypeJupyterVoila,
Entrypoint: filename,
RequiresPython: true,
}, t)
Expand Down
Loading

0 comments on commit 211d236

Please sign in to comment.