Added support for multi-licensed packages in library.json using SPDX Expressions // Resolve #4037

This commit is contained in:
Ivan Kravets
2022-04-02 14:19:24 +03:00
parent d86f7fc25e
commit feda42f18f
4 changed files with 37 additions and 7 deletions

View File

@ -24,11 +24,12 @@ PlatformIO Core 5
* `pio pkg uninstall <https://docs.platformio.org/en/latest/core/userguide/pkg/cmd_uninstall.html>`_ - uninstall the project dependencies or custom packages * `pio pkg uninstall <https://docs.platformio.org/en/latest/core/userguide/pkg/cmd_uninstall.html>`_ - uninstall the project dependencies or custom packages
* `pio pkg update <https://docs.platformio.org/en/latest/core/userguide/pkg/cmd_update.html>`__ - update the project dependencies or custom packages * `pio pkg update <https://docs.platformio.org/en/latest/core/userguide/pkg/cmd_update.html>`__ - update the project dependencies or custom packages
- Added support for multi-licensed packages in `library.json <https://docs.platformio.org/en/latest/librarymanager/config.html#license>`__ using SPDX Expressions (`issue #4037 <https://github.com/platformio/platformio-core/issues/4037>`_)
- Automatically install dependencies of the local (private) libraries (`issue #2910 <https://github.com/platformio/platformio-core/issues/2910>`_) - Automatically install dependencies of the local (private) libraries (`issue #2910 <https://github.com/platformio/platformio-core/issues/2910>`_)
- Added support for dependencies declared in a "tool" type package - Added support for dependencies declared in a "tool" type package
- Ignore files according to the patterns declared in ".gitignore" when using `pio package pack <https://docs.platformio.org/en/latest/core/userguide/pkg/cmd_pack.html>`__ command (`issue #4188 <https://github.com/platformio/platformio-core/issues/4188>`_) - Ignore files according to the patterns declared in ".gitignore" when using the `pio package pack <https://docs.platformio.org/en/latest/core/userguide/pkg/cmd_pack.html>`__ command (`issue #4188 <https://github.com/platformio/platformio-core/issues/4188>`_)
- Dropped automatic updates of global libraries and development platforms (`issue #4179 <https://github.com/platformio/platformio-core/issues/4179>`_) - Dropped automatic updates of global libraries and development platforms (`issue #4179 <https://github.com/platformio/platformio-core/issues/4179>`_)
- Dropped support for "pythonPackages" field in "platform.json" manifest in favor of `Extra Python Dependencies <https://docs.platformio.org/en/latest/scripting/examples/extra_python_packages.html>`__ - Dropped support for the "pythonPackages" field in "platform.json" manifest in favor of `Extra Python Dependencies <https://docs.platformio.org/en/latest/scripting/examples/extra_python_packages.html>`__
* **Static Code Analysis** * **Static Code Analysis**
@ -38,7 +39,7 @@ PlatformIO Core 5
* **Miscellaneous** * **Miscellaneous**
* Improved PIO Remote setup on credit-card sized computers (Raspberry Pi, BeagleBon, etc) (`issue #3865 <https://github.com/platformio/platformio-core/issues/3865>`_) * Improved PIO Remote setup on credit-card sized computers (Raspberry Pi, BeagleBon, etc) (`issue #3865 <https://github.com/platformio/platformio-core/issues/3865>`_)
* Better handling of the failed tests using `Unit Testing <https://docs.platformio.org/en/latest/plus/unit-testing.html>`__ solution * Better handling of the failed tests using the `Unit Testing <https://docs.platformio.org/en/latest/plus/unit-testing.html>`__ solution.
5.2.5 (2022-02-10) 5.2.5 (2022-02-10)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~

2
docs

Submodule docs updated: b953caefb7...1e6df4bb83

View File

@ -15,6 +15,7 @@
# pylint: disable=too-many-ancestors # pylint: disable=too-many-ancestors
import json import json
import re
import marshmallow import marshmallow
import requests import requests
@ -254,8 +255,17 @@ class ManifestSchema(BaseSchema):
spdx = self.load_spdx_licenses() spdx = self.load_spdx_licenses()
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
raise ValidationError("Could not load SPDX licenses for validation") raise ValidationError("Could not load SPDX licenses for validation")
for item in spdx.get("licenses", []): known_ids = set(item.get("licenseId") for item in spdx.get("licenses", []))
if item.get("licenseId") == value: if value in known_ids:
return True
# parse license expression
# https://spdx.github.io/spdx-spec/SPDX-license-expressions/
package_ids = [
item.strip()
for item in re.sub(r"(\s+(?:OR|AND|WITH)\s+|[\(\)])", " ", value).split(" ")
if item.strip()
]
if known_ids >= set(package_ids):
return True return True
raise ValidationError( raise ValidationError(
"Invalid SPDX license identifier. See valid identifiers at " "Invalid SPDX license identifier. See valid identifiers at "

View File

@ -426,6 +426,25 @@ def test_library_json_schema():
}, },
) )
# test multiple licenses
contents = """
{
"name": "MultiLicense",
"version": "1.0.0",
"license": "MIT AND (LGPL-2.1-or-later OR BSD-3-Clause)"
}
"""
raw_data = parser.LibraryJsonManifestParser(contents).as_dict()
data = ManifestSchema().load_manifest(raw_data)
assert not jsondiff.diff(
data,
{
"name": "MultiLicense",
"version": "1.0.0",
"license": "MIT AND (LGPL-2.1-or-later OR BSD-3-Clause)",
},
)
def test_library_properties_schema(): def test_library_properties_schema():
contents = """ contents = """