microbit-foundation / micropython-microbit-stubs

Type stubs for MicroPython for micro:bit to support the micro:bit Python Editor V3
https://python.microbit.org/
Other
3 stars 2 forks source link

Is it possible to use these stubs coding locally in VS Code? #106

Open ddribin opened 2 weeks ago

ddribin commented 2 weeks ago

Hi. This is more of a question than an issue, but is it possible to use these stubs if coding locally in Visual Studio Code? And if so, do you have any pointers as to how that would work?

Thanks! My kids have learned how to use the micro:bit in their school, and have really enjoyed it!

Josverl commented 2 weeks ago

Hi, I maintain the micropython-stubs repo with typestubs of quite a few of the micropython ports and boards. I would be interested in collaboration to:

just @mention me if you are interested, and we can figure out how to make that work.

Josverl commented 1 week ago

Assuming you are using vscode and pylance the below setup should get you started by setting up a sparce clone of just (one of) the typing folder(s) in this repo:

To clone just the lang/en folder from the https://github.com/microbit-foundation/micropython-microbit-stubs repository using the sparse-checkout feature of Git.

Assuming you have a folder for you project called: project_foo

Create and navigate to the typings directory:

cd project_foo
mkdir typings
cd typings
git init

Add the remote repository:

Pull from the remote repository:

git pull origin main

Start VScode

cd ..
code .
ddribin commented 1 week ago

@Josverl Thanks for the response! I've tried what you wrote, and the copied candle.py from this repo to the top-level:

> tree -F -L 5
./
├── candle.py
└── typings/
    └── lang/
        └── en/
            └── typeshed/
                └── stdlib/

Unfortunately, I still get red squiggles in VS Code on the from microbit import * line:

Screenshot 2024-06-25 at 8 44 22 AM
ddribin commented 1 week ago

The red squiggles are coming from the Flake8 VS Code plugin. If I disable that plugin for the workspace, then it does appear to be working. Thanks! I can make this work, though it would be super helpful if this were pip installable.