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

Added documentation of how to handle code changes. #920

Merged
merged 6 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
75 changes: 75 additions & 0 deletions doc/contributors_guide/code_changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Code changes
============
Although that DLite haven't reached version 1.0.0, it strives to be stable and not introduce unnecessary backward-incompatible changes.


Versioning
----------
Before reaching v 1.0.0, DLite follows the following versioning rules that are well-known from Python:

* **patch release**: Only backward-compatible changes.
New deprecation warnings can be added.

* **minor release**: Backward-incompatible changes.
Removal of deprecated features.
jesper-friis marked this conversation as resolved.
Show resolved Hide resolved

After version 1.0.0, DLite should strictly follow the [semantic versioning] rules.
jesper-friis marked this conversation as resolved.
Show resolved Hide resolved


Feature deprecation
-------------------
In Python, use `dlite.deprecation_warning()` (function to be added) to mark deprecation warnings.
This function is a simple wrapper around `warnings.warn(msg, DeprecationWarning, stacklevel=2)` with the release version when the feature is planned to be removed as an additional argument.

In C, use the `deprecation_warning()` function (to be added) to mark a
deprecation warning.

The idea with these functions is to make it easy to grep for deprecation warnings that should be remove in a new backward-incompatible release.
The following command can e.g. be used to find all deprecation warnings:

find \( -name '*.py' -o -name '*.i' -o -name '*.c' \) ! -path './build*' | xargs grep -n -A1 deprecation_warning


How to handle different types of code changes
---------------------------------------------

### Backward-compatible API changes
The easiest API changes are those that only adds new functions or classes without changing the existing code, apart from adding deprecation warnings hinting about how to use the new API.

Adding new arguments to an existing function or new methods to existing classes falls also into this category. It is possible to
jesper-friis marked this conversation as resolved.
Show resolved Hide resolved
**Note**, new (positional) arguments should be added to the end of the argument list, such that existing code using positional arguments will be unaffected by the change.

### New behavior
All changes in behavior should be considered backward-incompatible.

Where it make sense, DLite will try to optionally keep the new/old behaviour over some releases in order for users to adapt to the new behavior.

Each optional new behavior should have a:
- name
- description
- release number for when the behavior was introduced (keeping old behavior as default)
- release number for when the new behavior should be the default (managed automatically)
- expected release number for when the old behavior should be removed (require developer effort)

All behaviors are described in a single source file `src/dlite-behavior.c`.

Behavior can be selected in several ways:

- **programmatically from Python**:

>>> from dlite.behavior import Behavior
>>> Behavior.<NAME> = True # true means use the new behavior

- **programmatically from C**:

dlite_behavior("<NAME>", 1);

- **via environment variables**:

export DLITE_BEHAVIOR_<NAME>

A deprecation warning will automatically be issued if a behavior is not selected
explicitly.


[semantic versioning]: https://semver.org/
jesper-friis marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions doc/contributors_guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Contributor's Guide
documentation_contributors
documentation_testing
release_instructions
code_changes
tips_and_tricks