Skip to content

Commit

Permalink
Replaced Pico-W-Stub with micropython-stubs
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Oct 18, 2023
1 parent 9a222c5 commit 8573ec1
Show file tree
Hide file tree
Showing 98 changed files with 105 additions and 12,466 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
paths-ignore:
- ".idea/**"
- ".vscode/**"
- "scripts/**"
- "**/*.md"
- ".prettierrc.json"
- "LICENSE"
Expand All @@ -24,17 +25,22 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup node
- name: Setup Node v18.15.x
uses: actions/setup-node@v3
with:
node-version: "18.15.x"
registry-url: "https://npm.pkg.github.com"
scope: "@paulober"
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Python v3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Dependencies
- name: Install NPM Dependencies And Download Stubs
shell: bash
run: |
sed -i '1i//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}' .npmrc
Expand All @@ -43,4 +49,4 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Package Extension
run: npx @vscode/vsce package --no-yarn -o pico-w-go-${{ github.sha }}.vsix
run: npx @vscode/vsce package --no-yarn -o micropico-${{ github.sha }}.vsix
21 changes: 14 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ jobs:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4

- name: Setup Node v18.15.x
uses: actions/setup-node@v3
with:
node-version: '18.15.x'
registry-url: "https://npm.pkg.github.com"
scope: "@paulober"
token: ${{ secrets.GITHUB_TOKEN }}

- name: NPM install
- name: Setup Python v3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install NPM dependencies And Download Stubs
shell: bash
run: |
sed -i '1i//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}' .npmrc
Expand All @@ -35,18 +42,18 @@ jobs:
- name: Package
run: npx @vscode/vsce package --no-yarn

- run: npx @vscode/vsce publish --no-yarn --target win32-x64 linux-x64 linux-arm64 darwin-x64 darwin-arm64
name: Publish
- name: Publish
run: npx @vscode/vsce publish --no-yarn --target win32-x64 linux-x64 linux-arm64 darwin-x64 darwin-arm64
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}

- name: Upload artifact
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: Visual Studio Code extension package
path: pico-w-go-*.vsix

- name: Upload artifact to release
- name: Upload Artifact To Release
#gh api --method POST -H "Accept: application/vnd.github+json" /repos/paulober/Pico-W-Go/releases/$RELEASE_ID/assets
run: gh release upload $RELEASE_TAG_NAME pico-w-go-*.vsix
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,4 @@ fabric.properties
# End of https://www.toptal.com/developers/gitignore/api/node,python,webstorm,visualstudiocode,macos

*.zip
mpy_stubs/
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ azure-pipelines.yml
!dist/*.cjs
!dist/scripts/*.py
dist/scripts/__pycache__
!mpy_stubs/
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

"MicroPico" is a Visual Studio Code extension designed to simplify and accelerate the development of MicroPython projects for the Raspberry Pi Pico and Pico W boards. This tool streamlines the coding process, providing code highlighting, auto-completion, code snippets, and project management features, all tailored for the seamless development experience with MicroPython on Raspberry Pi Pico and Pico W microcontrollers.

> __Auto-completion based on Raspberry Pi Pico W MicroPython firmware: [RPI_PICO_W-20231005-v1.21.0.uf2](https://micropython.org/resources/firmware/RPI_PICO_W-20231005-v1.21.0.uf2)__
> __Auto-completion based on Raspberry Pi Pico W MicroPython firmware: [RPI_PICO_W-20230426-v1.20.0.uf2](https://micropython.org/resources/firmware/RPI_PICO_W-20230426-v1.20.0.uf2) from the [micropython-stubs project](https://github.com/Josverl/micropython-stubs)__
> NOTE: Support for MPY v1.21.0 will be added in the next few days.
Works with:
| Platform | x64 | arm64 |
Expand All @@ -13,7 +14,7 @@ Works with:

## Features

- Auto-completion and docs
- Auto-completion with docs
- Pseudo terminal integration for communication with MicroPython REPL on a Pico (w) board (with support for tab-completion)
- Running / Transferring files to / from your board
- Built-in virtual-workspace provider for Raspberry Pi Pico (W) boards
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@
"scripts": {
"vscode:uninstall": "node ./dist/vscodeUninstall.mjs",
"vscode:prepublish": "npm run package",
"postinstall": "python3 -m pip install -U micropython-rp2-pico_w-stubs --target ./mpy_stubs --no-user",
"compile-uninstaller": "rollup -c uninstall.rollup.config.mjs",
"compile": "rollup -c && npm run compile-uninstaller",
"watch": "rollup -cw",
Expand Down
99 changes: 74 additions & 25 deletions src/stubs.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
recommendedExtensions,
shouldRecommendExtensions,
} from "./api.mjs";
import { mkdir, readFile, symlink } from "fs/promises";
import { mkdir, readdir, symlink } from "fs/promises";
import { pathExists, readJsonFile, writeJsonFile } from "./osHelper.mjs";
import { copy, emptyDir } from "fs-extra";
import Logger from "./logger.mjs";
Expand All @@ -19,37 +19,76 @@ export default class Stubs {
this.logger = new Logger("Stubs");
}

private async updateSettings(): Promise<void> {
const workspace = getProjectPath();

if (workspace === undefined) {
return;
}

// the path to the .vscode folder in the project folder
const vsc = join(workspace, ".vscode");

// check if .vscode folder exists if not create it
if (!(await pathExists(vsc))) {
await mkdir(vsc);
}

// update to new vscode settings for new stubs if old stubs are still installed
// TODO: maybe remove in later versions
await this.addSettings(vsc, true);
}

public async update(): Promise<void> {
const configFolder = getVsCodeUserPath();
const stubsFolder = join(configFolder, "Pico-W-Stub");
const installedStubsFolder = join(configFolder, "Pico-W-Stub");

// ensure config folder exists
await mkdir(configFolder, { recursive: true });
// TODO: remove in later versions
await this.updateSettings();

const existingVersionFile = join(stubsFolder, "version.json");
const currentVersionFile = resolve(
join(__dirname, "..", "stubs", "version.json")
);
if (!(await pathExists(join(installedStubsFolder, "version.json")))) {
// ensure config folder exists
await mkdir(configFolder, { recursive: true });

let installedVersion = "";
let currentVersion = "";

if (await pathExists(installedStubsFolder)) {
const installedMatchingFolders = (
await readdir(installedStubsFolder)
).filter(name => name.match(/micropython_rp2.*\.dist-info/));

if (installedMatchingFolders.length > 0) {
installedVersion = installedMatchingFolders[0];
}
}

const currentFolder = join(__dirname, "..", "mpy_stubs");

const currentVersion = JSON.parse(
await readFile(currentVersionFile, "utf8")
) as { version: string };
if (await pathExists(currentFolder)) {
const currentMatchingFolders = (await readdir(currentFolder)).filter(
name => name.match(/micropython_rp2.*\.dist-info/)
);

if (currentMatchingFolders.length > 0) {
currentVersion = currentMatchingFolders[0];
}
}

// Check if the existing version file exists and if the version is the same
if (await pathExists(existingVersionFile)) {
const existingVersion = JSON.parse(
await readFile(existingVersionFile, "utf8")
) as { version: string };
// Check if the existing version file exists and if the version is the same
if (installedVersion === currentVersion) {
this.logger.info("Installed stubs are already up to date!");

if (existingVersion.version === currentVersion.version) {
return;
}
}

try {
// update stubs folder
await emptyDir(stubsFolder);
await copy(join(__dirname, "..", "stubs"), stubsFolder);
await emptyDir(installedStubsFolder);
await copy(join(__dirname, "..", "mpy_stubs"), installedStubsFolder);

this.logger.info("Updated stubs successfully!");
} catch (error) {
const msg: string =
typeof error === "string" ? error : (error as Error).message;
Expand Down Expand Up @@ -126,22 +165,32 @@ export default class Stubs {
await writeJsonFile(extensionsFilePath, extensions);
}

private async addSettings(vsc: string): Promise<void> {
private async addSettings(
vsc: string,
justUpdate: boolean = false
): Promise<void> {
const settingsFilePath = join(vsc, "settings.json");
const stubsPath = join(".vscode", "Pico-W-Stub");
const defaultSettings = {
const defaultSettings: { [key: string]: string | boolean | object } = {
// eslint-disable-next-line @typescript-eslint/naming-convention
"python.linting.enabled": true,
// eslint-disable-next-line @typescript-eslint/naming-convention
"python.languageServer": "Pylance",
// eslint-disable-next-line @typescript-eslint/naming-convention
"python.analysis.typeCheckingMode": "basic",
// eslint-disable-next-line @typescript-eslint/naming-convention
"micropico.syncFolder": "",
// eslint-disable-next-line @typescript-eslint/naming-convention
"micropico.openOnStart": true,
"python.analysis.diagnosticSeverityOverrides": {
reportMissingModuleSource: "none",
},
};

if (!justUpdate) {
// eslint-disable-next-line @typescript-eslint/naming-convention
defaultSettings["micropico.syncFolder"] = "";
// eslint-disable-next-line @typescript-eslint/naming-convention
defaultSettings["micropico.openOnStart"] = true;
}

interface ISettings {
// eslint-disable-next-line @typescript-eslint/naming-convention
"python.analysis.typeshedPaths": string[];
Expand All @@ -158,7 +207,7 @@ export default class Stubs {
);
settings["python.analysis.extraPaths"] = _.union(
settings["python.analysis.extraPaths"] || [],
[join(stubsPath, "stubs")]
[stubsPath]
);

await writeJsonFile(settingsFilePath, settings);
Expand Down
2 changes: 0 additions & 2 deletions stubs/README.md

This file was deleted.

Loading

0 comments on commit 8573ec1

Please sign in to comment.