Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ You will be prompted to install the Python dependencies during the first use.
- _**[Python 3.7.4](https://www.python.org/downloads/)**_: Make sure you've added python and pip to your PATH in your environment variables. (1)
- _**[Python VS Code extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)**_: This will be installed automatically from the marketplace when you install Pacifica.

The following dependecies can be installed for you by the extension by clicking yes when you are prompted to. (2)
The following dependecies can be installed for you by the extension by clicking yes when you are prompted to (**except** `pywin32` which is needed only on Windows platform). (2)

- _**Playsound**_
install by typing the following commands in a console: `pip install playsound`

- _**Pywin 32**_
install by typing the following commands in a console: `pip install pywin32`
install by typing the following commands in a console (only for Windows computers, you must run it manually): `pip install pywin32`
- _**Python-Socketio**_
install by typing the following commands in a console: `pip install python-socketio`
- _**Requests**_
Expand Down
14 changes: 7 additions & 7 deletions docs/developers-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@

- Python 3.7.4 (or latest)

- Download link : https://www.python.org/downloads/
- **NOTE :** Make sure Python is in your path under an environment variable named `python` (during installation or insert it manually afterwards)
- **NOTE :** Make sure pip is added to your environment variables as well
(for example it could be found at : `c:\users\<...>\appdata\local\programs\python\python37\lib\site-packages\pip`)
- Run in a console `python -m pip install --upgrade pip`
- Download link : https://www.python.org/downloads/
- **NOTE :** Make sure Python is in your path under an environment variable named `python` or `python3.7` (during installation or insert it manually afterwards)
- **NOTE :** Make sure pip is added to your environment variables as well
(for example it could be found at : `c:\users\<...>\appdata\local\programs\python\python37\lib\site-packages\pip`)
- Run in a console `python -m pip install --upgrade pip`

* Python Modules

- **Note:** On extension activation you will be prompted asking if you want the modules to be automatically installed for you
- **Note:** On extension activation you will be prompted a popup asking if you want the modules to be automatically installed for you, **except** `pywin32` which is needed only on Windows platform.
- Playsound
- Run the command in a console : `pip install playsound`
- pytest
- Run the command in a console : `pip install pytest`
- Pywin32
- **Note:** This is only needed for Windows computers
- **Note:** This is only needed for Windows computers. You must install it manually with the above command!
- Run the command in a console : `pip install pywin32`
- Python-Socketio
- Run the command in a console : `pip install python-socketio`
Expand Down
8 changes: 4 additions & 4 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ _Note: You need to install all the dependencies in order to use the extension._
- [VS Code](https://code.visualstudio.com/Download)
- [Node](https://nodejs.org/en/download/)
- [Python 3.7.4](https://www.python.org/downloads/)
- **Warning :** Make sure you've included `python` and `pip` to your `PATH` in your **environment variables**.
_(Note: the easiest way to do it might be when you install Python, you can select the "Add to PATH" option directly. Otherwise you can search how to insert it manually, but make sure that when you type `python` in a terminal, the command is recognized.)_
- **Warning :** Make sure you've included `python` (or `python3.7`) and `pip` to your `PATH` in your **environment variables**.
_(Note: the easiest way to do it might be when you install Python, you can select the "Add to PATH" option directly. Otherwise you can search how to insert it manually, but make sure that when you type `python` (or `python3.7`) in a terminal, the command is recognized.)_
- [Python VS Code extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
- **Note:** This extension is installed automatically from the marketplace when you install our extension
- Python Modules
- **Note:** On extension activation you will be prompted asking if you want the modules to be automatically installed for you.
- **Note:** On extension activation you will be prompted a popup asking if you want the modules to be automatically installed for you, **except** `pywin32` which is needed only on Windows platform.
- Playsound : `pip install playsound`
- Pywin32 : `pip install pywin32`
- **Note:** This is only needed for Windows computers
- **Note:** This is only needed for Windows computers. You must install it manually with the above command!
- Python-Socketio : `pip install python-socketio`
- Requests : `pip install requests`
- Application Insights: `pip install applicationinsights`
Expand Down
6 changes: 5 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const languages = [{ folderName: "en", id: "en" }];

gulp.task("clean", () => {
return del(
["out/**", "package.nls.*.json", "../../dist/*0.0.0-UNTRACKEDVERSION.vsix"],
[
"out/!(python_libs)",
"package.nls.*.json",
"../../dist/*0.0.0-UNTRACKEDVERSION.vsix"
],
{ force: true }
);
});
Expand Down
6 changes: 5 additions & 1 deletion src/adafruit_circuitplayground/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
telemetry_client = TelemetryClient('__AIKEY__')
EXTENSION_NAME = '__EXTENSIONNAME__'


def show(state, debug_mode=False):
global previous_state
if state != previous_state:
Expand All @@ -30,15 +31,18 @@ def remove_leading_slashes(string):
string = string.lstrip('\\/')
return string


def escape_if_OSX(file_name):
if sys.platform.startswith(CONSTANTS.MAC_OS):
file_name = file_name.replace(" ", "%20")
return file_name


def send_telemetry(event_name):
telemetry_client.track_event(
'{}/{}'.format(EXTENSION_NAME, CONSTANTS.TELEMETRY_EVENT_NAMES[event_name]))
telemetry_client.flush()


def telemetry_available():
return telemetry_client.context.instrumentation_key != '__AIKEY__'
return telemetry_client.context.instrumentation_key != '__AIKEY__'
7 changes: 5 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export const CONSTANTS = {
DEPENDENCY_CHECKER: {
PIP3: "pip3",
PYTHON: "python",
PYTHON3: "python3",
PYTHON_LAUNCHER: "py -3"
PYTHON3: "python3.7",
},
ERROR: {
COMPORT_UNKNOWN_ERROR:
Expand Down Expand Up @@ -148,6 +147,10 @@ export const CONSTANTS = {
"info.incorrectFileNameForSimulatorPopup",
'We want your code to work on your actual board as well. Make sure you name your file "code.py" or "main.py" to be able to run your code on an actual physical device'
),
INSTALLING_PYTHON_DEPENDENCIES: localize(
"info.installingPythonDependencies",
"The Python packages are currently being installed. You will be prompt a message telling you when the installation is done."
),
INSTALL_PYTHON_DEPENDENCIES: localize(
"info.installPythonDependencies",
"Do you want us to try and install this extensions dependencies for you?"
Expand Down
13 changes: 11 additions & 2 deletions src/debug_user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
import traceback
from pathlib import Path
import python_constants as CONSTANTS
from adafruit_circuitplayground.express import cpx
from adafruit_circuitplayground import debugger_communication_client



# Insert absolute path to Adafruit library into sys.path
abs_path_to_parent_dir = os.path.dirname(os.path.abspath(__file__))
abs_path_to_lib = os.path.join(abs_path_to_parent_dir, CONSTANTS.LIBRARY_NAME)
sys.path.insert(0, abs_path_to_lib)

# Insert absolute path to python libraries into sys.path
abs_path_to_parent_dir = os.path.dirname(os.path.abspath(__file__))
abs_path_to_lib = os.path.join(
abs_path_to_parent_dir, CONSTANTS.PYTHON_LIBS_DIR)
sys.path.insert(0, abs_path_to_lib)

# This import must happen after the sys.path is modified
from adafruit_circuitplayground.express import cpx
from adafruit_circuitplayground import debugger_communication_client


## Execute User Code ##

Expand Down
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export async function activate(context: vscode.ExtensionContext) {
// Add our library path to settings.json for autocomplete functionality
updatePythonExtraPaths();

await utils.checkPythonDependencies(context)
pythonExecutableName = await utils.setPythonExectuableName();

await utils.checkPythonDependencies(context, pythonExecutableName)

// Generate cpx.json
try {
Expand All @@ -79,7 +81,6 @@ export async function activate(context: vscode.ExtensionContext) {
configFileCreated = false;
}

pythonExecutableName = await utils.setPythonExectuableName();

if (pythonExecutableName === "") {
return;
Expand Down
22 changes: 1 addition & 21 deletions src/extension_utils/dependencyChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ interface IDependency {
}

const PYTHON3_REGEX = RegExp("^(Python )(3\\.[0-9]+\\.[0-9]+)");
const MINIMUM_PYTHON_VERSION = "3.5.0"
const MINIMUM_PYTHON_VERSION = "3.7.0"

export class DependencyChecker {
constructor() { }

public async checkDependency(dependencyName: string): Promise<IPayloadResponse> {
let state: boolean = false;
if (dependencyName === CONSTANTS.DEPENDENCY_CHECKER.PYTHON) {
const userOS: string = os.platform();
const userOnWin: boolean = userOS.indexOf("win") === 0;

if (
await this.runCommandVersion(CONSTANTS.DEPENDENCY_CHECKER.PYTHON3, MINIMUM_PYTHON_VERSION)
Expand All @@ -37,24 +35,6 @@ export class DependencyChecker {
) {
state = true;
dependencyName = CONSTANTS.DEPENDENCY_CHECKER.PYTHON;
} else if (
userOnWin &&
(await this.runCommandVersion(
CONSTANTS.DEPENDENCY_CHECKER.PYTHON_LAUNCHER,
MINIMUM_PYTHON_VERSION
))
) {
state = true;
dependencyName = CONSTANTS.DEPENDENCY_CHECKER.PYTHON;
} else {
state = false;
}
} else if (dependencyName === CONSTANTS.DEPENDENCY_CHECKER.PIP3) {
if (
await this.runCommandVersion(CONSTANTS.DEPENDENCY_CHECKER.PIP3)
) {
state = true;
dependencyName = CONSTANTS.DEPENDENCY_CHECKER.PYTHON3;
} else {
state = false;
}
Expand Down
22 changes: 13 additions & 9 deletions src/extension_utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import * as fs from "fs";
import * as path from "path";
import * as os from "os";
import { DependencyChecker } from "./dependencyChecker";
import { DeviceContext } from "../deviceContext";
import * as vscode from "vscode";
Expand Down Expand Up @@ -234,11 +235,11 @@ export const checkConfig = (configName: string): boolean => {
return vscode.workspace.getConfiguration().get(configName) === true;
}

export const checkPythonDependencies = async (context: vscode.ExtensionContext) => {
export const checkPythonDependencies = async (context: vscode.ExtensionContext, pythonExecutable: string) => {
let hasInstalledDependencies: boolean = false;
if (checkPipDependency() && checkPythonDependency()) {
if (checkConfig(CONFIG.SHOW_DEPENDENCY_INSTALL)) {
hasInstalledDependencies = await promptInstallPythonDependencies(context);
hasInstalledDependencies = await promptInstallPythonDependencies(context, pythonExecutable);
if (hasInstalledDependencies) {
await vscode.workspace.getConfiguration().update(CONFIG.SHOW_DEPENDENCY_INSTALL, false);
}
Expand All @@ -250,22 +251,22 @@ export const checkPythonDependencies = async (context: vscode.ExtensionContext)
}


export const promptInstallPythonDependencies = (context: vscode.ExtensionContext) => {
export const promptInstallPythonDependencies = (context: vscode.ExtensionContext, pythonExecutable: string) => {
return vscode.window.showInformationMessage(
CONSTANTS.INFO.INSTALL_PYTHON_DEPENDENCIES,
DialogResponses.YES,
DialogResponses.NO)
.then((selection: vscode.MessageItem | undefined) => {
if (selection === DialogResponses.YES) {
return installPythonDependencies(context);
return installPythonDependencies(context, pythonExecutable);
} else if (selection === DialogResponses.NO) {
return vscode.window.showInformationMessage(
CONSTANTS.INFO.ARE_YOU_SURE,
DialogResponses.INSTALL_NOW,
DialogResponses.DONT_INSTALL
).then((installChoice: vscode.MessageItem | undefined) => {
if (installChoice === DialogResponses.INSTALL_NOW) {
return installPythonDependencies(context);
return installPythonDependencies(context, pythonExecutable);
} else {
return false;
}
Expand All @@ -274,16 +275,19 @@ export const promptInstallPythonDependencies = (context: vscode.ExtensionContext
});
}

export const installPythonDependencies = async (context: vscode.ExtensionContext) => {
export const installPythonDependencies = async (context: vscode.ExtensionContext, pythonExecutable: string) => {
let installed: boolean = false;
try {
vscode.window.showInformationMessage(CONSTANTS.INFO.INSTALLING_PYTHON_DEPENDENCIES);
const requirementsPath: string = getPathToScript(context, "out", "requirements.txt");
const { stdout } = await exec(`pip3 install -r ${requirementsPath}`);
const pathToLibs: string = getPathToScript(context, "out", "python_libs");
const { stdout } = await exec(`${pythonExecutable} -m pip install -r ${requirementsPath} -t ${pathToLibs}`);
console.info(stdout);
installed = true;
vscode.window.showInformationMessage(CONSTANTS.INFO.SUCCESSFUL_INSTALL)
vscode.window.showInformationMessage(CONSTANTS.INFO.SUCCESSFUL_INSTALL);
} catch (err) {
console.error(err);
installed = false;
}
return installed
}
}
10 changes: 9 additions & 1 deletion src/process_user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
import traceback
import python_constants as CONSTANTS
from pathlib import Path
from adafruit_circuitplayground.express import cpx

# Insert absolute path to python libraries into sys.path
abs_path_to_parent_dir = os.path.dirname(os.path.abspath(__file__))
abs_path_to_lib = os.path.join(
abs_path_to_parent_dir, CONSTANTS.PYTHON_LIBS_DIR)
sys.path.insert(0, abs_path_to_lib)

read_val = ""
threads = []
Expand All @@ -24,6 +29,9 @@
abs_path_to_parent_dir, CONSTANTS.LIBRARY_NAME)
sys.path.insert(0, abs_path_to_lib)

# This import must happen after the sys.path is modified
from adafruit_circuitplayground.express import cpx


# Handle User Inputs Thread
class UserInput(threading.Thread):
Expand Down
2 changes: 2 additions & 0 deletions src/python_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
NOT_SUPPORTED_OS = 'The OS "{}" not supported.'
NOT_IMPLEMENTED_ERROR = "This method is not implemented by the simulator"

PYTHON_LIBS_DIR = "python_libs"

UTF_FORMAT = "utf-8"

WINDOWS_OS = "win32"
Expand Down
11 changes: 6 additions & 5 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
playsound
pytest
applicationinsights
python-socketio
requests
playsound==1.2.2
pytest==5.0.1
applicationinsights==0.11.9
python-socketio==4.3.1
requests==2.22.0
pywin32==224