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

Experiment towards an auto-geneated type stubs package #5472

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 0 additions & 4 deletions lib/controller/python/controller/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ def getNodeId(self):
return self.node_id


class Node:
pass


class Node:
wb.wb_supervisor_node_get_root.restype = ctypes.c_void_p
wb.wb_supervisor_node_get_selected.restype = ctypes.c_void_p
Expand Down
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 # 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',
],
)