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
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ out/
!locales/**/out/
package.nls.*.json

# virtual environment
venv/

# testing
.vscode-test

Expand Down
36 changes: 19 additions & 17 deletions locales/en/package.i18n.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"deviceSimulatorExpressExtension.commands.common.installDependencies": "Install Extension Dependencies",
"deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express",
"deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator",
"deviceSimulatorExpressExtension.commands.cpx.changeBaudRate": "[Circuit Playground Express] Change Baud Rate",
"deviceSimulatorExpressExtension.commands.cpx.closeSerialMonitor": "[Circuit Playground Express] Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.cpx.openSerialMonitor": "[Circuit Playground Express] Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.selectSerialPort": "[Circuit Playground Express] Select Serial Port",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger.",
"deviceSimulatorExpressExtension.configuration.properties.previewMode": "Enable this to test out and play with the new micro:bit simulator!"
}
{
"deviceSimulatorExpressExtension.commands.common.installDependencies": "Install Extension Dependencies",
"deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express",
"deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator",
"deviceSimulatorExpressExtension.commands.cpx.changeBaudRate": "[Circuit Playground Express] Change Baud Rate",
"deviceSimulatorExpressExtension.commands.cpx.closeSerialMonitor": "[Circuit Playground Express] Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.cpx.openSerialMonitor": "[Circuit Playground Express] Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.selectSerialPort": "[Circuit Playground Express] Select Serial Port",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
"deviceSimulatorExpressExtension.configuration.properties.configEnvOnChange": "When you change the Python interpreter, the Device Simulator Express will automatically configure itself for the required dependencies.",
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger.",
"deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask if we can download dependencies. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files."
"deviceSimulatorExpressExtension.configuration.properties.previewMode": "Enable this to test out and play with the new micro:bit simulator!"
}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,20 @@
"type": "object",
"title": "%deviceSimulatorExpressExtension.configuration.title%",
"properties": {
"deviceSimulatorExpress.configNewEnvironmentUponSwitch": {
"type": "boolean",
"default": false,
"description": "%deviceSimulatorExpressExtension.configuration.properties.configEnvOnChange%",
"scope": "resource"
},
"deviceSimulatorExpress.enableUSBDetection": {
"type": "boolean",
"default": true
},
"deviceSimulatorExpress.showDependencyInstall": {
"type": "boolean",
"default": true,
"description": "%deviceSimulatorExpressExtension.configuration.properties.dependencyChecker%",
"scope": "resource"
},
"deviceSimulatorExpress.showNewFilePopup": {
Expand Down Expand Up @@ -344,4 +351,4 @@
"extensionDependencies": [
"ms-python.python"
]
}
}
35 changes: 18 additions & 17 deletions package.nls.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"deviceSimulatorExpressExtension.commands.common.installDependencies": "Install Extension Dependencies",
"deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express",
"deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator",
"deviceSimulatorExpressExtension.commands.cpx.changeBaudRate": "[Circuit Playground Express] Change Baud Rate",
"deviceSimulatorExpressExtension.commands.cpx.closeSerialMonitor": "[Circuit Playground Express] Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.cpx.openSerialMonitor": "[Circuit Playground Express] Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.selectSerialPort": "[Circuit Playground Express] Select Serial Port",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger.",
"deviceSimulatorExpressExtension.configuration.properties.previewMode": "Enable this to test out and play with the new micro:bit simulator!"
}
{
"deviceSimulatorExpressExtension.commands.common.installDependencies": "Install Extension Dependencies",
"deviceSimulatorExpressExtension.commands.common.label": "Device Simulator Express",
"deviceSimulatorExpressExtension.commands.common.runSimulator": "Run Simulator",
"deviceSimulatorExpressExtension.commands.cpx.changeBaudRate": "[Circuit Playground Express] Change Baud Rate",
"deviceSimulatorExpressExtension.commands.cpx.closeSerialMonitor": "[Circuit Playground Express] Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.cpx.openSerialMonitor": "[Circuit Playground Express] Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.selectSerialPort": "[Circuit Playground Express] Select Serial Port",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
"deviceSimulatorExpressExtension.configuration.properties.configEnvOnChange": "When you change the Python interpreter, the Device Simulator Express will automatically configure itself for the required dependencies.",
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger.",
"deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask for dependency downloads. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files."
"deviceSimulatorExpressExtension.configuration.properties.previewMode": "Enable this to test out and play with the new micro:bit simulator!"
11 changes: 11 additions & 0 deletions src/check_if_venv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# from https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv
import sys

isVenv = hasattr(sys, "real_prefix") or (
hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix
)

# prints result for frontend to read
# 1 -> is a venv
# 0 -> is NOT a venv
print(int(isVenv))
10 changes: 10 additions & 0 deletions src/check_python_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# from https://stackoverflow.com/questions/16294819/check-if-my-python-has-all-required-packages
import sys
import pkg_resources

with open(f"{sys.path[0]}/requirements.txt") as f:
dependencies = [x.strip() for x in f.readlines()]

# here, if a dependency is not met, a DistributionNotFound or VersionConflict
# exception is thrown.
pkg_resources.require(dependencies)
78 changes: 63 additions & 15 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ const localize: nls.LocalizeFunc = nls.config({
})();

export const CONFIG = {
CONFIG_ENV_ON_SWITCH:
"deviceSimulatorExpress.configNewEnvironmentUponSwitch",
PYTHON_PATH: "python.pythonPath",
ENABLE_PREVIEW_MODE: "deviceSimulatorExpress.previewMode",
SHOW_DEPENDENCY_INSTALL: "deviceSimulatorExpress.showDependencyInstall",
SHOW_NEW_FILE_POPUP: "deviceSimulatorExpress.showNewFilePopup",
};

export const CONSTANTS = {
DEBUG_CONFIGURATION_TYPE: "deviceSimulatorExpress",
DEPENDENCY_CHECKER: {
PIP3: "pip3",
PYTHON: "python",
PYTHON3: "python3.7",
},
DEVICE_NAME: {
CPX: "CPX",
MICROBIT: "micro:bit",
},
ERROR: {
BAD_PYTHON_PATH:
'Your interpreter is not pointing to a valid Python executable. Please select a different interpreter (CTRL+SHIFT+P and type "python.selectInterpreter") and restart the application',
COMPORT_UNKNOWN_ERROR:
"Writing to COM port (GetOverlappedResult): Unknown error code 121",
CPX_FILE_ERROR: localize(
Expand All @@ -51,7 +51,8 @@ export const CONSTANTS = {
"[ERROR] A debugging session is currently in progress, please stop it before running your code. \n"
),
DEPENDENCY_DOWNLOAD_ERROR:
"Package downloads failed. Some functionalities may not work. Try restarting the simulator or review the installation docs.",
"Dependency download could not be completed. Functionality may be limited. Please review the installation docs.",

FAILED_TO_OPEN_SERIAL_PORT: (port: string): string => {
return localize(
"error.failedToOpenSerialPort",
Expand Down Expand Up @@ -80,6 +81,10 @@ export const CONSTANTS = {
"error.invalidFileExtensionDebug",
"The file you tried to run isn't a Python file."
),
INVALID_PYTHON_PATH: localize(
"error.invalidPythonPath",
'We found that your selected Python interpreter version is too low to run the extension. Please upgrade to version 3.7+ or select a different interpreter (CTRL+SHIFT+P and type "python.selectInterpreter") and restart the application.'
),
NO_DEVICE: localize(
"error.noDevice",
"No plugged in boards detected. Please double check if your board is connected and/or properly formatted"
Expand All @@ -96,6 +101,10 @@ export const CONSTANTS = {
"error.noProgramFoundDebug",
"Cannot find a program to debug."
),
NO_PIP: localize(
"error.noPip",
"We found that you don't have Pip installed on your computer, please install it and try again."
),
NO_PYTHON_PATH: localize(
"error.noPythonPath",
"We found that you don't have Python 3 installed on your computer, please install the latest version, add it to your PATH and try again."
Expand All @@ -114,9 +123,13 @@ export const CONSTANTS = {
},
FILESYSTEM: {
OUTPUT_DIRECTORY: "out",
PYTHON_LIBS_DIR: "python_libs",
PYTHON_VENV_DIR: "venv",
},
INFO: {
ALREADY_SUCCESSFUL_INSTALL: localize(
"info.successfulInstall",
"Your current configuration is already successfully set up for the Device Simulator Expresss."
),
ARE_YOU_SURE: localize(
"info.areYouSure",
"Are you sure you don't want to install the dependencies? The extension can't run without installing them."
Expand Down Expand Up @@ -162,13 +175,17 @@ 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."
INSTALLING_PYTHON_VENV: localize(
"info.installingPythonVenv",
"A virtual environment is currently being created. The required Python packages will be installed. You will be prompted a message telling you when the installation is done."
),
INSTALL_PYTHON_DEPENDENCIES: localize(
INSTALL_PYTHON_DEPS: localize(
"info.installPythonDependencies",
"Do you want us to try and install this extensions dependencies for you?"
"Do you want us to try and install this extension's dependencies on your selected Python interpreter for you?"
),
INSTALL_PYTHON_VENV: localize(
"info.installPythonVenv",
"Do you want us to try and install this extension's dependencies via virtual environment for you?"
),
INVALID_FILE_NAME_DEBUG: localize(
"info.invalidFileNameDebug",
Expand Down Expand Up @@ -198,12 +215,24 @@ export const CONSTANTS = {
RUNNING_CODE: localize("info.runningCode", "Running user code"),
SUCCESSFUL_INSTALL: localize(
"info.successfulInstall",
"Successfully installed Python dependencies."
"Successfully set up the Python environment."
),
THIRD_PARTY_WEBSITE: localize(
"info.thirdPartyWebsite",
THIRD_PARTY_WEBSITE_ADAFRUIT: localize(
"info.thirdPartyWebsiteAdafruit",
'By clicking "Agree and Proceed" you will be redirected to adafruit.com, a third party website not managed by Microsoft. Please note that your activity on adafruit.com is subject to Adafruit\'s privacy policy'
),
THIRD_PARTY_WEBSITE_PIP: localize(
"info.thirdPartyWebsitePip",
'By clicking "Agree and Proceed" you will be redirected to pip.pypa.io, a third party website not managed by Microsoft. Please note that your activity on pip.pypa.io is subject to PyPA\'s privacy policy'
),
THIRD_PARTY_WEBSITE_PYTHON: localize(
"info.thirdPartyWebsitePython",
'By clicking "Agree and Proceed" you will be redirected to python.org, a third party website not managed by Microsoft. Please note that your activity on python.org is subject to Python\'s privacy policy'
),
UPDATED_TO_EXTENSION_VENV: localize(
"info.updatedToExtensionsVenv",
"Automatically updated interpreter to point to extension's virtual environment."
),
WELCOME_OUTPUT_TAB: localize(
"info.welcomeOutputTab",
"Welcome to the Device Simulator Express output tab!\n\n"
Expand All @@ -216,6 +245,7 @@ export const CONSTANTS = {
),
},
LINKS: {
DOWNLOAD_PIP: "https://pip.pypa.io/en/stable/installing/",
DOWNLOAD_PYTHON: "https://www.python.org/downloads/",
EXAMPLE_CODE:
"https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples",
Expand Down Expand Up @@ -395,6 +425,12 @@ export namespace DialogResponses {
export const MESSAGE_UNDERSTOOD: MessageItem = {
title: localize("dialogResponses.messageUnderstood", "Got It"),
};
export const INSTALL_PIP: MessageItem = {
title: localize(
"dialogResponses.installPip",
"Install from Pip's webpage"
),
};
export const INSTALL_PYTHON: MessageItem = {
title: localize(
"dialogResponses.installPython",
Expand Down Expand Up @@ -425,4 +461,16 @@ export const STATUS_BAR_PRIORITY = {
BAUD_RATE: 40,
};

export const VERSIONS = {
MIN_PY_VERSION: "3.7.0",
};

export const HELPER_FILES = {
CHECK_IF_VENV_PY: "check_if_venv.py",
CHECK_PYTHON_DEPENDENCIES: "check_python_dependencies.py",
DEVICE_PY: "device.py",
PROCESS_USER_CODE_PY: "process_user_code.py",
PYTHON_EXE: "python.exe",
};

export default CONSTANTS;
1 change: 0 additions & 1 deletion src/debug_user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# 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
Expand Down
Loading