File: licenses.rst

package info (click to toggle)
python-packaging 25.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,716 kB
  • sloc: python: 8,071; makefile: 130; sh: 35
file content (52 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Licenses
=========

.. currentmodule:: packaging.licenses


Helper for canonicalizing SPDX
`License-Expression metadata <https://peps.python.org/pep-0639/#term-license-expression>`__
as `defined in PEP 639 <https://peps.python.org/pep-0639/#spdx>`__.


Reference
---------

.. class:: NormalizedLicenseExpression

    A :class:`typing.NewType` of :class:`str`, representing a normalized
    License-Expression.


.. exception:: InvalidLicenseExpression

    Raised when a License-Expression is invalid.


.. function:: canonicalize_license_expression(raw_license_expression)

    This function takes a valid License-Expression, and returns the normalized form of it.

    The return type is typed as :class:`NormalizedLicenseExpression`. This allows type
    checkers to help require that a string has passed through this function
    before use.

    :param str raw_license_expression: The License-Expression to canonicalize.
    :raises InvalidLicenseExpression: If the License-Expression is invalid due to an
        invalid/unknown license identifier or invalid syntax.

    .. doctest::

        >>> from packaging.licenses import canonicalize_license_expression
        >>> canonicalize_license_expression("mit")
        'MIT'
        >>> canonicalize_license_expression("mit and (apache-2.0 or bsd-2-clause)")
        'MIT AND (Apache-2.0 OR BSD-2-Clause)'
        >>> canonicalize_license_expression("(mit")
        Traceback (most recent call last):
          ...
        InvalidLicenseExpression: Invalid license expression: '(mit'
        >>> canonicalize_license_expression("Use-it-after-midnight")
        Traceback (most recent call last):
          ...
        InvalidLicenseExpression: Unknown license: 'Use-it-after-midnight'