GithubHelp home page GithubHelp logo

drewwhis / pybricks-stubs Goto Github PK

View Code? Open in Web Editor NEW
21.0 5.0 6.0 77 KB

Typing for EV3 Python programming (using the LEGO® pybricks)

License: MIT License

Python 100.00%
lego ev3 robot first-lego-league pybricks fll first pybricks-stubs mindstorms

pybricks-stubs's Introduction

pybricks-stubs

Package Rationale

This package is meant to provide typings (and IntelliSense) to those developing Python programs for the LEGO® MINDSTORMS® EV3 with the official LEGO® software (pybricks).

This package does not support executing robot code on the computer or on the robot. This package does provide type hinting while writing Python code on the computer for later upload/deployment to the robot.

Version Documentation

For version 1.0.0 and earlier, all typings are based on the LEGO® API 1.0.0.

For versions after 1.0.0 (including 2.0.x and the 1.0.* pre-releases for 2.0.0), all typings are based on the LEGO® API 2.0.0.

Choosing Your Version

For the latest version, you can run:

pip install pybricks-stubs

If you are working with version 1.0.0 from LEGO®, make sure you install version 1.0.0 of the package with this command:

pip install pybricks-stubs==1.0.0

Turning On Type Hints

If you are working with version 2.0.0 or later and have generated a project using the Visual Studio Code extension, you may need to edit your settings file in order for your hints to work.

If so, you would go to the .vscode folder to the settings.json file. You will want to edit this line:

"python.languageServer": "None"

Just change "None" to "Microsoft" or "Jedi" (either should work). You will have to reload the project. Follow the prompts or close Visual Studio Code and re-open the project.

Be aware that things your computer lets you import may not be available on the EV3's local version of Python. Make sure you check that your code runs on the brick whenever you import something new.

Disclaimer

This package is not produced or maintained by LEGO®, nor is it officially endorsed by LEGO® or FIRST®.

Issues

Please report any issues you encounter on the GitHub page.

pybricks-stubs's People

Contributors

drewwhis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pybricks-stubs's Issues

Return values of methods

Is there a reason why methods that would return a value, don't actually do so?
(I am new to python, so I might miss something.)

I am aware that these are only stubs, but the linter gives me errors like "Assigning result of a function call, where the function has no returnpylint(assignment-from-no-return)" which I would like to avoid and my test show that this is easily avoided by returning some dummy value (e.g. 0 or []).

I would be happy to fix it myself and create a pull request, if you want me to.
And thanks for the nice work, makes ev3 programming so much easier and more fun.

pip command

Unable to install the new version of pybricks-stups (2.0.0). Here is the error message:
B:>pip install pybricks-stubs
Requirement already satisfied: pybricks-stubs in c:\users\kawag\appdata\local\programs\python\python37-32\lib\site-packages (0.0.6)

[QUESTION] PEP 561 stubs

Hi. Nice work here. I have a question about making this work better with Pybricks.

We are currently publishing the pybricks-api repository as the pybricks package on PyPi. As such, the fact that pybricks-stubs also provides a pybricks package means that both can't be installed at the same time.

pybricks-api currently provides documentation for Pybricks MicroPython but no type hints. And given the name pybricks-stubs, I would expect this repository to provide typing information in .pyi files rather than .py files in a package named pybricks-stubs rather than pybircks as per PEP 561.

Would you be open to a pull request to make such a change? This would allow pybricks-api and pybricks-stubs to complement each other rather than essentially providing the same thing. This would mean that any implementation would get removed here (e.g. function bodies replaced with ...) and the tests would probably no longer be relevant. I know a lot of hard work went into that and it is not a nice feeling to just throw it out but we would probably accept it in pybricks-api if it seems useful.

Additionally, I would like for pybricks-stubs to provide additional -stubs packages for MicroPython modules like urandom so that we can have code completion for those as well.

In the long term (i.e. for Pybricks 3.x), it would be cool if we could also add a setup option so that people could install pybricks-stubs for different hubs besides the EV3.

Invalid syntax in Enum stubs, and no code completion for enums

I added your project in my environment and I got error message. I is still installed and the intellisence support for VS Code mostly works.

Downloading/unpacking pybricks-stubs
  Downloading pybricks-stubs-0.0.3.tar.gz
  Running setup.py (path:/tmp/pip_build_root/pybricks-stubs/setup.py) egg_info for package pybricks-stubs
    /usr/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    
Installing collected packages: pybricks-stubs
  Running setup.py install for pybricks-stubs
    /usr/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
      File "/usr/local/lib/python3.4/dist-packages/pybricks/parameters.py", line 7
        BOTTOM_LEFT: ...
                   ^
    SyntaxError: invalid syntax
    
    
Successfully installed pybricks-stubs
Cleaning up...

https://github.com/drewwhis/pybricks-stubs/blob/master/pybricks/parameters.py#L7
My issue is that the code completion can't help me for the enums like Align, SoundFile, etc.

Any idea why and how to fix it?

If I define the enum value with
LEFT = ""
for example, it is now visible in the code hints. But I am afraid that I am doing something utterly wrong.

Update: Well, I tested and it worked:

class ImageFile(Enum):
    STOP_2: ...
    THUMBS_UP = "" 
    EV3: ...

and my code:

brick.sound.beep()
brick.display.image(ImageFile.THUMBS_UP)
time.sleep(2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.