Skip to content

Commit d62352f

Browse files
committed
Relax licence restrictions to support custom licences
This change adds support of use of custom licenses for projects. If the value specified for `licence` is not in the SPDX License List or "Proprietary", we treat it as a custom licence withe value (as is) as the name. As a side-effect, the validation of licence is no longer performed when executing `poetry check`. Resolves: python-poetry/poetry#2020
1 parent a2af0b7 commit d62352f

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

poetry/core/factory.py

-9
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,6 @@ def validate(
141141

142142
if strict:
143143
# If strict, check the file more thoroughly
144-
145-
# Checking license
146-
license = config.get("license")
147-
if license:
148-
try:
149-
license_by_id(license)
150-
except ValueError:
151-
result["errors"].append("{} is not a valid license".format(license))
152-
153144
if "dependencies" in config:
154145
python_versions = config["dependencies"]["python"]
155146
if python_versions == "*":

poetry/core/spdx/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def license_by_id(identifier):
1717
id = identifier.lower()
1818

1919
if id not in _licenses:
20-
raise ValueError("Invalid license id: {}".format(identifier))
20+
if not identifier:
21+
raise ValueError("A license identifier is required")
22+
return License(identifier, identifier, False, False)
2123

2224
return _licenses[id]
2325

tests/spdx/test_license.py

+6
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ def test_proprietary_license():
4848
license = license_by_id("Proprietary")
4949

5050
assert "License :: Other/Proprietary License" == license.classifier
51+
52+
53+
def test_custom_license():
54+
license = license_by_id("Amazon Software License")
55+
56+
assert "License :: Other/Proprietary License" == license.classifier

tests/spdx/test_main.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,13 @@ def test_license_by_id_with_full_name():
4040

4141
def test_license_by_id_invalid():
4242
with pytest.raises(ValueError):
43-
license_by_id("invalid")
43+
license_by_id("")
44+
45+
46+
def test_license_by_id_custom():
47+
license = license_by_id("Custom")
48+
49+
assert license.id == "Custom"
50+
assert license.name == "Custom"
51+
assert not license.is_osi_approved
52+
assert not license.is_deprecated

0 commit comments

Comments
 (0)