|
| 1 | +.. -*- mode: rst -*- |
| 2 | +
|
| 3 | +Pickler2 |
| 4 | +=================================== |
| 5 | + |
| 6 | +Small package allowing to decorate a function so that it automatically pickle its results |
| 7 | +and load it the next time it is called. |
| 8 | + |
| 9 | +Example of usage |
| 10 | +=================================== |
| 11 | + |
| 12 | +With the following code, the first time long_function() will be called, it will execute and |
| 13 | +save the pickle processed_data. Next time it is run, it will load the pickled object without |
| 14 | +running the function. |
| 15 | + |
| 16 | +.. code-block:: python |
| 17 | +
|
| 18 | + from pickler2 import pickled |
| 19 | +
|
| 20 | + @pickled("some_file_name.pck") |
| 21 | + def long_function(): |
| 22 | + ... long time to process data ... |
| 23 | + return processed_data |
| 24 | +
|
| 25 | +To explicitly re-run the function, you can call |
| 26 | + |
| 27 | +.. code-block:: python |
| 28 | +
|
| 29 | + long_function(run=True) |
| 30 | +
|
| 31 | +When using this functionality at different places, within a project, you might want to save |
| 32 | +all the pickles at a same place. This can be done by given full name to the decorator |
| 33 | + |
| 34 | +.. code-block:: python |
| 35 | +
|
| 36 | + @pickled("/some/long/path/some_file_name.pck") |
| 37 | + def long_function(): |
| 38 | + ... long time to process data ... |
| 39 | + return processed_data |
| 40 | +
|
| 41 | +Alternatively, the project pickling path can be registered as follow |
| 42 | + |
| 43 | +.. code-block:: python |
| 44 | +
|
| 45 | + from pickler2 import register_project_path |
| 46 | +
|
| 47 | + register_project_path("/some/long/path/", "my_project") |
| 48 | +
|
| 49 | +and then use provide the project name to the constructor: |
| 50 | + |
| 51 | +.. code-block:: python |
| 52 | +
|
| 53 | + @pickled("some_file_name.pck", project_name="my_project") |
| 54 | + def long_function(): |
| 55 | + ... long time to process data ... |
| 56 | + return processed_data |
| 57 | +
|
| 58 | +The registered pickled path are saved in "~/.pickler_conf.yaml". This allow to run the same code |
| 59 | +on different systems with differents path, as long as the corresponding path have been registered |
| 60 | +in their respective configuration path. |
| 61 | + |
| 62 | + |
| 63 | +Why the 2 in Piclker2? |
| 64 | +=================================== |
| 65 | +Because Pickler was already taken on PyPi! |
| 66 | + |
| 67 | +Licensing |
| 68 | +^^^^^^^^^ |
| 69 | + |
| 70 | +Pickler2 is **BSD-licenced** (3 clause): |
| 71 | + |
| 72 | + This software is OSI Certified Open Source Software. |
| 73 | + OSI Certified is a certification mark of the Open Source Initiative. |
| 74 | + |
| 75 | + Copyright (c) 2011-2019, authors of MNE-Python. |
| 76 | + All rights reserved. |
| 77 | + |
| 78 | + Redistribution and use in source and binary forms, with or without |
| 79 | + modification, are permitted provided that the following conditions are met: |
| 80 | + |
| 81 | + * Redistributions of source code must retain the above copyright notice, |
| 82 | + this list of conditions and the following disclaimer. |
| 83 | + |
| 84 | + * Redistributions in binary form must reproduce the above copyright notice, |
| 85 | + this list of conditions and the following disclaimer in the documentation |
| 86 | + and/or other materials provided with the distribution. |
| 87 | + |
| 88 | + * Neither the names of MNE-Python authors nor the names of any |
| 89 | + contributors may be used to endorse or promote products derived from |
| 90 | + this software without specific prior written permission. |
| 91 | + |
| 92 | + **This software is provided by the copyright holders and contributors |
| 93 | + "as is" and any express or implied warranties, including, but not |
| 94 | + limited to, the implied warranties of merchantability and fitness for |
| 95 | + a particular purpose are disclaimed. In no event shall the copyright |
| 96 | + owner or contributors be liable for any direct, indirect, incidental, |
| 97 | + special, exemplary, or consequential damages (including, but not |
| 98 | + limited to, procurement of substitute goods or services; loss of use, |
| 99 | + data, or profits; or business interruption) however caused and on any |
| 100 | + theory of liability, whether in contract, strict liability, or tort |
| 101 | + (including negligence or otherwise) arising in any way out of the use |
| 102 | + of this software, even if advised of the possibility of such |
| 103 | + damage.** |
0 commit comments