license-utils-kit 0.1a0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. license_utils_kit-0.1a0/LICENSE.txt +24 -0
  2. license_utils_kit-0.1a0/MANIFEST.in +5 -0
  3. license_utils_kit-0.1a0/PKG-INFO +224 -0
  4. license_utils_kit-0.1a0/README.rst +187 -0
  5. license_utils_kit-0.1a0/license_utils_kit.egg-info/PKG-INFO +224 -0
  6. license_utils_kit-0.1a0/license_utils_kit.egg-info/SOURCES.txt +47 -0
  7. license_utils_kit-0.1a0/license_utils_kit.egg-info/dependency_links.txt +1 -0
  8. license_utils_kit-0.1a0/license_utils_kit.egg-info/requires.txt +1 -0
  9. license_utils_kit-0.1a0/license_utils_kit.egg-info/top_level.txt +1 -0
  10. license_utils_kit-0.1a0/licenseutils/__init__.py +4 -0
  11. license_utils_kit-0.1a0/licenseutils/base.py +96 -0
  12. license_utils_kit-0.1a0/licenseutils/core.py +123 -0
  13. license_utils_kit-0.1a0/licenseutils/custom.py +243 -0
  14. license_utils_kit-0.1a0/licenseutils/licenses.py +152 -0
  15. license_utils_kit-0.1a0/licenseutils/templates/AGPL-3.0 +661 -0
  16. license_utils_kit-0.1a0/licenseutils/templates/AGPL-3.0+ +661 -0
  17. license_utils_kit-0.1a0/licenseutils/templates/AGPL-3.0+__header +14 -0
  18. license_utils_kit-0.1a0/licenseutils/templates/AGPL-3.0__header +13 -0
  19. license_utils_kit-0.1a0/licenseutils/templates/Apache-1.0 +45 -0
  20. license_utils_kit-0.1a0/licenseutils/templates/Apache-1.1 +45 -0
  21. license_utils_kit-0.1a0/licenseutils/templates/Apache-2.0 +201 -0
  22. license_utils_kit-0.1a0/licenseutils/templates/Apache-2.0__header +13 -0
  23. license_utils_kit-0.1a0/licenseutils/templates/BSD-2-Clause +22 -0
  24. license_utils_kit-0.1a0/licenseutils/templates/BSD-3-Clause +24 -0
  25. license_utils_kit-0.1a0/licenseutils/templates/GPL-2.0 +339 -0
  26. license_utils_kit-0.1a0/licenseutils/templates/GPL-2.0+ +339 -0
  27. license_utils_kit-0.1a0/licenseutils/templates/GPL-2.0+__header +15 -0
  28. license_utils_kit-0.1a0/licenseutils/templates/GPL-2.0__header +14 -0
  29. license_utils_kit-0.1a0/licenseutils/templates/GPL-3.0 +674 -0
  30. license_utils_kit-0.1a0/licenseutils/templates/GPL-3.0+ +674 -0
  31. license_utils_kit-0.1a0/licenseutils/templates/GPL-3.0+__header +14 -0
  32. license_utils_kit-0.1a0/licenseutils/templates/GPL-3.0__header +13 -0
  33. license_utils_kit-0.1a0/licenseutils/templates/LGPL-2.1 +502 -0
  34. license_utils_kit-0.1a0/licenseutils/templates/LGPL-2.1+ +502 -0
  35. license_utils_kit-0.1a0/licenseutils/templates/LGPL-2.1+__header +15 -0
  36. license_utils_kit-0.1a0/licenseutils/templates/LGPL-2.1__header +15 -0
  37. license_utils_kit-0.1a0/licenseutils/templates/LGPL-3.0 +165 -0
  38. license_utils_kit-0.1a0/licenseutils/templates/LGPL-3.0+ +165 -0
  39. license_utils_kit-0.1a0/licenseutils/templates/LGPL-3.0+__header +14 -0
  40. license_utils_kit-0.1a0/licenseutils/templates/LGPL-3.0__header +13 -0
  41. license_utils_kit-0.1a0/licenseutils/templates/MIT +21 -0
  42. license_utils_kit-0.1a0/setup.cfg +4 -0
  43. license_utils_kit-0.1a0/setup.py +35 -0
  44. license_utils_kit-0.1a0/test/__init__.py +8 -0
  45. license_utils_kit-0.1a0/test/files/CUSTOM +1 -0
  46. license_utils_kit-0.1a0/test/test_base.py +109 -0
  47. license_utils_kit-0.1a0/test/test_db.py +155 -0
  48. license_utils_kit-0.1a0/test/test_render.py +49 -0
@@ -0,0 +1,24 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Red Hat, Inc.
4
+ Copyright (c) 2015 Miro Hrončok <miro@hroncok.cz>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ Provided license texts might have their own copyrights and restrictions
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ include README.rst
2
+ include LICENSE.txt
3
+ recursive-include licenseutils/templates *
4
+ recursive-include test *.py
5
+ recursive-include test/files *
@@ -0,0 +1,224 @@
1
+ Metadata-Version: 2.4
2
+ Name: license-utils-kit
3
+ Version: 0.1a0
4
+ Summary: Library that encapsulates free software licenses
5
+ Home-page: https://github.com/hroncok/licenseutils
6
+ Author: Miro Hrončok
7
+ Author-email: miro@hroncok.cz
8
+ License: MIT
9
+ Keywords: license-utils-kit
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: MacOS :: MacOS X
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: Implementation :: CPython
17
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
18
+ Classifier: Programming Language :: Python :: 2
19
+ Classifier: Programming Language :: Python :: 2.7
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.3
22
+ Classifier: Programming Language :: Python :: 3.4
23
+ Classifier: Programming Language :: Python :: 3.5
24
+ Classifier: Topic :: Software Development :: Libraries
25
+ License-File: LICENSE.txt
26
+ Requires-Dist: jinja2
27
+ Dynamic: author
28
+ Dynamic: author-email
29
+ Dynamic: classifier
30
+ Dynamic: description
31
+ Dynamic: home-page
32
+ Dynamic: keywords
33
+ Dynamic: license
34
+ Dynamic: license-file
35
+ Dynamic: requires-dist
36
+ Dynamic: summary
37
+
38
+ license
39
+ =======
40
+
41
+ .. image:: https://badge.fury.io/py/license.svg
42
+ :target: http://badge.fury.io/py/license
43
+
44
+ .. image:: http://img.shields.io/:license-mit-green.svg?style=flat
45
+ :target: http://opensource.org/licenses/MIT
46
+
47
+ .. image:: https://travis-ci.org/hroncok/license.png?branch=master
48
+ :target: https://travis-ci.org/hroncok/license
49
+
50
+ license is a Python library providing some metadata about common free software licenses, such as
51
+ GNU GPL, MIT and others. It is compatible with Python 3.3+ and legacy Python 2.7.
52
+
53
+ Basic usage
54
+ -----------
55
+
56
+ To get a license, you can use `SPDX license identifier <http://spdx.org/licenses/>`_:
57
+
58
+ .. code-block:: python
59
+
60
+ import license
61
+ mit = license.find('MIT')
62
+
63
+ Each license is a static class providing a few properties:
64
+
65
+ * ``id`` - the SPDX identifier
66
+ * ``name`` - a human readable name of the license
67
+ * ``rpm`` - `license identifier used in Fedora, RHEL and CentOS RPMs <https://fedoraproject.org/wiki/Licensing:Main#Good_Licenses>`_
68
+ * ``python`` - `PyPI classifier <https://pypi.python.org/pypi?%3Aaction=list_classifiers>`_
69
+ * ``url`` - link to a license description or website
70
+
71
+ .. code-block:: python
72
+
73
+ mit.python
74
+ 'License :: OSI Approved :: MIT License'
75
+
76
+ License classes also offer a static method ``render()`` that will output the entire license text.
77
+ Some variables have to be passed to it, usually ``name``, ``email`` and optional ``year``
78
+ (current year is used when omitted).
79
+
80
+ .. code-block:: python
81
+
82
+ mit.render(name='Petr Foo', email='petr@foo.org')
83
+ '''The MIT License (MIT)
84
+
85
+ Copyright (c) 2015 Petr Foo <petr@foo.org>
86
+
87
+ Permission is hereby granted... (snip)'''
88
+
89
+ Some licenses (such as the ones from GPL family) also have a header text, that's supposed to be
90
+ added to each source file. ``header()`` is used to render that, but be careful, if the license does
91
+ not use special header, ``AttributeError`` is risen.
92
+
93
+ .. code-block:: python
94
+
95
+ mit.header(name='Petr Foo', email='petr@foo.org')
96
+ AttributeError: The MIT license uses no header
97
+
98
+ If you want to search the licenses by some other key, you can:
99
+
100
+ .. code-block:: python
101
+
102
+ bsd = license.find_by_key('rpm', 'BSD')
103
+ bsd
104
+ [license.licenses.BSD3ClauseLicense, license.licenses.BSD2ClauseLicense]
105
+
106
+ ``bsd`` is now a list, because unlike SPDX identifiers, other keys might not always be unique. If
107
+ you only need the first license with such identifier, you can pass ``multiple=False`` to
108
+ ``find_by_key()``:
109
+
110
+ .. code-block:: python
111
+
112
+ bsd = license.find_by_key('rpm', 'BSD', multiple=False)
113
+ bsd
114
+ license.licenses.BSD3ClauseLicense
115
+
116
+ If such license is not found, you'll get ``KeyError`` instead, the same as with regular ``find()``.
117
+
118
+ In case you would like to perform a lot of searches by some key, you can build and index, which
119
+ should (in theory) make the searches faster (no measurements have been performed).
120
+
121
+ .. code-block:: python
122
+
123
+ license.build_index('rpm')
124
+
125
+ In case you want to get rid of an index, use ``license.delete_index(key)``. It is safe to call it
126
+ even if the index does not exist.
127
+
128
+ It is also possible to use ``find_by_function()`` to find licenses that match a certain expression.
129
+ The function should accept one argument (the license class) and return True if the license is
130
+ supposed to be in the results:
131
+
132
+ .. code-block:: python
133
+
134
+ osi = license.find_by_function(lambda l: l.python.startswith('License :: OSI Approved :: '))
135
+
136
+ Again, it returns a list and has ``multiple`` argument to change that.
137
+
138
+ In case a simple function is not enough, you can iterate over all the license with
139
+ ``license.iter()``:
140
+
141
+ .. code-block:: python
142
+
143
+ for cls in license.iter():
144
+ # do something
145
+
146
+ Adding licenses
147
+ ---------------
148
+
149
+ The current license list is in no way much extensive, so maybe your favorite license is not in
150
+ there. If you wish to change that, add the license to ``license/licenses.py`` and a template(s) to
151
+ ``license/templates``, and send a `pull request on GitHub
152
+ <https://github.com/hroncok/license/pulls>`_. See the current licenses to learn how to do it.
153
+ A license class looks like this:
154
+
155
+ .. code-block:: python
156
+
157
+ class AGPLv3LaterLicense(license.base.License):
158
+ '''
159
+ GNU Affero General Public License v3.0 or later
160
+ '''
161
+ id = 'AGPL-3.0+'
162
+ rpm = 'AGPLv3+'
163
+ python = 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)'
164
+ url = 'http://www.gnu.org/licenses/agpl-3.0.html'
165
+
166
+ One license can inherit from other and omit the keys that are equal. Note that the docstring is
167
+ important and it is used as ``name`` property. License template is named as ``id``, header template
168
+ is named with ``__header`` suffix.
169
+
170
+ If you wish to add custom licenses in your code, you can do that as well. If you won't use
171
+ ``render()`` or ``header()``, the thing is simple. Just define such class anywhere and call
172
+ ``license.register()`` on it.
173
+
174
+ However, if you would then call ``render()`` or ``header()``, the template would hove not been
175
+ found. In that case, you have to create a *Custom Base License* with a ``jinja2`` template loader.
176
+
177
+ .. code-block:: python
178
+
179
+ CustomBaseLicense = license.base.custom_license_base_class(loader=jinja2.FileSystemLoader('path/to/templates'))
180
+
181
+ class CustomLicense(CustomBaseLicense):
182
+ ...
183
+
184
+ license.register(CustomLicense)
185
+
186
+ The ``loader`` can be any valid `jinja2 loader <http://jinja.pocoo.org/docs/dev/api/#loaders>`_.
187
+ If you wish to register multiple classes at once, you can use ``license.autoregister()`` that will
188
+ register all classes present in given module. You will not want to register your
189
+ ``CustomBaseLicense``, so you'll pass it in the ``ignore`` argument.
190
+
191
+ .. code-block:: python
192
+
193
+ license.autoregister(sys.modules[__name__], ignore=[CustomBaseLicense])
194
+
195
+ Note that if you add custom licenses and use ``license.build_index()``, you want to build the index
196
+ after registering them. Calling ``build_index()`` multiple times is safe.
197
+
198
+ (Possibly) Frequently Asked Questions
199
+ -------------------------------------
200
+
201
+ Why are licenses represented as subclasses and not instances of ``License``?
202
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
+
204
+ This way, it is easier to inherit data between multiple licenses. The definition of classes is
205
+ easier maintainable and readable.
206
+
207
+ Isn't ``license`` a reserved name?
208
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
209
+
210
+ Yes, it is, it prints the Python's license. Possibly something you would only use in an interactive
211
+ Python console. By importing this library, you are overriding it. We could have named the library
212
+ with something cool and unique, such as ``licenraptor``, but we wanted to make the name as easy as
213
+ possible. In case you don't like this, you can always do ``import license as somethignelse``.
214
+
215
+ Aren't there already Python tools that can render license texts?
216
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217
+
218
+ Yes, they are. However all of them are command line utilities and provide no API for Python
219
+ programmers.
220
+
221
+ * `choosealicense-cli <https://pypi.python.org/pypi/choosealicense-cli>`_
222
+ * `licenser <https://pypi.python.org/pypi/licenser>`_
223
+ * `licen <https://pypi.python.org/pypi/licen>`_
224
+ * `garnish <https://pypi.python.org/pypi/garnish>`_
@@ -0,0 +1,187 @@
1
+ license
2
+ =======
3
+
4
+ .. image:: https://badge.fury.io/py/license.svg
5
+ :target: http://badge.fury.io/py/license
6
+
7
+ .. image:: http://img.shields.io/:license-mit-green.svg?style=flat
8
+ :target: http://opensource.org/licenses/MIT
9
+
10
+ .. image:: https://travis-ci.org/hroncok/license.png?branch=master
11
+ :target: https://travis-ci.org/hroncok/license
12
+
13
+ license is a Python library providing some metadata about common free software licenses, such as
14
+ GNU GPL, MIT and others. It is compatible with Python 3.3+ and legacy Python 2.7.
15
+
16
+ Basic usage
17
+ -----------
18
+
19
+ To get a license, you can use `SPDX license identifier <http://spdx.org/licenses/>`_:
20
+
21
+ .. code-block:: python
22
+
23
+ import license
24
+ mit = license.find('MIT')
25
+
26
+ Each license is a static class providing a few properties:
27
+
28
+ * ``id`` - the SPDX identifier
29
+ * ``name`` - a human readable name of the license
30
+ * ``rpm`` - `license identifier used in Fedora, RHEL and CentOS RPMs <https://fedoraproject.org/wiki/Licensing:Main#Good_Licenses>`_
31
+ * ``python`` - `PyPI classifier <https://pypi.python.org/pypi?%3Aaction=list_classifiers>`_
32
+ * ``url`` - link to a license description or website
33
+
34
+ .. code-block:: python
35
+
36
+ mit.python
37
+ 'License :: OSI Approved :: MIT License'
38
+
39
+ License classes also offer a static method ``render()`` that will output the entire license text.
40
+ Some variables have to be passed to it, usually ``name``, ``email`` and optional ``year``
41
+ (current year is used when omitted).
42
+
43
+ .. code-block:: python
44
+
45
+ mit.render(name='Petr Foo', email='petr@foo.org')
46
+ '''The MIT License (MIT)
47
+
48
+ Copyright (c) 2015 Petr Foo <petr@foo.org>
49
+
50
+ Permission is hereby granted... (snip)'''
51
+
52
+ Some licenses (such as the ones from GPL family) also have a header text, that's supposed to be
53
+ added to each source file. ``header()`` is used to render that, but be careful, if the license does
54
+ not use special header, ``AttributeError`` is risen.
55
+
56
+ .. code-block:: python
57
+
58
+ mit.header(name='Petr Foo', email='petr@foo.org')
59
+ AttributeError: The MIT license uses no header
60
+
61
+ If you want to search the licenses by some other key, you can:
62
+
63
+ .. code-block:: python
64
+
65
+ bsd = license.find_by_key('rpm', 'BSD')
66
+ bsd
67
+ [license.licenses.BSD3ClauseLicense, license.licenses.BSD2ClauseLicense]
68
+
69
+ ``bsd`` is now a list, because unlike SPDX identifiers, other keys might not always be unique. If
70
+ you only need the first license with such identifier, you can pass ``multiple=False`` to
71
+ ``find_by_key()``:
72
+
73
+ .. code-block:: python
74
+
75
+ bsd = license.find_by_key('rpm', 'BSD', multiple=False)
76
+ bsd
77
+ license.licenses.BSD3ClauseLicense
78
+
79
+ If such license is not found, you'll get ``KeyError`` instead, the same as with regular ``find()``.
80
+
81
+ In case you would like to perform a lot of searches by some key, you can build and index, which
82
+ should (in theory) make the searches faster (no measurements have been performed).
83
+
84
+ .. code-block:: python
85
+
86
+ license.build_index('rpm')
87
+
88
+ In case you want to get rid of an index, use ``license.delete_index(key)``. It is safe to call it
89
+ even if the index does not exist.
90
+
91
+ It is also possible to use ``find_by_function()`` to find licenses that match a certain expression.
92
+ The function should accept one argument (the license class) and return True if the license is
93
+ supposed to be in the results:
94
+
95
+ .. code-block:: python
96
+
97
+ osi = license.find_by_function(lambda l: l.python.startswith('License :: OSI Approved :: '))
98
+
99
+ Again, it returns a list and has ``multiple`` argument to change that.
100
+
101
+ In case a simple function is not enough, you can iterate over all the license with
102
+ ``license.iter()``:
103
+
104
+ .. code-block:: python
105
+
106
+ for cls in license.iter():
107
+ # do something
108
+
109
+ Adding licenses
110
+ ---------------
111
+
112
+ The current license list is in no way much extensive, so maybe your favorite license is not in
113
+ there. If you wish to change that, add the license to ``license/licenses.py`` and a template(s) to
114
+ ``license/templates``, and send a `pull request on GitHub
115
+ <https://github.com/hroncok/license/pulls>`_. See the current licenses to learn how to do it.
116
+ A license class looks like this:
117
+
118
+ .. code-block:: python
119
+
120
+ class AGPLv3LaterLicense(license.base.License):
121
+ '''
122
+ GNU Affero General Public License v3.0 or later
123
+ '''
124
+ id = 'AGPL-3.0+'
125
+ rpm = 'AGPLv3+'
126
+ python = 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)'
127
+ url = 'http://www.gnu.org/licenses/agpl-3.0.html'
128
+
129
+ One license can inherit from other and omit the keys that are equal. Note that the docstring is
130
+ important and it is used as ``name`` property. License template is named as ``id``, header template
131
+ is named with ``__header`` suffix.
132
+
133
+ If you wish to add custom licenses in your code, you can do that as well. If you won't use
134
+ ``render()`` or ``header()``, the thing is simple. Just define such class anywhere and call
135
+ ``license.register()`` on it.
136
+
137
+ However, if you would then call ``render()`` or ``header()``, the template would hove not been
138
+ found. In that case, you have to create a *Custom Base License* with a ``jinja2`` template loader.
139
+
140
+ .. code-block:: python
141
+
142
+ CustomBaseLicense = license.base.custom_license_base_class(loader=jinja2.FileSystemLoader('path/to/templates'))
143
+
144
+ class CustomLicense(CustomBaseLicense):
145
+ ...
146
+
147
+ license.register(CustomLicense)
148
+
149
+ The ``loader`` can be any valid `jinja2 loader <http://jinja.pocoo.org/docs/dev/api/#loaders>`_.
150
+ If you wish to register multiple classes at once, you can use ``license.autoregister()`` that will
151
+ register all classes present in given module. You will not want to register your
152
+ ``CustomBaseLicense``, so you'll pass it in the ``ignore`` argument.
153
+
154
+ .. code-block:: python
155
+
156
+ license.autoregister(sys.modules[__name__], ignore=[CustomBaseLicense])
157
+
158
+ Note that if you add custom licenses and use ``license.build_index()``, you want to build the index
159
+ after registering them. Calling ``build_index()`` multiple times is safe.
160
+
161
+ (Possibly) Frequently Asked Questions
162
+ -------------------------------------
163
+
164
+ Why are licenses represented as subclasses and not instances of ``License``?
165
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
166
+
167
+ This way, it is easier to inherit data between multiple licenses. The definition of classes is
168
+ easier maintainable and readable.
169
+
170
+ Isn't ``license`` a reserved name?
171
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172
+
173
+ Yes, it is, it prints the Python's license. Possibly something you would only use in an interactive
174
+ Python console. By importing this library, you are overriding it. We could have named the library
175
+ with something cool and unique, such as ``licenraptor``, but we wanted to make the name as easy as
176
+ possible. In case you don't like this, you can always do ``import license as somethignelse``.
177
+
178
+ Aren't there already Python tools that can render license texts?
179
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180
+
181
+ Yes, they are. However all of them are command line utilities and provide no API for Python
182
+ programmers.
183
+
184
+ * `choosealicense-cli <https://pypi.python.org/pypi/choosealicense-cli>`_
185
+ * `licenser <https://pypi.python.org/pypi/licenser>`_
186
+ * `licen <https://pypi.python.org/pypi/licen>`_
187
+ * `garnish <https://pypi.python.org/pypi/garnish>`_
@@ -0,0 +1,224 @@
1
+ Metadata-Version: 2.4
2
+ Name: license-utils-kit
3
+ Version: 0.1a0
4
+ Summary: Library that encapsulates free software licenses
5
+ Home-page: https://github.com/hroncok/licenseutils
6
+ Author: Miro Hrončok
7
+ Author-email: miro@hroncok.cz
8
+ License: MIT
9
+ Keywords: license-utils-kit
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: MacOS :: MacOS X
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: Implementation :: CPython
17
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
18
+ Classifier: Programming Language :: Python :: 2
19
+ Classifier: Programming Language :: Python :: 2.7
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.3
22
+ Classifier: Programming Language :: Python :: 3.4
23
+ Classifier: Programming Language :: Python :: 3.5
24
+ Classifier: Topic :: Software Development :: Libraries
25
+ License-File: LICENSE.txt
26
+ Requires-Dist: jinja2
27
+ Dynamic: author
28
+ Dynamic: author-email
29
+ Dynamic: classifier
30
+ Dynamic: description
31
+ Dynamic: home-page
32
+ Dynamic: keywords
33
+ Dynamic: license
34
+ Dynamic: license-file
35
+ Dynamic: requires-dist
36
+ Dynamic: summary
37
+
38
+ license
39
+ =======
40
+
41
+ .. image:: https://badge.fury.io/py/license.svg
42
+ :target: http://badge.fury.io/py/license
43
+
44
+ .. image:: http://img.shields.io/:license-mit-green.svg?style=flat
45
+ :target: http://opensource.org/licenses/MIT
46
+
47
+ .. image:: https://travis-ci.org/hroncok/license.png?branch=master
48
+ :target: https://travis-ci.org/hroncok/license
49
+
50
+ license is a Python library providing some metadata about common free software licenses, such as
51
+ GNU GPL, MIT and others. It is compatible with Python 3.3+ and legacy Python 2.7.
52
+
53
+ Basic usage
54
+ -----------
55
+
56
+ To get a license, you can use `SPDX license identifier <http://spdx.org/licenses/>`_:
57
+
58
+ .. code-block:: python
59
+
60
+ import license
61
+ mit = license.find('MIT')
62
+
63
+ Each license is a static class providing a few properties:
64
+
65
+ * ``id`` - the SPDX identifier
66
+ * ``name`` - a human readable name of the license
67
+ * ``rpm`` - `license identifier used in Fedora, RHEL and CentOS RPMs <https://fedoraproject.org/wiki/Licensing:Main#Good_Licenses>`_
68
+ * ``python`` - `PyPI classifier <https://pypi.python.org/pypi?%3Aaction=list_classifiers>`_
69
+ * ``url`` - link to a license description or website
70
+
71
+ .. code-block:: python
72
+
73
+ mit.python
74
+ 'License :: OSI Approved :: MIT License'
75
+
76
+ License classes also offer a static method ``render()`` that will output the entire license text.
77
+ Some variables have to be passed to it, usually ``name``, ``email`` and optional ``year``
78
+ (current year is used when omitted).
79
+
80
+ .. code-block:: python
81
+
82
+ mit.render(name='Petr Foo', email='petr@foo.org')
83
+ '''The MIT License (MIT)
84
+
85
+ Copyright (c) 2015 Petr Foo <petr@foo.org>
86
+
87
+ Permission is hereby granted... (snip)'''
88
+
89
+ Some licenses (such as the ones from GPL family) also have a header text, that's supposed to be
90
+ added to each source file. ``header()`` is used to render that, but be careful, if the license does
91
+ not use special header, ``AttributeError`` is risen.
92
+
93
+ .. code-block:: python
94
+
95
+ mit.header(name='Petr Foo', email='petr@foo.org')
96
+ AttributeError: The MIT license uses no header
97
+
98
+ If you want to search the licenses by some other key, you can:
99
+
100
+ .. code-block:: python
101
+
102
+ bsd = license.find_by_key('rpm', 'BSD')
103
+ bsd
104
+ [license.licenses.BSD3ClauseLicense, license.licenses.BSD2ClauseLicense]
105
+
106
+ ``bsd`` is now a list, because unlike SPDX identifiers, other keys might not always be unique. If
107
+ you only need the first license with such identifier, you can pass ``multiple=False`` to
108
+ ``find_by_key()``:
109
+
110
+ .. code-block:: python
111
+
112
+ bsd = license.find_by_key('rpm', 'BSD', multiple=False)
113
+ bsd
114
+ license.licenses.BSD3ClauseLicense
115
+
116
+ If such license is not found, you'll get ``KeyError`` instead, the same as with regular ``find()``.
117
+
118
+ In case you would like to perform a lot of searches by some key, you can build and index, which
119
+ should (in theory) make the searches faster (no measurements have been performed).
120
+
121
+ .. code-block:: python
122
+
123
+ license.build_index('rpm')
124
+
125
+ In case you want to get rid of an index, use ``license.delete_index(key)``. It is safe to call it
126
+ even if the index does not exist.
127
+
128
+ It is also possible to use ``find_by_function()`` to find licenses that match a certain expression.
129
+ The function should accept one argument (the license class) and return True if the license is
130
+ supposed to be in the results:
131
+
132
+ .. code-block:: python
133
+
134
+ osi = license.find_by_function(lambda l: l.python.startswith('License :: OSI Approved :: '))
135
+
136
+ Again, it returns a list and has ``multiple`` argument to change that.
137
+
138
+ In case a simple function is not enough, you can iterate over all the license with
139
+ ``license.iter()``:
140
+
141
+ .. code-block:: python
142
+
143
+ for cls in license.iter():
144
+ # do something
145
+
146
+ Adding licenses
147
+ ---------------
148
+
149
+ The current license list is in no way much extensive, so maybe your favorite license is not in
150
+ there. If you wish to change that, add the license to ``license/licenses.py`` and a template(s) to
151
+ ``license/templates``, and send a `pull request on GitHub
152
+ <https://github.com/hroncok/license/pulls>`_. See the current licenses to learn how to do it.
153
+ A license class looks like this:
154
+
155
+ .. code-block:: python
156
+
157
+ class AGPLv3LaterLicense(license.base.License):
158
+ '''
159
+ GNU Affero General Public License v3.0 or later
160
+ '''
161
+ id = 'AGPL-3.0+'
162
+ rpm = 'AGPLv3+'
163
+ python = 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)'
164
+ url = 'http://www.gnu.org/licenses/agpl-3.0.html'
165
+
166
+ One license can inherit from other and omit the keys that are equal. Note that the docstring is
167
+ important and it is used as ``name`` property. License template is named as ``id``, header template
168
+ is named with ``__header`` suffix.
169
+
170
+ If you wish to add custom licenses in your code, you can do that as well. If you won't use
171
+ ``render()`` or ``header()``, the thing is simple. Just define such class anywhere and call
172
+ ``license.register()`` on it.
173
+
174
+ However, if you would then call ``render()`` or ``header()``, the template would hove not been
175
+ found. In that case, you have to create a *Custom Base License* with a ``jinja2`` template loader.
176
+
177
+ .. code-block:: python
178
+
179
+ CustomBaseLicense = license.base.custom_license_base_class(loader=jinja2.FileSystemLoader('path/to/templates'))
180
+
181
+ class CustomLicense(CustomBaseLicense):
182
+ ...
183
+
184
+ license.register(CustomLicense)
185
+
186
+ The ``loader`` can be any valid `jinja2 loader <http://jinja.pocoo.org/docs/dev/api/#loaders>`_.
187
+ If you wish to register multiple classes at once, you can use ``license.autoregister()`` that will
188
+ register all classes present in given module. You will not want to register your
189
+ ``CustomBaseLicense``, so you'll pass it in the ``ignore`` argument.
190
+
191
+ .. code-block:: python
192
+
193
+ license.autoregister(sys.modules[__name__], ignore=[CustomBaseLicense])
194
+
195
+ Note that if you add custom licenses and use ``license.build_index()``, you want to build the index
196
+ after registering them. Calling ``build_index()`` multiple times is safe.
197
+
198
+ (Possibly) Frequently Asked Questions
199
+ -------------------------------------
200
+
201
+ Why are licenses represented as subclasses and not instances of ``License``?
202
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
+
204
+ This way, it is easier to inherit data between multiple licenses. The definition of classes is
205
+ easier maintainable and readable.
206
+
207
+ Isn't ``license`` a reserved name?
208
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
209
+
210
+ Yes, it is, it prints the Python's license. Possibly something you would only use in an interactive
211
+ Python console. By importing this library, you are overriding it. We could have named the library
212
+ with something cool and unique, such as ``licenraptor``, but we wanted to make the name as easy as
213
+ possible. In case you don't like this, you can always do ``import license as somethignelse``.
214
+
215
+ Aren't there already Python tools that can render license texts?
216
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217
+
218
+ Yes, they are. However all of them are command line utilities and provide no API for Python
219
+ programmers.
220
+
221
+ * `choosealicense-cli <https://pypi.python.org/pypi/choosealicense-cli>`_
222
+ * `licenser <https://pypi.python.org/pypi/licenser>`_
223
+ * `licen <https://pypi.python.org/pypi/licen>`_
224
+ * `garnish <https://pypi.python.org/pypi/garnish>`_