Skip to content

Commit

Permalink
Add dvc.yaml pipeline snippets (#4233)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon authored Jul 7, 2023
1 parent 8bffe8b commit b59033c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
9 changes: 8 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"Machine Learning",
"Data Science",
"Visualization",
"SCM Providers"
"SCM Providers",
"Snippets"
],
"galleryBanner": {
"color": "#333",
Expand Down Expand Up @@ -1380,6 +1381,12 @@
}
]
},
"snippets": [
{
"language": "yaml",
"path": "./snippets/dvc-yaml.code-snippets"
}
],
"viewsContainers": {
"activitybar": [
{
Expand Down
54 changes: 54 additions & 0 deletions extension/snippets/dvc-yaml.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"Get Started with DVC pipelines": {
"prefix": "dvc-help",
"body": [
"# The DVC for VS Code extension provides snippets to help with building dvc.yaml pipelines.",
"# These snippets, all prefixed with dvc-, are designed to give pointers on basic usage.",
"# Type dvc- in the editor to see the list of available snippets.",
"# Visit https://dvc.org/doc/user-guide/project-structure/dvcyaml-files for further details on building pipelines.",
"# On-hover information and completions will be provided for each of the keys in a dvc.yaml file if the redhat.yaml extension is installed."
],
"description": "Information on the support provided for building dvc.yaml pipelines"
},
"Pipeline Stage Template": {
"prefix": "dvc-pipeline-stage",
"body": [
" ${1:stage name}:",
" cmd: ${2:command for the stage, e.g. python train.py}",
" deps:",
" - ${3:list dependencies for the stage, e.g. train.py}",
" params:",
" - ${4:list params file(s) for the stage, e.g params.yaml}",
" metrics:",
" - ${5:list metric file(s) for the stage, e.g metrics.json}",
" outs:",
" - ${6:list output(s) of the stage, e.g. model.pkl}"
],
"description": "Stage template for dvc.yaml pipeline"
},
"Minimal Pipeline Stage Template": {
"prefix": "dvc-pipeline-minimal-stage",
"body": [
" ${1:stage name}:",
" cmd: ${2:command for the stage, e.g. python train.py}",
" deps:",
" - ${3:list dependencies for the stage, e.g. train.py}",
" outs:",
" - ${4:list output(s) of the stage, e.g. model.pkl}"
],
"description": "Minimal stage template for dvc.yaml pipeline"
},
"Foreach Pipeline Stage Template": {
"prefix": "dvc-pipeline-foreach-stage",
"body": [
" ${1:stage name}:",
" foreach:",
" - ${2:list of simple values to iterate over}",
" do:",
" cmd: ${3:command to be run for each templated item, e.g python evaluate.py} \"\\${item}\"",
" outs:",
" - \\${item}.${5:suffix for the templated output file, e.g. pkl}"
],
"description": "Foreach stage template for dvc.yaml pipeline"
}
}
3 changes: 1 addition & 2 deletions extension/src/fileSystem/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ describe('findOrCreateDvcYamlFile', () => {
expect(mockedAppendFileSync).toHaveBeenCalledWith(
`${cwd}/dvc.yaml`,
expect.stringContaining(
`# Read about DVC pipeline configuration (https://dvc.org/doc/user-guide/project-structure/dvcyaml-files#stages)
# to customize your stages even more`
'# Type dvc-help in this file and hit enter to get more information on how the extension can help to setup pipelines'
)
)
})
Expand Down
6 changes: 3 additions & 3 deletions extension/src/fileSystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ export const findOrCreateDvcYamlFile = (
: format(parse(trainingScript))

const pipeline = `
# Read about DVC pipeline configuration (https://dvc.org/doc/user-guide/project-structure/dvcyaml-files#stages)
# to customize your stages even more
# Type dvc-help in this file and hit enter to get more information on how the extension can help to setup pipelines
stages:
${stageName}:
cmd: ${command} ${scriptPath}
deps:
- ${scriptPath}`
- ${scriptPath}
`

void openFileInEditor(dvcYamlPath)
return appendFileSync(dvcYamlPath, pipeline)
Expand Down

0 comments on commit b59033c

Please sign in to comment.