aboutcode-org / license-expression

Utility library to parse, normalize and compare License expressions for Python using a boolean logic engine. For expressions using SPDX or any other license id scheme.
http://aboutcode.org
Other
58 stars 24 forks source link

The order of the expression shouldn't be changed #62

Closed chinyeungli closed 3 years ago

chinyeungli commented 3 years ago
>>> from license_expression import Licensing, LicenseSymbol
>>> exp = 'mit or apache-2.0 or public-domain'
>>> licensing = Licensing().parse(exp)
>>> licensing.simplify().render()
'apache-2.0 OR mit OR public-domain'
>>>

Most of the time, the left most license key in the license expression is considered as the primary license (or primary license choice if both fall into the same license category). However, the simplify() break the order.

In my opinion, the simplify should not modify/break the order of a license_expression.

pombredanne commented 3 years ago

The new Licensing.dedup() (that you did contribute ;) ) does exactly that: a license-specific simplification without reordering.

chinyeungli commented 3 years ago

AH! I thought I did it but obviously forgotten. Need to look into the code to see if there is enough test for it.

chinyeungli commented 3 years ago
>>> licensing = Licensing()
>>> exp = 'mit or apache-2.0 or public-domain or apache-2.0'
>>> licensing.dedup(exp)
OR(LicenseSymbol('mit', is_exception=False), LicenseSymbol('apache-2.0', is_exception=False), LicenseSymbol('public-domain', is_exception=False))
>>> licensing.dedup(exp).render()
'mit OR apache-2.0 OR public-domain'
>>>

It's working 👯 and we have test for it. Closing it.