Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/iterative/vscode-dvc into…
Browse files Browse the repository at this point in the history
… update-checkout-action
  • Loading branch information
mattseddon committed Sep 30, 2021
2 parents f75f24b + bf51acc commit d60e25a
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 222 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2020-2021 Iterative, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
16 changes: 0 additions & 16 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@
"category": "DVC",
"icon": "$(trash)"
},
{
"title": "%command.deselectDefaultProject%",
"command": "dvc.deselectDefaultProject",
"category": "DVC"
},
{
"title": "%command.experimentGarbageCollect%",
"command": "dvc.experimentGarbageCollect",
Expand Down Expand Up @@ -237,11 +232,6 @@
"category": "DVC",
"icon": "$(notebook-revert)"
},
{
"title": "%command.selectDefaultProject%",
"command": "dvc.selectDefaultProject",
"category": "DVC"
},
{
"title": "%command.selectForCompare%",
"command": "dvc.selectForCompare",
Expand Down Expand Up @@ -299,12 +289,6 @@
"configuration": {
"title": "DVC",
"properties": {
"dvc.defaultProject": {
"title": "%config.defaultProject.title%",
"description": "%config.defaultProject.description%",
"type": "string",
"default": null
},
"dvc.dvcPath": {
"title": "%config.dvcPath.title%",
"description": "%config.dvcPath.description%",
Expand Down
6 changes: 1 addition & 5 deletions extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"command.copyFilePath": "Copy Path",
"command.copyRelativeFilePath": "Copy Relative Path",
"command.deleteTarget": "Delete",
"command.deselectDefaultProject": "Deselect Default Project",
"command.experimentGarbageCollect": "Garbage Collect Experiments",
"command.findInFolder": "Find in Folder...",
"command.getStarted": "Get Started",
Expand All @@ -32,11 +31,10 @@
"command.removeExperimentsTableSorts": "Remove Sort(s) From Experiments Table",
"command.removeTarget": "Remove",
"command.renameTarget": "Rename",
"command.resetWorkspace": "Reset the Workspace",
"command.runExperiment": "Run Experiment",
"command.runQueuedExperiments": "Run All Queued Experiments",
"command.runResetExperiment": "Run and Reset Experiment",
"command.resetWorkspace": "Reset the Workspace",
"command.selectDefaultProject": "Select Default Project",
"command.selectForCompare": "Select for Compare",
"command.setupWorkspace": "Setup The Workspace",
"command.showCommands": "Show Commands",
Expand All @@ -46,8 +44,6 @@
"command.views.experimentsFilterByTree.removeFilter": "Remove Filter From Experiments Table",
"command.views.experimentsSortByTree.removeAllSorts": "Remove All Sorts From Experiments Table",
"command.views.experimentsSortByTree.removeSort": "Remove Sort From Experiments Table",
"config.defaultProject.description": "When enabled all generic commands will be run against this project.",
"config.defaultProject.title": "DVC Default Project",
"config.dvcPath.description": "Call DVC from this path. Follows Python extension when blank.",
"config.dvcPath.title": "DVC CLI Path",
"config.noOpenUnsupported.description": "Do not attempt to open dvc tracked files that are not supported by the text editor.",
Expand Down
2 changes: 0 additions & 2 deletions extension/src/commands/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export enum RegisteredCommands {
EXPERIMENT_SORTS_REMOVE_ALL = 'dvc.views.experimentsSortByTree.removeAllSorts',
STOP_EXPERIMENT = 'dvc.stopRunningExperiment',

EXTENSION_DESELECT_DEFAULT_PROJECT = 'dvc.deselectDefaultProject',
EXTENSION_GET_STARTED = 'dvc.getStarted',
EXTENSION_SELECT_DEFAULT_PROJECT = 'dvc.selectDefaultProject',
EXTENSION_SETUP_WORKSPACE = 'dvc.setupWorkspace',
EXTENSION_SHOW_COMMANDS = 'dvc.showCommands',

Expand Down
6 changes: 2 additions & 4 deletions extension/src/commands/internal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { ICli } from '../cli'
import { Config } from '../config'
import { OutputChannel } from '../vscode/outputChannel'

const mockedConfig = {
getDefaultProject: jest.fn()
} as unknown as Config
const mockedConfig = {} as Config

const mockedOutputChannel = {
show: jest.fn()
Expand Down Expand Up @@ -33,7 +31,7 @@ describe('InternalCommands', () => {
it('should throw an error if we try to re-register an existing command', () => {
expect(() =>
internalCommands.registerCommand(
AvailableCommands.GET_DEFAULT_OR_PICK_PROJECT,
AvailableCommands.GET_ONLY_OR_PICK_PROJECT,
jest.fn()
)
).toThrow()
Expand Down
10 changes: 5 additions & 5 deletions extension/src/commands/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Command = (...args: Args) => unknown | Promise<unknown>

export const AvailableCommands = Object.assign(
{
GET_DEFAULT_OR_PICK_PROJECT: 'getDefaultOrPickProject',
GET_ONLY_OR_PICK_PROJECT: 'getOnlyOrPickProject',
GET_THEME: 'getTheme'
} as const,
CliExecutorCommands,
Expand All @@ -40,15 +40,15 @@ export class InternalCommands {
this.outputChannel = outputChannel

this.registerCommand(
AvailableCommands.GET_DEFAULT_OR_PICK_PROJECT,
AvailableCommands.GET_ONLY_OR_PICK_PROJECT,
(...dvcRoots: string[]) => {
if (dvcRoots.length === 1) {
return dvcRoots[0]
}

return (
config.getDefaultProject() ||
quickPickOne(dvcRoots, 'Select which project to run command against')
return quickPickOne(
dvcRoots,
'Select which project to run command against'
)
}
)
Expand Down
65 changes: 1 addition & 64 deletions extension/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import {
getOnDidChangePythonExecutionDetails,
getPythonBinPath
} from './extensions/python'
import { QuickPickItemWithValue, quickPickValue } from './vscode/quickPick'
import { getConfigValue, setConfigValue } from './vscode/config'
import { definedAndNonEmpty } from './util/array'
import { getConfigValue } from './vscode/config'

export class Config {
@observable
Expand All @@ -34,14 +32,11 @@ export class Config {

private readonly executionDetailsChanged: EventEmitter<void>

private dvcRoots: string[] = []

private readonly deferred = new Deferred()
private readonly initialized = this.deferred.promise

private dvcPathOption = 'dvc.dvcPath'
private pythonPathOption = 'dvc.pythonPath'
private defaultProjectOption = 'dvc.defaultProject'

constructor() {
makeObservable(this)
Expand All @@ -64,10 +59,6 @@ export class Config {
this.onDidConfigurationChange()
}

public setDvcRoots(dvcRoots: string[]): void {
this.dvcRoots = dvcRoots
}

public isReady() {
return this.initialized
}
Expand All @@ -83,20 +74,6 @@ export class Config {
return getConfigValue(this.dvcPathOption)
}

public getDefaultProject(): string {
return getConfigValue(this.defaultProjectOption)
}

public deselectDefaultProject = (): Thenable<void> =>
this.setDefaultProject(undefined)

public selectDefaultProject = async (): Promise<void> => {
const dvcRoot = await this.pickDefaultProject()
if (dvcRoot) {
this.setDefaultProject(dvcRoot)
}
}

public isPythonExtensionUsed() {
return !getConfigValue(this.pythonPathOption) && !!this.pythonBinPath
}
Expand Down Expand Up @@ -149,44 +126,4 @@ export class Config {
this.executionDetailsChanged.fire()
}
}

private getDefaultProjectOptions(
dvcRoots: string[]
): QuickPickItemWithValue[] {
return [
{
description: 'Choose project each time a command is run',
label: 'Always prompt',
picked: true,
value: 'remove-default'
},
...dvcRoots.map(dvcRoot => ({
description: dvcRoot,
label: 'Project',
value: dvcRoot
}))
]
}

private async pickDefaultProject(): Promise<string | undefined> {
if (definedAndNonEmpty(this.dvcRoots)) {
const selected = await quickPickValue(
this.getDefaultProjectOptions(this.dvcRoots),
{
placeHolder: 'Select a default project to run all commands against'
}
)

if (selected === 'remove-default') {
this.deselectDefaultProject()
return
}

return selected
}
}

private setDefaultProject(path?: string): Thenable<void> {
return setConfigValue(this.defaultProjectOption, path)
}
}
Loading

0 comments on commit d60e25a

Please sign in to comment.