Skip to content

Commit 85fa207

Browse files
[#0000] Improve plugins documentation
1 parent d78f098 commit 85fa207

2 files changed

Lines changed: 64 additions & 50 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: 34 additions & 21 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,23 @@ 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.),
113120
# add its implementation from the SDK:
114121
# list(APPEND PLUGIN_SOURCES "${BSK_SDK_RUNTIME_MIN_DIR}/atmosphereBase.cpp")
115-
122+
# An example of this is in the `custom-atm-plugin` example in the SDK repo.
116123
bsk_add_swig_module(
117-
TARGET myModule
118-
INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/myModule/myModule.i"
124+
TARGET exampleCppModule
125+
INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/exampleCppModule/exampleCppModule.i"
119126
SOURCES ${PLUGIN_SOURCES}
120127
INCLUDE_DIRS
121-
"${CMAKE_CURRENT_SOURCE_DIR}/myModule"
128+
"${CMAKE_CURRENT_SOURCE_DIR}/exampleCppModule"
122129
"${CMAKE_CURRENT_SOURCE_DIR}/messages"
123-
LINK_LIBS bsk::plugin
124130
OUTPUT_DIR "${PKG_DIR}"
125131
)
126132
127-
# Optional: generate Python bindings for custom messages
133+
# Optionally generate Python bindings for custom messages
128134
bsk_generate_messages(
129135
OUTPUT_DIR "${PKG_DIR}/messaging"
130136
MSG_HEADERS
@@ -137,7 +143,7 @@ pyproject.toml
137143
.. code-block:: toml
138144
139145
[build-system]
140-
requires = ["scikit-build-core>=0.9"]
146+
requires = ["scikit-build-core>=0.9.3", "bsk-sdk==2.X.Y", "bsk==2.X.Y"]
141147
build-backend = "scikit_build_core.build"
142148
143149
[project]
@@ -147,7 +153,14 @@ pyproject.toml
147153
dependencies = ["bsk"]
148154
149155
[tool.scikit-build]
150-
wheel.packages = []
156+
wheel.packages = ["my_plugin"]
157+
158+
.. note::
159+
160+
Both ``bsk-sdk`` and ``bsk`` must be **pinned to the same version** in
161+
``build-system.requires``. The SDK compiles BSK sources into your plugin
162+
at build time, so mismatched versions will produce a CMake error.
163+
Replace ``2.X.Y`` with the Basilisk version you are targeting.
151164

152165
Building and Installing
153166
-----------------------
@@ -162,7 +175,7 @@ Building and Installing
162175
pip install dist/*.whl
163176
164177
# Run unit tests
165-
pytest myModule/_UnitTest/ -v
178+
pytest exampleCppModule/_UnitTest/ -v
166179
167180
Publishing to PyPI
168181
------------------

0 commit comments

Comments
 (0)