MylesMor / nanoleafapi

A Python3 wrapper for the Nanoleaf OpenAPI, for use with the Light Panels, Canvas and Shapes (Hexagons, Triangles and Elements).
https://nanoleafapi.readthedocs.io
MIT License
58 stars 15 forks source link

Add py.typed to enable type checking #17

Open alexlukas opened 5 months ago

alexlukas commented 5 months ago

I was a little too fast and created some stubs for the typeshed project in order to allow for type checking code using this library according to PEP 561 (see here for the pull request). However, I was made aware that most of this library is already typed, so to enable type checking for nanoleafapi, all one has to do is

setup(
    ...,
    package_data = {
        'nanoleafapi': ['py.typed'],
    },
    ...,
    )

This would explicitly allow type checking for nanoleafapi, e.g. in VS Code.

MylesMor commented 5 months ago

Hi, appreciate you opening this issue here! I can definitely see about adding this tomorrow. Since this is new to me, would you know how I can test to make sure it works before I publish the change to the package?

AlexWaygood commented 5 months ago

Hey @MylesMor — here's a possible way of testing this kind of thing in a GitHub Actions workflow:

jobs:
  check-pep561-compliance:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          path: invoke
      - uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - run: |
          pip install mypy
          pip install ./nanoleafapi
          mkdir newdir
          cd newdir
          mypy -c "import nanoleafapi"

The job should fail with mypy errors without the py.typed file, but pass if the py.typed file has been properly added (including the packaging changes @alexlukas mentioned above, which are necessary to ensure that the file gets included in the wheel)

MylesMor commented 5 months ago

Thanks, appreciate this! Unfortunately was super busy today but will hopefully get around to this tomorrow.