Skip to content

Commit 8e23e3c

Browse files
committedNov 11, 2022
First pass at building a stubs package from the sources
This uses mypy's stubgen to derive stubs from the source code, then wraps the generated stubs in a minimal Python package.
1 parent ca64aaa commit 8e23e3c

File tree

6 files changed

+97
-0
lines changed

6 files changed

+97
-0
lines changed
 
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build Python Stubs
2+
3+
# TODO: work out where this should actually run
4+
on:
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
10+
jobs:
11+
build-python-stubs:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Python 3.11
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.11'
20+
cache: pip
21+
cache-dependency-path: resources/python_stubs/requirements.txt
22+
23+
- name: Install Dependencies
24+
run: |
25+
pip install -r resources/python_stubs/requirements.txt
26+
27+
- name: Build the package
28+
run: |
29+
resources/python_stubs/build.sh
30+
31+
- uses: actions/upload-artifact@v3
32+
with:
33+
name: dist
34+
path: resources/python_stubs/dist

‎resources/python_stubs/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.egg-info
2+
3+
controller-stubs/*.pyi
4+
5+
build
6+
dist

‎resources/python_stubs/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Webots Stubs
2+
3+
Typing stubs for [Webots][webots]' `controller` package.
4+
5+
These are auto-generated from the Python API which comes with Webots.
6+
7+
[webots]: https://www.cyberbotics.com/

‎resources/python_stubs/build.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
cd $(dirname $0)
4+
5+
rm -rf controller-stubs
6+
7+
stubgen ../../lib/controller/python/controller --output .
8+
9+
mv controller controller-stubs
10+
11+
python setup.py sdist bdist_wheel
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mypy
2+
wheel

‎resources/python_stubs/setup.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from pathlib import Path
2+
3+
from setuptools import setup # type: ignore[import]
4+
5+
long_description = (Path(__file__).parent / 'README.md').read_text()
6+
7+
setup(
8+
name='webots-stubs',
9+
version='0.1.0', # TODO: version with the Webots version number?
10+
url='https://www.cyberbotics.com/',
11+
project_urls={
12+
'Issue tracker': 'https://github.com/cyberbotics/webots/issues',
13+
'Source Code': 'https://github.com/cyberbotics/webots',
14+
},
15+
description="Type stubs for Webots' 'controller' package.",
16+
long_description=long_description,
17+
long_description_content_type='text/markdown',
18+
19+
package_data={'controller-stubs': ['*.pyi']},
20+
packages=['controller-stubs'],
21+
22+
license='Apache 2.0',
23+
24+
classifiers=[
25+
'Development Status :: 2 - Pre-Alpha',
26+
'Natural Language :: English',
27+
'Operating System :: OS Independent',
28+
'Programming Language :: Python',
29+
'Programming Language :: Python :: 3 :: Only',
30+
'Programming Language :: Python :: 3.7',
31+
'Programming Language :: Python :: 3.8',
32+
'Programming Language :: Python :: 3.9',
33+
'Programming Language :: Python :: 3.10',
34+
'Programming Language :: Python :: 3.11',
35+
'Topic :: Software Development',
36+
],
37+
)

0 commit comments

Comments
 (0)