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

Generate Python stubs with m.css for IDE autocompletion and type checking #2477

Draft
wants to merge 1 commit into
base: main
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
14 changes: 14 additions & 0 deletions docs/conf-stubs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) Meta Platforms, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# Inherit everything from the base config
import os, sys

sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from conf import *

# TODO: uncomment once m.sphinx can handle that
# OUTPUT = None

OUTPUT_STUBS = "../habitat_sim"
2 changes: 1 addition & 1 deletion docs/m.css
Submodule m.css updated 371 files
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
attrs>=19.1.0
docutils
gitpython
imageio
imageio-ffmpeg
jinja2
matplotlib
numba
numpy==1.26.4
Expand Down
17 changes: 15 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ def run(self):
for ext in self.extensions:
self.build_extension(ext)

# Build stubs for all of 'habitat_sim' including bindings to provide
# type information.
subprocess.run(
subprocess.run(["docs/m.css/documentation/python.py", "docs/conf-stubs.py"])
)

def build_extension(self, ext):
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))

Expand Down Expand Up @@ -450,21 +456,28 @@ def load(filename):
setup(
name="habitat_sim",
version=habitat_sim.__version__,
author="FAIR A-STAR",
author="Meta",
description="A high performance simulator for training embodied agents",
long_description="",
packages=find_packages(where="src_python"),
package_dir={"": "src_python"},
install_requires=requirements,
tests_require=["hypothesis", "pytest-benchmark", "pytest"],
setup_requires=["pybind11-stubgen"],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this probably shouldn't be here 🤔

python_requires=">=3.9",
# add extension module
ext_modules=[CMakeExtension("habitat_sim._ext.habitat_sim_bindings", "src")],
# add custom build_ext command
cmdclass=dict(build_ext=CMakeBuild),
cmdclass={
"build_ext": CMakeBuild,
},
zip_safe=False,
include_package_data=True,
package_data={
"habitat_sim": ["py.typed", "**/*.pyi"],
},
)

pymagnum_build_dir = osp.join(
_cmake_build_dir, "deps", "magnum-bindings", "src", "python"
)
Expand Down
Empty file added src_python/habitat_sim/py.typed
Empty file.