METADATA 3.8 KB

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