Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax licence restrictions to support custom licences #5

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,6 @@ def validate(

if strict:
# If strict, check the file more thoroughly

# Checking license
license = config.get("license")
if license:
try:
license_by_id(license)
except ValueError:
result["errors"].append("{} is not a valid license".format(license))

if "dependencies" in config:
python_versions = config["dependencies"]["python"]
if python_versions == "*":
Expand Down
4 changes: 3 additions & 1 deletion poetry/core/spdx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def license_by_id(identifier):
id = identifier.lower()

if id not in _licenses:
raise ValueError("Invalid license id: {}".format(identifier))
if not identifier:
raise ValueError("A license identifier is required")
return License(identifier, identifier, False, False)

return _licenses[id]

Expand Down
Empty file added tests/spdx/__init__.py
Empty file.
56 changes: 56 additions & 0 deletions tests/spdx/test_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from poetry.core.spdx import license_by_id


def test_classifier_name():
license = license_by_id("lgpl-3.0-or-later")

assert (
license.classifier_name
== "GNU Lesser General Public License v3 or later (LGPLv3+)"
)


def test_classifier_name_no_classifer_osi_approved():
license = license_by_id("LiLiQ-R-1.1")

assert license.classifier_name is None


def test_classifier_name_no_classifer():
license = license_by_id("Leptonica")

assert license.classifier_name == "Other/Proprietary License"


def test_classifier():
license = license_by_id("lgpl-3.0-or-later")

assert license.classifier == (
"License :: "
"OSI Approved :: "
"GNU Lesser General Public License v3 or later (LGPLv3+)"
)


def test_classifier_no_classifer_osi_approved():
license = license_by_id("LiLiQ-R-1.1")

assert license.classifier == "License :: OSI Approved"


def test_classifier_no_classifer():
license = license_by_id("Leptonica")

assert license.classifier == "License :: Other/Proprietary License"


def test_proprietary_license():
license = license_by_id("Proprietary")

assert "License :: Other/Proprietary License" == license.classifier


def test_custom_license():
license = license_by_id("Amazon Software License")

assert "License :: Other/Proprietary License" == license.classifier
52 changes: 52 additions & 0 deletions tests/spdx/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest

from poetry.core.spdx import license_by_id


def test_license_by_id():
license = license_by_id("MIT")

assert license.id == "MIT"
assert license.name == "MIT License"
assert license.is_osi_approved
assert not license.is_deprecated

license = license_by_id("LGPL-3.0-or-later")

assert license.id == "LGPL-3.0-or-later"
assert license.name == "GNU Lesser General Public License v3.0 or later"
assert license.is_osi_approved
assert not license.is_deprecated


def test_license_by_id_is_case_insensitive():
license = license_by_id("mit")

assert license.id == "MIT"

license = license_by_id("miT")

assert license.id == "MIT"


def test_license_by_id_with_full_name():
license = license_by_id("GNU Lesser General Public License v3.0 or later")

assert license.id == "LGPL-3.0-or-later"
assert license.name == "GNU Lesser General Public License v3.0 or later"
assert license.is_osi_approved
assert not license.is_deprecated


def test_license_by_id_invalid():
with pytest.raises(ValueError):
license_by_id("")


def test_license_by_id_custom():
license = license_by_id("Custom")

assert license.id == "Custom"
assert license.name == "Custom"
assert not license.is_osi_approved
assert not license.is_deprecated