Skip to content

Commit

Permalink
0.6.0 Update (#19)
Browse files Browse the repository at this point in the history
* init

* Fix python management bugs
  • Loading branch information
thomashacker authored Apr 7, 2023
1 parent a5f2c66 commit 623b057
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 27 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ We try to follow semantic versioning (semver) if possible:

> Given a version number 1.2.3, 1 is the major number, 2 the minor and 3 the patch number.
## [0.6.0] - 05/04/2023

### Fixed

- Environment Selection Bug

## [0.5.0] - 28/02/2023

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# spaCy VSCode Extension

Version 0.5.0
Version 0.6.0

The spaCy VSCode Extension provides additional tooling and features for working with spaCy's config files. Version 1.0.0 includes hover descriptions for registry functions, variables, and section names within the config as an installable extension.

Expand Down
11 changes: 8 additions & 3 deletions client/src/python_validation.py → client/python_validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from packaging import version
from distutils.version import LooseVersion
import argparse

parser = argparse.ArgumentParser(description="Script to validate python interpreter")
Expand All @@ -10,18 +10,23 @@
try:
import pygls

if version.parse(pygls.__version__) >= version.parse(args.pygls_version):
if LooseVersion(pygls.__version__) >= LooseVersion(args.pygls_version):
try:
import spacy

if version.parse(spacy.__version__) >= version.parse(args.spacy_version):
if LooseVersion(spacy.__version__) >= LooseVersion(args.spacy_version):
sys.stdout.write("I003")
sys.exit()
else:
sys.stdout.write("E009")
sys.exit()
except ModuleNotFoundError as e:
sys.stdout.write("E007")
sys.exit()
else:
sys.stdout.write("E008")
sys.exit()

except ModuleNotFoundError as e:
sys.stdout.write("E006")
sys.exit()
1 change: 1 addition & 0 deletions client/src/client_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const errors = {
E009:
"[E009] Version of spaCy not compatible. Please make sure your spaCy version is >=" +
spacy_version,
E010: "[E010] Python Interpreter not compatible",
};

export const warnings = {
Expand Down
38 changes: 25 additions & 13 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
status,
} from "./client_constants";

const fs = require("fs"); // eslint-disable-line
import * as fs from "fs"; // eslint-disable-line

// Server
let client: LanguageClient;
Expand Down Expand Up @@ -75,7 +75,7 @@ async function startProduction() {
const python_interpreter_compat = await verifyPythonEnvironment(
currentPythonEnvironment
);
if (!python_interpreter_compat.includes("E")) {
if (python_interpreter_compat.includes("I")) {
return startLangServer(
currentPythonEnvironment + "",
["-m", "server"],
Expand All @@ -90,12 +90,12 @@ async function restartClient() {
// Restart the server
if (client) {
await client.stop();
setStatus(false);
setClientActiveStatus(false);
}
client = await startProduction();
if (client) {
await client.start();
setStatus(true);
setClientActiveStatus(true);
}
}

Expand Down Expand Up @@ -123,6 +123,7 @@ async function showServerStatus() {

if (selection == option_select_interpreter) {
// Select python interpreter from file system
logging.info("Selecting from Python Interpreter from Directory");
const uris = await vscode.window.showOpenDialog({
filters: {},
canSelectFiles: false,
Expand All @@ -135,23 +136,27 @@ async function showServerStatus() {
}
} else if (selection == option_current_interpreter) {
// Select current python interpreter
logging.info("Selecting current Python Interpreter");
pythonPath = await vscode.commands.executeCommand(
"python.interpreterPath",
{ workspaceFolder: cwd }
);
}

if (pythonPath) {
logging.info("Python Path retrieved: " + pythonPath);
const pythonSet = await setPythonEnvironment(pythonPath);
if (pythonSet) {
restartClient();
} else {
vscode.window.showWarningMessage(status["S003"]);
}
} else {
logging.info("Python Path could not be retrieved");
}
}

function getAllFiles(dir: string, _files) {
function getAllFiles(dir: string, _files: string[] = []): string[] {
/** Get all files and sub-files from a directory */
const filter = ["bin", "Scripts", "shims"];
_files = _files || [];
Expand All @@ -167,7 +172,7 @@ function getAllFiles(dir: string, _files) {
return _files;
}

function getPythonExec(dir: string) {
function getPythonExec(dir: string): string {
/** Return path of python executable of a list of files */
const files = getAllFiles(dir, []);
for (const i in files) {
Expand All @@ -193,13 +198,16 @@ async function setPythonEnvironment(pythonPath: string) {
if (python_interpreter_compat.includes("E")) {
logging.error(errors[python_interpreter_compat]);
return false;
} else {
} else if (python_interpreter_compat.includes("I")) {
currentPythonEnvironment = pythonPath;
workspace
.getConfiguration("spacy-extension")
.update("pythonInterpreter", currentPythonEnvironment);
logging.info(infos[python_interpreter_compat] + currentPythonEnvironment);
return true;
} else {
logging.error(errors["E010"]);
return false;
}
}

Expand All @@ -212,9 +220,13 @@ async function verifyPythonEnvironment(pythonPath: string): Promise<string> {

return await importPythonCommand(
pythonPath +
" " +
path.join(__dirname, "..", "..") +
"/client/src/python_validation.py " +
` ${path.join(
__dirname,
"..",
"..",
"client",
"python_validation.py"
)} ` +
python_args
);
}
Expand Down Expand Up @@ -249,7 +261,7 @@ function setupStatusBar() {
return statusBar;
}

function setStatus(b: boolean) {
function setClientActiveStatus(b: boolean) {
/**
* Set the status bar color depending whether the client is active or not
* @params b: boolean - Is Client Active?
Expand Down Expand Up @@ -298,12 +310,12 @@ export async function activate(context: ExtensionContext) {

if (client) {
await client.start();
setStatus(true);
setClientActiveStatus(true);
}
}

export function deactivate(): Thenable<void> {
setStatus(false);
setClientActiveStatus(false);
statusBar.hide();
return client ? client.stop() : Promise.resolve();
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@
"name": "spacy-extension",
"displayName": "spaCy Extension",
"description": "spaCy extension that provides additional tooling and features for working with spaCy's config files",
"author": "Explosion AI",
"author": "Explosion",
"repository": "https://github.com/explosion/spacy-vscode",
"license": "MIT",
"version": "0.5.0",
"version": "0.6.0",
"icon": "icon.png",
"galleryBanner": {
"color": "#1e415e",
"theme": "dark"
},
"publisher": "Explosion AI",
"publisher": "Explosion",
"homepage": "explosion.ai",
"keywords": [
"python", "spacy", "prodigy", "explosion", "NLP", "ML"
"python",
"spacy",
"prodigy",
"explosion",
"NLP",
"ML"
],
"engines": {
"vscode": "^1.74.0"
},
"categories": [
"Other", "Machine Learning"
"Other",
"Machine Learning"
],
"extensionDependencies": [
"ms-python.python"
Expand All @@ -29,8 +35,7 @@
"workspaceContains:**/*.cfg"
],
"contributes": {
"commands": [
],
"commands": [],
"configuration": {
"title": "spaCy Server Configuration",
"properties": {
Expand Down Expand Up @@ -61,4 +66,4 @@
"dependencies": {
"vscode-languageclient": "^8.0.2"
}
}
}

0 comments on commit 623b057

Please sign in to comment.