Skip to content
This repository has been archived by the owner on Jan 26, 2020. It is now read-only.

Commit

Permalink
added possibility to change virtual env directory
Browse files Browse the repository at this point in the history
  • Loading branch information
p- committed Mar 7, 2018
1 parent d33ace1 commit 33d2213
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Change Log
All notable changes to the "vscode-vyper" extension will be documented in this file.

## [Unreleased]
## 0.0.2
- The virtual env path can now be changed
- The Vyper contract can now be in a subdirectory

## 0.0.1
- Initial release
- Vyper: Build Contract command that build a give contract and displays syntax errors
- Syntax Higlighting for Vyper (*.vy, *.v.py) files
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ This means that the folder `~/vyper-venv/bin` should contain a `python` and a `v

## Extension Settings

Coming eventually...
The path to the virtual Python environment can be set in the User Settings (`Ctrl+Shift+P`) + 'Open User Settings' via the `vyper.virtualEnvPath` variable.

## Known Issues

Requires a virtual Vyper env to be set up exactly as described in the [Vyper tutorial](https://vyper.readthedocs.io/en/latest/installing-vyper.html).
This means that the folder `~/vyper-venv/bin` should contain a `python` and a `vyper` executable.
![VS Code User Settings](vscode-vyper-settings.png)

## Installation

Expand Down
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-vyper",
"displayName": "Vyper",
"description": "Vyper (Ethereum) support for VS Code",
"version": "0.0.1",
"version": "0.0.2",
"publisher": "p-",
"keywords": [
"vyper",
Expand Down Expand Up @@ -51,7 +51,22 @@
"scopeName": "source.vyper",
"path": "./syntax/MagicPython.tmLanguage.json"
}
]
],
"configuration": {
"type": "object",
"title": "Vyper configuration",
"properties": {
"vyper.virtualEnvPath": {
"type": [
"string",
"null"
],
"default": null,
"description": "Specifies the Virtual Python Environment to use.",
"scope": "resource"
}
}
}
},
"scripts": {
"vscode:prepublish": "npm run compile",
Expand Down
27 changes: 14 additions & 13 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,26 @@ function mapSeverityToVSCodeSeverity(sev: string): vscode.DiagnosticSeverity {
}
}

export function getWorkspaceFolderPath(fileUri: vscode.Uri): string {
if (fileUri) {
let workspace = vscode.workspace.getWorkspaceFolder(fileUri);
if (workspace) {
return workspace.uri.fsPath;
}
}
export function getVyperVirtualEnv(): string {
const vyperConfig = vscode.workspace.getConfiguration('vyper', vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document.uri : null);

// fall back to the first workspace
let folders = vscode.workspace.workspaceFolders;
if (folders && folders.length) {
return folders[0].uri.fsPath;
if (vyperConfig['virtualEnvPath'] !== null) {
return resolveHomeDir(vyperConfig['virtualEnvPath']);
}
return os.homedir() + '/vyper-venv';
}

export function getVyperDefaultVirtualEnv(): string {
return os.homedir() + '/vyper-venv';
/**
* Expands ~ to homedir in non-Windows platform
*/
export function resolveHomeDir(inputPath: string): string {
if (!inputPath || !inputPath.trim()) {
return inputPath;
}
return inputPath.startsWith('~') ? path.join(os.homedir(), inputPath.substr(1)) : inputPath;
}


export function killTree(processId: number): void {
if (process.platform === 'win32') {
const TASK_KILL = 'C:\\Windows\\System32\\taskkill.exe';
Expand Down
9 changes: 4 additions & 5 deletions src/vyperBuild.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path = require('path');
import vscode = require('vscode');
import { runTool, ICheckResult, handleDiagnosticErrors, getWorkspaceFolderPath, getVyperDefaultVirtualEnv } from './util';
import { runTool, ICheckResult, handleDiagnosticErrors, getVyperVirtualEnv } from './util';
import { outputChannel } from './vyperStatus';
import { diagnosticsStatusBarItem } from './vyperStatus';

Expand Down Expand Up @@ -45,17 +45,16 @@ export function vyperBuild(fileUri: vscode.Uri, vyperConfig: vscode.WorkspaceCon
}

// Calls Vyper with virtual env: /Users/sectests/vyper-venv/bin/python /usr/local/bin/vyper (which vyper?)
const currentWorkspace = getWorkspaceFolderPath(fileUri);
const cwd = currentWorkspace ? currentWorkspace : path.dirname(fileUri.fsPath);
const cwd = path.dirname(fileUri.fsPath);
if (!path.isAbsolute(cwd)) {
return Promise.resolve([]);
}

running = true;

//TODO get Env and Vyper Exec from config if configured
const pythonFromVirtualEnv = getVyperDefaultVirtualEnv() + '/bin/python';
const vyperExec = getVyperDefaultVirtualEnv() + '/bin/vyper';
const pythonFromVirtualEnv = getVyperVirtualEnv() + '/bin/python';
const vyperExec = getVyperVirtualEnv() + '/bin/vyper';

const index = fileUri.path.lastIndexOf("/") + 1;
const fileName = fileUri.path.substr(index);
Expand Down
Binary file added vscode-vyper-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 33d2213

Please sign in to comment.