Skip to content

Commit

Permalink
Relax licence restrictions to support custom licences
Browse files Browse the repository at this point in the history
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
  • Loading branch information
abn committed Apr 1, 2020
1 parent a2af0b7 commit d62352f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
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
6 changes: 6 additions & 0 deletions tests/spdx/test_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ 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
11 changes: 10 additions & 1 deletion tests/spdx/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ def test_license_by_id_with_full_name():

def test_license_by_id_invalid():
with pytest.raises(ValueError):
license_by_id("invalid")
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

0 comments on commit d62352f

Please sign in to comment.