Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ddribin opened this issue Jun 21, 2024 · 4 comments
Open

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

ddribin opened this issue Jun 21, 2024 · 4 comments

Comments

@ddribin
Copy link

ddribin commented Jun 21, 2024

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
Copy link

Josverl commented Jun 24, 2024

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:

  • further enrich the microbit stubs , for instance by adding/referencing the micropython-stdlib-stubs
  • to publish the microbit stubs to PyPi for easy use in other IDEs

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

@Josverl
Copy link

Josverl commented Jun 24, 2024

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:

  • Open your terminal.
  • Navigate to your project_foo folder
  • Create the typings directory if it doesn't exist and navigate into it
  • Initialize a new git repository
cd project_foo
mkdir typings
cd typings
git init

Add the remote repository:

  • Enable sparse-checkout:
  • Create a file in .git/info/sparse-checkout and add the path of the folder you want to clone:
  • I am assuming you want to clone the lang/en folder.
    If you want to clone a different folder, replace lang/en with the path of the folder you want to clone.
git remote add -f origin https://github.com/microbit-foundation/micropython-microbit-stubs.git
git config core.sparseCheckout true
echo "lang/en" >> .git/info/sparse-checkout

Pull from the remote repository:

git pull origin main

Start VScode

cd ..
code .

@ddribin
Copy link
Author

ddribin commented Jun 25, 2024

@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
Copy link
Author

ddribin commented Jun 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants