1 Deprecation {#deprecation}
4 Sometimes it is useful to drop support
for code
for various reasons,
for example
5 - it represents a failed experiment
6 - there is better functionality that replaced it
8 - it is broken and not worth fixing
10 For such code that will be removed, our policy is to mark it as deprecated
11 for one stable release (e.g. 2.1) and then remove it in the next one (2.2).
12 In practice this means adding the markers in the %IMP `develop` branch *before*
13 the 2.1 release, then removing the code in the `develop` branch sometime between
14 the 2.1 and 2.2 releases. The general idea is that any code that works in the
15 latest stable release (e.g. tutorials, examples, biological systems) should
16 also work without modification in the latest nightly build (but there is no
17 guarantee that code works unchanged from one stable release to the next).
19 \note If you deprecate code in favor of some new mechanism, it is your
20 responsibility to update all callers of the old code in %IMP
21 (C++ code, test cases, examples, benchmarks) to use the new way of
22 doing things, and ensure the test cases still pass. You should also
23 wait until the new mechanism is fully functional before deprecating
26 Code that is deprecated must produce warnings when used. (You can also force
27 usage of deprecated code to trigger an exception by calling
28 IMP::set_deprecation_exceptions() or by passing the `--deprecation_exceptions`
34 C++ code should be marked in the following way (where EXAMPLE is replaced by
35 your module name and 2.1 is replaced by the release where the code is
37 - macros should have an `IMPEXAMPLE_DEPRECATED_MACRO(version, replacement)` line added within their definition
39 #define MY_DEPRECATED_MACRO(args) \
40 IMPEXAMPLE_DEPRECATED_MACRO(2.1, "You should use MY_NEW_MACRO(args) instead") \
43 - class methods should have `IMPEXAMPLE_DEPRECATED_METHOD_DECL(version)` added to the end of the declaration and `IMPEXAMPLE_DEPRECATED_METHOD_DEF(version, message)` added in their body
45 class IMPEXAMPLEEXPORT MyClass {
46 IMPEXAMPLE_DEPRECATED_METHOD_DECL(2.1)
47 void my_deprecated_method(args) {
48 IMPEXAMPLE_DEPRECATED_METHOD_DEF(2.1, "Use my_new_method(args) instead");
52 - functions should have `IMPEXAMPLE_DEPRECATED_FUNCTION_DECL(version)` added to the end of the declaration and `IMPEXAMPLE_DEPRECATED_FUNCTION_DEF(version, message)` added in their body
54 IMPEXAMPLE_DEPRECATED_FUNCTION_DECL(2.1)
55 void my_deprecated_function(args);
57 void my_deprecated_function(args) {
58 IMPEXAMPLE_DEPRECATED_FUNCTION_DEF(2.1, "Use my_new_function(args) instead");
62 - classes should have `IMPEXAMPLE_DEPRECATED_OBJECT_DECL(version)` or `IMPEXAMPLE_DEPRECATED_VALUE_DECL(version)` added before their constructor declarations and `IMPEXAMPLE_DEPRECATED_OBJECT_DEF(version, message)` or `IMPEXAMPLE_DEPRECATED_VALUE_DEF(version, message)` added in their constructor bodies.
64 class IMPEXAMPLEEXPORT MyDeprecatedClass :: public IMP::Object {
66 IMPEXAMPLE_DEPRECATED_OBJECT_DECL(2.1)
67 MyDeprecatedClass(args) {
68 IMPEXAMPLE_DEPRECATED_OBJECT_DEF(2.1, "Use MyNewClass instead");
70 IMPEXAMPLE_DEPRECATED_OBJECT_DECL(2.1)
71 MyDeprecatedClass(other_args) {
72 IMPEXAMPLE_DEPRECATED_OBJECT_DEF(2.1, "Use MyNewClass instead");
76 - Headers should have `IMPEXAMPLE_DEPRECATED_HEADER(version, message)` in them.
78 #ifndef IMP_MY_DEPRECATED_HEADER_H
79 #define IMP_MY_DEPRECATED_HEADER_H
80 IMPEXAMPLE_DEPREACTED_HEADER(2.1, "Use my_new_header.h")
82 #endif // IMP_MY_DEPRECATED_HEADER_H
85 - All things should also use the `\deprecated_at` doxygen macro in their docs:
89 These will provide documentation, and runtime and compile time warning messages to users.
94 For Python code, we provide similar functions and decorators to mark modules,
95 classes, methods, or functions as deprecated:
97 IMP.deprecated_module("2.1", __name__, "Use my_new_module instead")
99 @IMP.deprecated_object("2.1", "Use MyNewClass instead")
100 class MyClass(object):
101 @IMP.deprecated_method("2.1", "Use my_new_method(args) instead")
102 def my_deprecated_method(self):
105 @IMP.deprecated_function("2.1", "Use my_new_function(args) instead")
106 def my_deprecated_function(args):
109 For Python there is no need to use the `\\deprecated_at` macro - the
110 warning message from the decorator is automatically added to the documentation.
115 Any code that demonstrates the use of %IMP should not rely on deprecated
116 functionality. This includes tests, examples, and benchmarks.
118 All examples run as part of the %IMP test suite get passed the
119 `--deprecation_exceptions` command line flag. Thus, any example that calls
120 IMP.setup_from_argv() or uses IMP.OptionParser will fail if it tries to
121 call deprecated code. It is highly recommended that all examples do this.
123 All unit tests that call IMP.test.main() will also trigger exceptions if they
124 try to call deprecated code. If for some reason you need to test a deprecated
125 code pathway, use the IMP.allow_deprecated()
126 [context manager](http://eigenhombre.com/2013/04/20/introduction-to-context-managers/) as follows:
128 with IMP.allow_deprecated():
129 my_deprecated_function()