Skip to content

Commit 24b7af4

Browse files
[#1390] Improve plugins documentation
1 parent 1f1dcef commit 24b7af4

2 files changed

Lines changed: 66 additions & 53 deletions

File tree

docs/source/Plugins/overview.rst

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,24 @@ Basilisk plugins are built with `bsk-sdk <https://pypi.org/project/bsk-sdk/>`_,
9494
a companion Python package that ships the headers, SWIG interface files, and
9595
CMake helpers needed to compile out-of-tree modules.
9696

97-
.. code-block:: text
97+
.. graphviz::
98+
99+
digraph plugin_arch {
100+
graph [rankdir=TB, splines=ortho, bgcolor=transparent, nodesep=0.5]
101+
node [shape=box, style="rounded,filled", fontname="Helvetica",
102+
fontsize=13, margin="0.4,0.2", width=4, fixedsize=false]
103+
edge [fontname="Helvetica", fontsize=11, minlen=2]
104+
105+
plugin [label="Your plugin\n(separate repo / wheel)",
106+
fillcolor="#dce8fb"]
107+
sdk [label="bsk-sdk\n(BSK headers · SWIG interfaces · CMake helpers)",
108+
fillcolor="#d4edda"]
109+
bsk [label="Basilisk: pip install bsk",
110+
fillcolor="#fff3cd"]
98111

99-
┌─────────────────────────────────────┐
100-
│ Your plugin (separate repo/wheel) │
101-
│ │
102-
│ myModule.cpp / myModule.h │
103-
│ myModule.i │
104-
│ CMakeLists.txt │
105-
└──────────────┬──────────────────────┘
106-
│ links against
107-
┌──────────────▼──────────────────────┐
108-
│ bsk-sdk wheel │
109-
│ (vendored BSK headers + cmake) │
110-
└──────────────┬──────────────────────┘
111-
│ compatible with
112-
┌──────────────▼──────────────────────┐
113-
│ Basilisk (pip install bsk) │
114-
└─────────────────────────────────────┘
112+
plugin -> sdk [label=" compiles against "]
113+
sdk -> bsk [label=" compatible with "]
114+
}
115115

116116
The plugin compiles against the same BSK headers and SWIG runtime that
117117
Basilisk uses, so message types, base classes, and the module API are
@@ -126,19 +126,21 @@ Quick Start
126126
127127
pip install bsk-sdk
128128
129-
**2. Create your plugin layout** (following BSK module conventions)
129+
**2. Create your plugin layout**
130130

131131
.. code-block:: text
132132
133133
my-plugin/
134134
├── pyproject.toml
135135
├── CMakeLists.txt
136-
└── myModule/
137-
├── myModule.h
138-
├── myModule.cpp
139-
├── myModule.i
136+
├── my_plugin/ # importable Python package
137+
│ └── __init__.py
138+
└── exampleCppModule/ # C++/SWIG source
139+
├── exampleCppModule.h
140+
├── exampleCppModule.cpp
141+
├── exampleCppModule.i
140142
└── _UnitTest/
141-
└── test_myModule.py
143+
└── test_exampleCppModule.py
142144
143145
**3. Wire up CMakeLists.txt**
144146

@@ -158,10 +160,9 @@ Quick Start
158160
find_package(bsk-sdk CONFIG REQUIRED)
159161
160162
bsk_add_swig_module(
161-
TARGET myModule
162-
INTERFACE myModule/myModule.i
163-
SOURCES myModule/myModule.cpp
164-
LINK_LIBS bsk::plugin
163+
TARGET exampleCppModule
164+
INTERFACE exampleCppModule/exampleCppModule.i
165+
SOURCES exampleCppModule/exampleCppModule.cpp
165166
OUTPUT_DIR "${SKBUILD_PLATLIB_DIR}/my_plugin"
166167
)
167168
@@ -177,11 +178,11 @@ Quick Start
177178

178179
.. code-block:: python
179180
180-
from my_plugin import myModule
181+
from my_plugin import exampleCppModule
181182
from Basilisk.utilities import SimulationBaseClass
182183
183184
sim = SimulationBaseClass.SimBaseClass()
184-
mod = myModule.MyModule()
185+
mod = exampleCppModule.ExampleCppModule()
185186
sim.AddModelToTask("task", mod)
186187
187188
A complete working example is provided in the

docs/source/Plugins/writing.rst

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,29 @@ Prerequisites
3030
Plugin Layout
3131
-------------
3232

33-
Follow the same folder convention as BSK — one folder per module, named
34-
identically to the module:
33+
Every plugin needs a Python package directory (``my_plugin/`` below). This
34+
is the importable namespace your users will ``import`` from, and where both
35+
compiled SWIG extensions and pure-Python modules are installed. C++/SWIG
36+
source trees live alongside it at the repo root and get compiled into that
37+
package at build time. Pure-Python modules can be added directly inside the
38+
package directory with no extra build steps:
3539

3640
.. code-block:: text
3741
3842
my-plugin/
3943
├── pyproject.toml
4044
├── CMakeLists.txt
41-
├── messages/ # (optional) custom message definitions
45+
├── my_plugin/ # Python package (SWIG outputs install here too)
46+
│ ├── __init__.py
47+
│ └── examplePythonModule.py # (optional) pure-Python modules
48+
├── messages/ # (optional) custom message definitions
4249
│ └── MyMsgPayload.h
43-
└── myModule/
44-
├── myModule.h
45-
├── myModule.cpp
46-
├── myModule.i
50+
└── exampleCppModule/ # C++/SWIG module source
51+
├── exampleCppModule.h
52+
├── exampleCppModule.cpp
53+
├── exampleCppModule.i
4754
└── _UnitTest/
48-
└── test_myModule.py
55+
└── test_exampleCppModule.py
4956
5057
SWIG Interface
5158
--------------
@@ -55,14 +62,14 @@ The ``.i`` file is the same as any BSK module. For C++ use
5562

5663
.. code-block:: swig
5764
58-
%module myModule
65+
%module exampleCppModule
5966
%{
60-
#include "myModule.h"
67+
#include "exampleCppModule.h"
6168
%}
6269
6370
%include "swig_common_model.i" /* C++ modules */
6471
/* %include "swig_c_wrap.i" C modules — use %c_wrap_2 instead */
65-
%include "myModule.h"
72+
%include "exampleCppModule.h"
6673
6774
If subclassing a BSK base class, ``%include`` its ``.i`` file before yours:
6875

@@ -107,24 +114,22 @@ plugin-specific section:
107114
# Plugin-specific configuration
108115
# ==========================================================================
109116
110-
file(GLOB PLUGIN_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/myModule/*.cpp")
117+
file(GLOB PLUGIN_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/exampleCppModule/*.cpp")
111118
112119
# If subclassing a BSK base class (AtmosphereBase, DynamicEffector, etc.),
113-
# add its implementation from the SDK:
114-
# list(APPEND PLUGIN_SOURCES "${BSK_SDK_RUNTIME_MIN_DIR}/atmosphereBase.cpp")
115-
120+
# bsk_add_swig_module automatically links the required SDK runtime sources —
121+
# no manual list(APPEND) is needed. See the `custom-atm-plugin` example.
116122
bsk_add_swig_module(
117-
TARGET myModule
118-
INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/myModule/myModule.i"
123+
TARGET exampleCppModule
124+
INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/exampleCppModule/exampleCppModule.i"
119125
SOURCES ${PLUGIN_SOURCES}
120126
INCLUDE_DIRS
121-
"${CMAKE_CURRENT_SOURCE_DIR}/myModule"
127+
"${CMAKE_CURRENT_SOURCE_DIR}/exampleCppModule"
122128
"${CMAKE_CURRENT_SOURCE_DIR}/messages"
123-
LINK_LIBS bsk::plugin
124129
OUTPUT_DIR "${PKG_DIR}"
125130
)
126131
127-
# Optional: generate Python bindings for custom messages
132+
# Optionally generate Python bindings for custom messages
128133
bsk_generate_messages(
129134
OUTPUT_DIR "${PKG_DIR}/messaging"
130135
MSG_HEADERS
@@ -137,17 +142,24 @@ pyproject.toml
137142
.. code-block:: toml
138143
139144
[build-system]
140-
requires = ["scikit-build-core>=0.9"]
145+
requires = ["scikit-build-core>=0.9.3", "bsk-sdk==2.X.Y", "bsk==2.X.Y", "swig==4.4.1"]
141146
build-backend = "scikit_build_core.build"
142147
143148
[project]
144149
name = "my-plugin"
145150
version = "1.0.0"
146151
requires-python = ">=3.9"
147-
dependencies = ["bsk"]
152+
dependencies = ["bsk==2.X.Y"]
148153
149154
[tool.scikit-build]
150-
wheel.packages = []
155+
wheel.packages = ["my_plugin"]
156+
157+
.. note::
158+
159+
``bsk-sdk``, ``bsk``, and the runtime ``dependencies`` entry must all be
160+
**pinned to the same version**. The SDK compiles BSK sources into your
161+
plugin at build time, so mismatched versions will produce a CMake error.
162+
Replace ``2.X.Y`` with the Basilisk version you are targeting.
151163

152164
Building and Installing
153165
-----------------------
@@ -162,7 +174,7 @@ Building and Installing
162174
pip install dist/*.whl
163175
164176
# Run unit tests
165-
pytest myModule/_UnitTest/ -v
177+
pytest exampleCppModule/_UnitTest/ -v
166178
167179
Publishing to PyPI
168180
------------------

0 commit comments

Comments
 (0)