METADATA 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. Metadata-Version: 2.1
  2. Name: decorator
  3. Version: 4.4.2
  4. Summary: Decorators for Humans
  5. Home-page: https://github.com/micheles/decorator
  6. Author: Michele Simionato
  7. Author-email: michele.simionato@gmail.com
  8. License: new BSD License
  9. Keywords: decorators generic utility
  10. Platform: All
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: Intended Audience :: Developers
  13. Classifier: License :: OSI Approved :: BSD License
  14. Classifier: Natural Language :: English
  15. Classifier: Operating System :: OS Independent
  16. Classifier: Programming Language :: Python
  17. Classifier: Programming Language :: Python :: 2
  18. Classifier: Programming Language :: Python :: 2.6
  19. Classifier: Programming Language :: Python :: 2.7
  20. Classifier: Programming Language :: Python :: 3
  21. Classifier: Programming Language :: Python :: 3.2
  22. Classifier: Programming Language :: Python :: 3.3
  23. Classifier: Programming Language :: Python :: 3.4
  24. Classifier: Programming Language :: Python :: 3.5
  25. Classifier: Programming Language :: Python :: 3.6
  26. Classifier: Programming Language :: Python :: 3.7
  27. Classifier: Programming Language :: Python :: Implementation :: CPython
  28. Classifier: Topic :: Software Development :: Libraries
  29. Classifier: Topic :: Utilities
  30. Requires-Python: >=2.6, !=3.0.*, !=3.1.*
  31. Decorators for Humans
  32. =====================
  33. The goal of the decorator module is to make it easy to define
  34. signature-preserving function decorators and decorator factories.
  35. It also includes an implementation of multiple dispatch and other niceties
  36. (please check the docs). It is released under a two-clauses
  37. BSD license, i.e. basically you can do whatever you want with it but I am not
  38. responsible.
  39. Installation
  40. -------------
  41. If you are lazy, just perform
  42. ``$ pip install decorator``
  43. which will install just the module on your system.
  44. If you prefer to install the full distribution from source, including
  45. the documentation, clone the `GitHub repo`_ or download the tarball_, unpack it and run
  46. ``$ pip install .``
  47. in the main directory, possibly as superuser.
  48. .. _tarball: https://pypi.org/project/decorator/#files
  49. .. _GitHub repo: https://github.com/micheles/decorator
  50. Testing
  51. --------
  52. If you have the source code installation you can run the tests with
  53. `$ python src/tests/test.py -v`
  54. or (if you have setuptools installed)
  55. `$ python setup.py test`
  56. Notice that you may run into trouble if in your system there
  57. is an older version of the decorator module; in such a case remove the
  58. old version. It is safe even to copy the module `decorator.py` over
  59. an existing one, since we kept backward-compatibility for a long time.
  60. Repository
  61. ---------------
  62. The project is hosted on GitHub. You can look at the source here:
  63. https://github.com/micheles/decorator
  64. Documentation
  65. ---------------
  66. The documentation has been moved to https://github.com/micheles/decorator/blob/master/docs/documentation.md
  67. From there you can get a PDF version by simply using the print
  68. functionality of your browser.
  69. Here is the documentation for previous versions of the module:
  70. https://github.com/micheles/decorator/blob/4.3.2/docs/tests.documentation.rst
  71. https://github.com/micheles/decorator/blob/4.2.1/docs/tests.documentation.rst
  72. https://github.com/micheles/decorator/blob/4.1.2/docs/tests.documentation.rst
  73. https://github.com/micheles/decorator/blob/4.0.0/documentation.rst
  74. https://github.com/micheles/decorator/blob/3.4.2/documentation.rst
  75. For the impatient
  76. -----------------
  77. Here is an example of how to define a family of decorators tracing slow
  78. operations:
  79. .. code-block:: python
  80. from decorator import decorator
  81. @decorator
  82. def warn_slow(func, timelimit=60, *args, **kw):
  83. t0 = time.time()
  84. result = func(*args, **kw)
  85. dt = time.time() - t0
  86. if dt > timelimit:
  87. logging.warn('%s took %d seconds', func.__name__, dt)
  88. else:
  89. logging.info('%s took %d seconds', func.__name__, dt)
  90. return result
  91. @warn_slow # warn if it takes more than 1 minute
  92. def preprocess_input_files(inputdir, tempdir):
  93. ...
  94. @warn_slow(timelimit=600) # warn if it takes more than 10 minutes
  95. def run_calculation(tempdir, outdir):
  96. ...
  97. Enjoy!