METADATA 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. Metadata-Version: 2.1
  2. Name: traitlets
  3. Version: 5.14.1
  4. Summary: Traitlets Python configuration system
  5. Project-URL: Homepage, https://github.com/ipython/traitlets
  6. Project-URL: Documentation, https://traitlets.readthedocs.io
  7. Project-URL: Source, https://github.com/ipython/traitlets
  8. Project-URL: Funding, https://numfocus.org
  9. Project-URL: Tracker, https://github.com/ipython/traitlets/issues
  10. Author-email: IPython Development Team <ipython-dev@python.org>
  11. License: BSD 3-Clause License
  12. - Copyright (c) 2001-, IPython Development Team
  13. All rights reserved.
  14. Redistribution and use in source and binary forms, with or without
  15. modification, are permitted provided that the following conditions are met:
  16. 1. Redistributions of source code must retain the above copyright notice, this
  17. list of conditions and the following disclaimer.
  18. 2. Redistributions in binary form must reproduce the above copyright notice,
  19. this list of conditions and the following disclaimer in the documentation
  20. and/or other materials provided with the distribution.
  21. 3. Neither the name of the copyright holder nor the names of its
  22. contributors may be used to endorse or promote products derived from
  23. this software without specific prior written permission.
  24. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. License-File: LICENSE
  35. Keywords: Interactive,Interpreter,Shell,Web
  36. Classifier: Framework :: IPython
  37. Classifier: Framework :: Jupyter
  38. Classifier: Intended Audience :: Developers
  39. Classifier: Intended Audience :: Science/Research
  40. Classifier: Intended Audience :: System Administrators
  41. Classifier: License :: OSI Approved :: BSD License
  42. Classifier: Programming Language :: Python
  43. Classifier: Programming Language :: Python :: 3
  44. Classifier: Typing :: Typed
  45. Requires-Python: >=3.8
  46. Provides-Extra: docs
  47. Requires-Dist: myst-parser; extra == 'docs'
  48. Requires-Dist: pydata-sphinx-theme; extra == 'docs'
  49. Requires-Dist: sphinx; extra == 'docs'
  50. Provides-Extra: test
  51. Requires-Dist: argcomplete>=3.0.3; extra == 'test'
  52. Requires-Dist: mypy>=1.7.0; extra == 'test'
  53. Requires-Dist: pre-commit; extra == 'test'
  54. Requires-Dist: pytest-mock; extra == 'test'
  55. Requires-Dist: pytest-mypy-testing; extra == 'test'
  56. Requires-Dist: pytest<7.5,>=7.0; extra == 'test'
  57. Description-Content-Type: text/markdown
  58. # Traitlets
  59. [![Tests](https://github.com/ipython/traitlets/actions/workflows/tests.yml/badge.svg)](https://github.com/ipython/traitlets/actions/workflows/tests.yml)
  60. [![Documentation Status](https://readthedocs.org/projects/traitlets/badge/?version=latest)](https://traitlets.readthedocs.io/en/latest/?badge=latest)
  61. [![Tidelift](https://tidelift.com/subscription/pkg/pypi-traitlets)](https://tidelift.com/badges/package/pypi/traitlets)
  62. | | |
  63. | ------------- | ------------------------------------ |
  64. | **home** | https://github.com/ipython/traitlets |
  65. | **pypi-repo** | https://pypi.org/project/traitlets/ |
  66. | **docs** | https://traitlets.readthedocs.io/ |
  67. | **license** | Modified BSD License |
  68. Traitlets is a pure Python library enabling:
  69. - the enforcement of strong typing for attributes of Python objects
  70. (typed attributes are called _"traits"_);
  71. - dynamically calculated default values;
  72. - automatic validation and coercion of trait attributes when attempting a
  73. change;
  74. - registering for receiving notifications when trait values change;
  75. - reading configuring values from files or from command line
  76. arguments - a distinct layer on top of traitlets, so you may use
  77. traitlets without the configuration machinery.
  78. Its implementation relies on the [descriptor](https://docs.python.org/howto/descriptor.html)
  79. pattern, and it is a lightweight pure-python alternative of the
  80. [_traits_ library](https://docs.enthought.com/traits/).
  81. Traitlets powers the configuration system of IPython and Jupyter
  82. and the declarative API of IPython interactive widgets.
  83. ## Installation
  84. For a local installation, make sure you have
  85. [pip installed](https://pip.pypa.io/en/stable/installing/) and run:
  86. ```bash
  87. pip install traitlets
  88. ```
  89. For a **development installation**, clone this repository, change into the
  90. `traitlets` root directory, and run pip:
  91. ```bash
  92. git clone https://github.com/ipython/traitlets.git
  93. cd traitlets
  94. pip install -e .
  95. ```
  96. ## Running the tests
  97. ```bash
  98. pip install "traitlets[test]"
  99. py.test traitlets
  100. ```
  101. ## Code Styling
  102. `traitlets` has adopted automatic code formatting so you shouldn't
  103. need to worry too much about your code style.
  104. As long as your code is valid,
  105. the pre-commit hook should take care of how it should look.
  106. To install `pre-commit` locally, run the following::
  107. ```
  108. pip install pre-commit
  109. pre-commit install
  110. ```
  111. You can invoke the pre-commit hook by hand at any time with::
  112. ```
  113. pre-commit run
  114. ```
  115. which should run any autoformatting on your code
  116. and tell you about any errors it couldn't fix automatically.
  117. You may also install [black integration](https://github.com/psf/black#editor-integration)
  118. into your text editor to format code automatically.
  119. If you have already committed files before setting up the pre-commit
  120. hook with `pre-commit install`, you can fix everything up using
  121. `pre-commit run --all-files`. You need to make the fixing commit
  122. yourself after that.
  123. Some of the hooks only run on CI by default, but you can invoke them by
  124. running with the `--hook-stage manual` argument.
  125. ## Usage
  126. Any class with trait attributes must inherit from `HasTraits`.
  127. For the list of available trait types and their properties, see the
  128. [Trait Types](https://traitlets.readthedocs.io/en/latest/trait_types.html)
  129. section of the documentation.
  130. ### Dynamic default values
  131. To calculate a default value dynamically, decorate a method of your class with
  132. `@default({traitname})`. This method will be called on the instance, and
  133. should return the default value. In this example, the `_username_default`
  134. method is decorated with `@default('username')`:
  135. ```Python
  136. import getpass
  137. from traitlets import HasTraits, Unicode, default
  138. class Identity(HasTraits):
  139. username = Unicode()
  140. @default('username')
  141. def _username_default(self):
  142. return getpass.getuser()
  143. ```
  144. ### Callbacks when a trait attribute changes
  145. When a trait changes, an application can follow this trait change with
  146. additional actions.
  147. To do something when a trait attribute is changed, decorate a method with
  148. [`traitlets.observe()`](https://traitlets.readthedocs.io/en/latest/api.html?highlight=observe#traitlets.observe).
  149. The method will be called with a single argument, a dictionary which contains
  150. an owner, new value, old value, name of the changed trait, and the event type.
  151. In this example, the `_num_changed` method is decorated with `` @observe(`num`) ``:
  152. ```Python
  153. from traitlets import HasTraits, Integer, observe
  154. class TraitletsExample(HasTraits):
  155. num = Integer(5, help="a number").tag(config=True)
  156. @observe('num')
  157. def _num_changed(self, change):
  158. print("{name} changed from {old} to {new}".format(**change))
  159. ```
  160. and is passed the following dictionary when called:
  161. ```Python
  162. {
  163. 'owner': object, # The HasTraits instance
  164. 'new': 6, # The new value
  165. 'old': 5, # The old value
  166. 'name': "foo", # The name of the changed trait
  167. 'type': 'change', # The event type of the notification, usually 'change'
  168. }
  169. ```
  170. ### Validation and coercion
  171. Each trait type (`Int`, `Unicode`, `Dict` etc.) may have its own validation or
  172. coercion logic. In addition, we can register custom cross-validators
  173. that may depend on the state of other attributes. For example:
  174. ```Python
  175. from traitlets import HasTraits, TraitError, Int, Bool, validate
  176. class Parity(HasTraits):
  177. value = Int()
  178. parity = Int()
  179. @validate('value')
  180. def _valid_value(self, proposal):
  181. if proposal['value'] % 2 != self.parity:
  182. raise TraitError('value and parity should be consistent')
  183. return proposal['value']
  184. @validate('parity')
  185. def _valid_parity(self, proposal):
  186. parity = proposal['value']
  187. if parity not in [0, 1]:
  188. raise TraitError('parity should be 0 or 1')
  189. if self.value % 2 != parity:
  190. raise TraitError('value and parity should be consistent')
  191. return proposal['value']
  192. parity_check = Parity(value=2)
  193. # Changing required parity and value together while holding cross validation
  194. with parity_check.hold_trait_notifications():
  195. parity_check.value = 1
  196. parity_check.parity = 1
  197. ```
  198. However, we **recommend** that custom cross-validators don't modify the state
  199. of the HasTraits instance.
  200. ## About the IPython Development Team
  201. The IPython Development Team is the set of all contributors to the IPython project.
  202. This includes all of the IPython subprojects.
  203. The core team that coordinates development on GitHub can be found here:
  204. https://github.com/jupyter/.
  205. ## Our Copyright Policy
  206. IPython uses a shared copyright model. Each contributor maintains copyright
  207. over their contributions to IPython. But, it is important to note that these
  208. contributions are typically only changes to the repositories. Thus, the IPython
  209. source code, in its entirety is not the copyright of any single person or
  210. institution. Instead, it is the collective copyright of the entire IPython
  211. Development Team. If individual contributors want to maintain a record of what
  212. changes/contributions they have specific copyright on, they should indicate
  213. their copyright in the commit message of the change, when they commit the
  214. change to one of the IPython repositories.
  215. With this in mind, the following banner should be used in any source code file
  216. to indicate the copyright and license terms:
  217. ```
  218. # Copyright (c) IPython Development Team.
  219. # Distributed under the terms of the Modified BSD License.
  220. ```