Skip to content

Commit

Permalink
Merge branch 'main' into add-create-env-command
Browse files Browse the repository at this point in the history
  • Loading branch information
julieg18 authored Jun 12, 2023
2 parents 05e5246 + 7dbd5c2 commit 2d1742e
Show file tree
Hide file tree
Showing 38 changed files with 642 additions and 449 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"MNIST",
"nfiles",
"pseudoterminal",
"PYTHONPATH",
"rwlock",
"sonarjs",
"spyable",
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@

All notable changes to this project will be documented in this file.

## [1.0.0] - 2023-06-09

### 🚀 New Features and Enhancements

- Add PYTHONPATH to environment variables if the Python extension makes it available [#4045](https://github.com/iterative/vscode-dvc/pull/4045) by [@mattseddon](https://github.com/mattseddon)

### 🐛 Bug Fixes

- fix(plots): correct the empty screen link to the dvc docs [#4068](https://github.com/iterative/vscode-dvc/pull/4068) by [@shcheklein](https://github.com/shcheklein)

### 🔨 Maintenance

- Fix failing tests [#4070](https://github.com/iterative/vscode-dvc/pull/4070) by [@mattseddon](https://github.com/mattseddon)

## [0.9.6] - 2023-06-08

### 🚀 New Features and Enhancements

- Condense information on storage types for remote onboarding [#4051](https://github.com/iterative/vscode-dvc/pull/4051) by [@mattseddon](https://github.com/mattseddon)

### 🔨 Maintenance

- Remove mention of public beta from the README [#4052](https://github.com/iterative/vscode-dvc/pull/4052) by [@mattseddon](https://github.com/mattseddon)
- Rearrange DVCLive examples in setup screen [#4055](https://github.com/iterative/vscode-dvc/pull/4055) by [@mattseddon](https://github.com/mattseddon)
- Use shields.io for marketplace badges in README [#4063](https://github.com/iterative/vscode-dvc/pull/4063) by [@mattseddon](https://github.com/mattseddon)

## [0.9.5] - 2023-06-07

### 🚀 New Features and Enhancements
Expand Down
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

# DVC Extension for Visual Studio Code

[![Version](https://vsmarketplacebadges.dev/version-short/iterative.dvc.svg)](https://marketplace.visualstudio.com/items?itemName=Iterative.dvc)
[![Installs](https://vsmarketplacebadges.dev/installs/iterative.dvc.svg)](https://marketplace.visualstudio.com/items?itemName=Iterative.dvc)
[![Downloads](https://vsmarketplacebadges.dev/downloads/iterative.dvc.svg)](https://marketplace.visualstudio.com/items?itemName=Iterative.dvc)
[![Ratings](https://vsmarketplacebadges.dev/rating-short/iterative.dvc.svg)](https://marketplace.visualstudio.com/items?itemName=Iterative.dvc)
![Version](https://img.shields.io/visual-studio-marketplace/v/iterative.dvc)
![Installs](https://img.shields.io/visual-studio-marketplace/i/iterative.dvc)
![Downloads](https://img.shields.io/visual-studio-marketplace/d/iterative.dvc)
![Rating](https://img.shields.io/visual-studio-marketplace/r/iterative.dvc)

[![Continuous Integration](https://github.com/iterative/vscode-dvc/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/iterative/vscode-dvc/actions/workflows/continuous-integration.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/fb243c31ea059c0038b2/maintainability)](https://codeclimate.com/repos/608b5886f52398018b00264c/maintainability)
Expand Down Expand Up @@ -34,8 +34,8 @@ databases are required.
- **Data Management**: Handle and version large datasets, files, and models
effectively right from VS Code.

> **Note**: We are in public beta and welcome early adopter feedback!
> Feel free to reach out [via Discord] or open [issues in GitHub].
> **Note**: We always welcome feedback! Feel free to reach out [via Discord] or
> open [issues in GitHub].
>
> [issues in github]: https://github.com/iterative/vscode-dvc/issues
> [via discord]: https://discord.gg/BGCjJHvDHt
Expand Down Expand Up @@ -127,13 +127,12 @@ This extension augments VS Code in the following ways:
Open the Command Palette (`F1` or ⇧⌃P on Windows/Linux or ⇧⌘P on macOS) and type
in one of the following commands:

| Command | Description |
| -------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `DVC: Get Started` | Open the extension's walkthrough. Which details all of the current features and provides links to extra learning resources. |
| `View: Show DVC` | Open the extension's view container. |
| `DVC: Setup The Workspace` | Activate the extension's workspace setup wizard. |
| `DVC: Show Experiments` | Show an interactive version of DVC's `exp show` [command](https://dvc.org/doc/command-reference/exp/show). |
| `DVC: Show Plots` | Show an interactive version of DVC's `plots diff` [command](https://dvc.org/doc/command-reference/plots/diff). |
| Command | Description |
| ----------------------- | -------------------------------------------------------------------------------------------------------------- |
| `DVC: Show Setup` | Show the extension's setup page. Which can be used to setup the DVC project, view the walkthrough and more. |
| `View: Show DVC` | Open the extension's view container. |
| `DVC: Show Experiments` | Show an interactive version of DVC's `exp show` [command](https://dvc.org/doc/command-reference/exp/show). |
| `DVC: Show Plots` | Show an interactive version of DVC's `plots diff` [command](https://dvc.org/doc/command-reference/plots/diff). |

Learn more about the extension's [commands].

Expand All @@ -160,13 +159,22 @@ These are the VS Code [settings] available for the Extension:
> **Note** that the `Setup The Workspace` command helps you set up the basic
> ones at the [Workspace level] (saved to `.vscode/setting.json`).
### Python

This extension is integrated with Microsoft's [Python extension]. When possible,
the Python extension's selected interpreter will be used to locate DVC. The
`PYTHONPATH` environment variable identified via the [python.envFile] config
setting is also respected.

[python extension]:
https://marketplace.visualstudio.com/items?itemName=ms-python.python
[studio.token]:
https://dvc.org/doc/user-guide/project-structure/configuration#studio
[Studio]: https://studio.iterative.ai
[workspace level]:
https://code.visualstudio.com/docs/getstarted/settings#_workspace-settings
[python.envFile]:
https://code.visualstudio.com/docs/python/environments#_use-of-the-pythonpath-variable

## Debugging

Expand Down
20 changes: 10 additions & 10 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"extensionDependencies": [
"vscode.git"
],
"version": "0.9.5",
"version": "1.0.0",
"license": "Apache-2.0",
"readme": "./README.md",
"repository": {
Expand Down Expand Up @@ -1651,13 +1651,13 @@
"vscode-languageclient": "8.1.0"
},
"devDependencies": {
"@swc/core": "1.3.61",
"@swc/core": "1.3.62",
"@swc/jest": "0.2.26",
"@types/chai": "4.3.5",
"@types/chai-as-promised": "7.1.5",
"@types/copy-webpack-plugin": "10.1.0",
"@types/fs-extra": "11.0.1",
"@types/jest": "29.5.1",
"@types/jest": "29.5.2",
"@types/js-yaml": "4.0.5",
"@types/lodash.clonedeep": "4.5.7",
"@types/lodash.get": "4.4.7",
Expand All @@ -1675,10 +1675,10 @@
"@types/vscode": "1.64.0",
"@vscode/test-electron": "2.3.2",
"@vscode/vsce": "2.19.0",
"@wdio/cli": "8.10.5",
"@wdio/local-runner": "8.10.5",
"@wdio/mocha-framework": "8.10.4",
"@wdio/spec-reporter": "8.10.5",
"@wdio/cli": "8.10.7",
"@wdio/local-runner": "8.10.7",
"@wdio/mocha-framework": "8.10.7",
"@wdio/spec-reporter": "8.10.6",
"chai": "4.3.7",
"chai-as-promised": "7.1.1",
"clean-webpack-plugin": "4.0.0",
Expand All @@ -1695,9 +1695,9 @@
"ts-loader": "9.4.3",
"vscode-uri": "3.0.7",
"wdio-vscode-service": "5.1.0",
"webdriverio": "8.10.5",
"webpack": "5.84.1",
"webpack-cli": "5.1.1"
"webdriverio": "8.10.7",
"webpack": "5.85.0",
"webpack-cli": "5.1.3"
},
"peerDependencies": {
"typescript": "*"
Expand Down
1 change: 1 addition & 0 deletions extension/src/cli/dvc/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('DvcConfig', () => {
const dvcConfig = new DvcConfig(
{
getCliPath: () => undefined,
getPYTHONPATH: () => undefined,
getPythonBinPath: () => undefined
} as unknown as Config,
{
Expand Down
1 change: 1 addition & 0 deletions extension/src/cli/dvc/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('CliExecutor', () => {
const dvcExecutor = new DvcExecutor(
{
getCliPath: () => undefined,
getPYTHONPATH: () => undefined,
getPythonBinPath: () => undefined
} as unknown as Config,
{
Expand Down
2 changes: 2 additions & 0 deletions extension/src/cli/dvc/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('executeDvcProcess', () => {
const cli = new DvcCli(
{
getCliPath: () => undefined,
getPYTHONPATH: () => undefined,
getPythonBinPath: () => undefined
} as unknown as Config,
{
Expand Down Expand Up @@ -111,6 +112,7 @@ describe('executeDvcProcess', () => {
const cli = new DvcCli(
{
getCliPath: () => '/some/path/to/dvc',
getPYTHONPATH: () => undefined,
getPythonBinPath: () => pythonBinPath
} as unknown as Config,
{
Expand Down
11 changes: 6 additions & 5 deletions extension/src/cli/dvc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export class DvcCli extends Cli {
}

protected getOptions(cwd: string, ...args: Args) {
return getOptions(
this.extensionConfig.getPythonBinPath(),
this.extensionConfig.getCliPath(),
return getOptions({
PYTHONPATH: this.extensionConfig.getPYTHONPATH(),
args: [...args],
cliPath: this.extensionConfig.getCliPath(),
cwd,
...args
)
pythonBinPath: this.extensionConfig.getPythonBinPath()
})
}
}
50 changes: 47 additions & 3 deletions extension/src/cli/dvc/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ describe('getOptions', () => {
const cwd = join('path', 'to', 'work', 'dir')

it('should give the correct options given a basic environment', () => {
const options = getOptions(undefined, '', cwd, Command.CHECKOUT, Flag.FORCE)
const options = getOptions({
PYTHONPATH: undefined,
args: [Command.CHECKOUT, Flag.FORCE],
cliPath: '',
cwd,
pythonBinPath: undefined
})
expect(options).toStrictEqual({
args: ['checkout', '-f'],
cwd,
Expand All @@ -36,7 +42,13 @@ describe('getOptions', () => {

it('should append -m dvc to the args and use the python as the executable if only an isolated python env is in use', () => {
const pythonBinPath = join('path', 'to', 'python', '.venv', 'python')
const options = getOptions(pythonBinPath, '', cwd, Command.PULL)
const options = getOptions({
PYTHONPATH: undefined,
args: [Command.PULL],
cliPath: '',
cwd,
pythonBinPath
})
expect(options).toStrictEqual({
args: ['-m', 'dvc', 'pull'],
cwd,
Expand All @@ -53,7 +65,13 @@ describe('getOptions', () => {
it('should append to the PATH but only use the path to the cli if both an isolated python env and path to dvc are in use', () => {
const pythonBinPath = join('path', 'to', 'python', '.venv', 'python')
const cliPath = join('custom', 'path', 'to', 'dvc')
const options = getOptions(pythonBinPath, cliPath, cwd, Command.PULL)
const options = getOptions({
PYTHONPATH: undefined,
args: [Command.PULL],
cliPath,
cwd,
pythonBinPath
})
expect(options).toStrictEqual({
args: ['pull'],
cwd,
Expand All @@ -66,4 +84,30 @@ describe('getOptions', () => {
executable: cliPath
})
})

it('should add PYTHONPATH to the environment variables if it is provided', () => {
const PYTHONPATH = join('path', 'to', 'project')
const venvPath = join(PYTHONPATH, '.venv')
const pythonBinPath = join(venvPath, 'python')
const cliPath = ''
const options = getOptions({
PYTHONPATH,
args: [Command.PULL],
cliPath,
cwd,
pythonBinPath
})
expect(options).toStrictEqual({
args: ['-m', 'dvc', 'pull'],
cwd,
env: {
DVCLIVE_OPEN: 'false',
DVC_NO_ANALYTICS: 'true',
GIT_TERMINAL_PROMPT: '0',
PATH: joinEnvPath(venvPath, mockedPATH),
PYTHONPATH
},
executable: pythonBinPath
})
})
})
41 changes: 27 additions & 14 deletions extension/src/cli/dvc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@ const getPATH = (existingPath: string, pythonBinPath?: string): string => {
return joinEnvPath(python, existingPath)
}

const getEnv = (pythonBinPath?: string): NodeJS.ProcessEnv => {
const env = getProcessEnv()
const PATH = getPATH(env?.PATH as string, pythonBinPath)
return {
...env,
const getEnv = (
pythonBinPath: string | undefined,
PYTHONPATH: string | undefined
): NodeJS.ProcessEnv => {
const existingEnv = getProcessEnv()
const PATH = getPATH(existingEnv?.PATH as string, pythonBinPath)
const env: NodeJS.ProcessEnv = {
...existingEnv,
DVCLIVE_OPEN: 'false',
DVC_NO_ANALYTICS: 'true',
GIT_TERMINAL_PROMPT: '0',
PATH
}
if (PYTHONPATH) {
env.PYTHONPATH = PYTHONPATH
}
return env
}

const getArgs = (
Expand All @@ -35,18 +42,24 @@ const getArgs = (
const getExecutable = (pythonBinPath: string | undefined, cliPath: string) =>
cliPath || pythonBinPath || 'dvc'

export const getOptions = (
pythonBinPath: string | undefined,
cliPath: string,
cwd: string,
...originalArgs: Args
): ExecutionOptions => {
export const getOptions = ({
args = [],
cliPath,
cwd,
pythonBinPath,
PYTHONPATH
}: {
args?: Args
cliPath: string
cwd: string
pythonBinPath: string | undefined
PYTHONPATH: string | undefined
}): ExecutionOptions => {
const executable = getExecutable(pythonBinPath, cliPath)
const args = getArgs(pythonBinPath, cliPath, ...originalArgs)
return {
args,
args: getArgs(pythonBinPath, cliPath, ...args),
cwd: getCaseSensitiveCwd(cwd),
env: getEnv(pythonBinPath),
env: getEnv(pythonBinPath, PYTHONPATH),
executable
}
}
19 changes: 19 additions & 0 deletions extension/src/cli/dvc/reader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import expShowFixture from '../../test/fixtures/expShow/base/output'
import plotsDiffFixture from '../../test/fixtures/plotsDiff/output/minimal'
import { Config } from '../../config'
import { joinEnvPath } from '../../util/env'
import { dvcDemoPath } from '../../test/util'

jest.mock('vscode')
jest.mock('@hediet/std/disposable')
Expand All @@ -34,6 +35,7 @@ const mockedEnv = {
const JSON_FLAG = '--json'

const mockedGetPythonBinPath = jest.fn()
const mockedGetPYTHONPATH = jest.fn()

beforeEach(() => {
jest.resetAllMocks()
Expand All @@ -53,6 +55,7 @@ describe('CliReader', () => {
const dvcReader = new DvcReader(
{
getCliPath: () => undefined,
getPYTHONPATH: mockedGetPYTHONPATH,
getPythonBinPath: mockedGetPythonBinPath
} as unknown as Config,
{
Expand Down Expand Up @@ -311,5 +314,21 @@ describe('CliReader', () => {

await expect(dvcReader.version(cwd)).rejects.toBeTruthy()
})

it('should add PYTHONPATH to the environment used to create a DVC process when it is available from the extension config', async () => {
mockedGetPYTHONPATH.mockReturnValue(dvcDemoPath)
const cwd = __dirname
const stdout = '3.9.11'
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))
const output = await dvcReader.version(cwd)

expect(output).toStrictEqual(stdout)
expect(mockedCreateProcess).toHaveBeenCalledWith({
args: ['--version'],
cwd,
env: { ...mockedEnv, PYTHONPATH: dvcDemoPath },
executable: 'dvc'
})
})
})
})
Loading

0 comments on commit 2d1742e

Please sign in to comment.