Skip to content

Commit 62889b5

Browse files
authored
docs: Add deprecation policy to contributor guide (#2900)
Adds a new "Deprecation Policy" section to our contributor guide, establishing clear guidelines for how we deprecate features in Mesa. The deprecation policy is structured around a clear 4-step process: (1) introduce alternative with optional PendingDeprecationWarning (2) complete prerequisites (docs, migration guide, examples) (3) add FutureWarning for active deprecation (4) remove in next major version. Changes the active deprecation warning from DeprecationWarning to FutureWarning, which is visible to users by default. This is important since Mesa's deprecated methods live in imported modules, not user scripts, so DeprecationWarning would be hidden even when users run code in __main__.
1 parent 553160b commit 62889b5

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

CONTRIBUTING.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,88 @@ To create a new release, follow these steps:
197197

198198
A recorded video of this process is [available here](https://youtu.be/JE44jkegmns).
199199

200+
### Deprecation policy
201+
Mesa follows [Semantic Versioning](https://semver.org/) (SemVer) and has a structured deprecation process to ensure users have time to migrate to new APIs while maintaining backward compatibility.
202+
203+
#### Deprecation process
204+
##### Step 1: Introduce alternative
205+
When implementing a replacement feature:
206+
207+
- Add the new, stable alternative
208+
- Optionally add a `PendingDeprecationWarning` to the old feature (signals intent in source code, hidden by default)
209+
210+
```python
211+
warnings.warn(
212+
"old_feature() will be deprecated in a future release. "
213+
"Use new_feature() instead.",
214+
PendingDeprecationWarning,
215+
stacklevel=2,
216+
)
217+
```
218+
219+
##### Step 2: Complete prerequisites
220+
Before active deprecation, all of the following must be complete:
221+
222+
1. **Documentation updated**: All relevant docs and tutorials reflect the new approach
223+
2. **Migration guide entry added**: Clear entry in the [Migration Guide](https://github.com/projectmesa/mesa/blob/main/docs/migration_guide.md) explaining what changed and how to update code
224+
3. **Examples updated**: All example models use the new API
225+
226+
##### Step 3: Active deprecation
227+
The alternative must be available for *at least one minor release* before adding a `FutureWarning`. This warning is visible to all users by default.
228+
229+
```python
230+
warnings.warn(
231+
"old_feature() is deprecated and will be removed in Mesa X.0. "
232+
"Use new_feature() instead. "
233+
"See: https://mesa.readthedocs.io/latest/migration_guide.html#section",
234+
FutureWarning,
235+
stacklevel=2,
236+
)
237+
```
238+
239+
##### Step 4: Remove deprecated feature
240+
Remove the old feature in the next major version.
241+
242+
#### Version requirements
243+
| Action | Allowed in |
244+
|--------|------------|
245+
| Add alternative + `PendingDeprecationWarning` | Any release |
246+
| Add `FutureWarning` | Minor release (patch only with compelling reason) |
247+
| Remove deprecated feature | Major release only |
248+
249+
#### Experimental features
250+
For features in `mesa.experimental`, steps 1–3 can be done simultaneously, and step 4 can occur in any subsequent release (including minor/patch). Experimental features:
251+
252+
- Can be changed or removed in any release
253+
- Don't require a deprecation warning period
254+
- Should still communicate changes through release notes
255+
256+
Following the full process is encouraged when feasible.
257+
258+
#### Migration guide entry format
259+
Place new entries at the top (newest first). Include:
260+
261+
1. Clear heading describing the change
262+
2. Brief explanation of what changed and why
263+
3. Before/after code examples
264+
4. Links to relevant PRs/issues
265+
266+
````markdown
267+
## Mesa X.Y.0
268+
### Feature Name Change
269+
Brief description of what changed and why.
270+
271+
```python
272+
# Old
273+
old_method()
274+
275+
# New
276+
new_method()
277+
```
278+
279+
- Ref: [PR #1234](https://github.com/projectmesa/mesa/pull/1234), [Documentation](link)
280+
````
281+
200282
## Special Thanks
201283

202284
A special thanks to the following projects who offered inspiration for this contributing file.

0 commit comments

Comments
 (0)