Skip to content

Commit

Permalink
First pass at building a stubs package from the sources
Browse files Browse the repository at this point in the history
This uses mypy's stubgen to derive stubs from the source code, then
wraps the generated stubs in a minimal Python package.
  • Loading branch information
PeterJCLaw committed Nov 11, 2022
1 parent ca64aaa commit c0f3567
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build_stubs_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build Python Stubs

# TODO: work out where this should actually run
on:
push:
branches:
- master
pull_request:

jobs:
build-python-stubs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: pip
cache-dependency-path: resources/python_stubs/requirements.txt

- name: Install Dependencies
run: |
pip install -r resources/python_stubs/requirements.txt
- name: Build the package
run: |
resources/python_stubs/build.sh
- uses: actions/upload-artifact@v3
with:
name: dist
path: resources/python_stubs/dist
6 changes: 6 additions & 0 deletions resources/python_stubs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.egg-info

controller-stubs/*.pyi

build
dist
7 changes: 7 additions & 0 deletions resources/python_stubs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Webots Stubs

Typing stubs for [Webots][webots]' `controller` package.

These are auto-generated from the Python API which comes with Webots.

[webots]: https://www.cyberbotics.com/
11 changes: 11 additions & 0 deletions resources/python_stubs/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

cd $(dirname $0)

rm -rf controller-stubs

stubgen ../../lib/controller/python/controller --output .

mv controller controller-stubs

python setup.py sdist bdist_wheel
2 changes: 2 additions & 0 deletions resources/python_stubs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mypy
wheel
37 changes: 37 additions & 0 deletions resources/python_stubs/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from pathlib import Path

from setuptools import setup, find_packages # type: ignore[import]

long_description = (Path(__file__).parent / 'README.md').read_text()

setup(
name='webots-stubs',
version='0.1.0', # TODO: version with the Webots version number?
url='https://www.cyberbotics.com/',
project_urls={
'Issue tracker': 'https://github.com/cyberbotics/webots/issues',
'Source Code': 'https://github.com/cyberbotics/webots',
},
description="Type stubs for Webots' 'controller' package.",
long_description=long_description,
long_description_content_type='text/markdown',

package_data={'controller-stubs': ['*.pyi']},
packages=['controller-stubs'],

license='Apache 2.0',

classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Software Development',
],
)

0 comments on commit c0f3567

Please sign in to comment.