Skip to content
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
13 changes: 13 additions & 0 deletions src/license_expression/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,19 @@ def __init__(self, symbols=tuple(), quiet=True):

# FIXME: this should be instead a super class of all symbols
self.LicenseSymbol = self.Symbol
# LicenseWithExceptionSymbol does not get its internal Expressions mapped durring BooleanAlgebra init
# have to set it after the fact
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the solution could not be instead something about a better/different way to call super?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the better super call. originally that's what i was trying to do, but unless boolean is changed i don't think there is a way from what i can tell license-expression is a outlier with 2 symbol classes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah... Note that I maintain boolean too, so I could do it there, but that's indeed a weird thing, though may be the check should be for any symbol subclass somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry i didn't realize you were also the maintainer of boolean.

Yea in boolean if you could do the same thing for all sub classes of the passed in symbol class that should fix it.

Is this something you would prefer to do if not i can take a look at it myself when i get the chance.

right now i'm working around it by just patching the operators right after the import using the same code

tf_nao = {
    "TRUE": spdx_licensing.TRUE,
    "FALSE": spdx_licensing.FALSE,
    "NOT": spdx_licensing.NOT,
    "AND": spdx_licensing.AND,
    "OR": spdx_licensing.OR,
    "Symbol": spdx_licensing.Symbol,
}

for name, value in tf_nao.items():
    setattr(LicenseWithExceptionSymbol, name, value)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some tests if the plan is to fix this in boolean should be a good base.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It looks like the boolean.py code will need a good facelift to account for this.

tf_nao = {
"TRUE": self.TRUE,
"FALSE": self.FALSE,
"NOT": self.NOT,
"AND": self.AND,
"OR": self.OR,
"Symbol": self.Symbol,
}

for name, value in tf_nao.items():
setattr(LicenseWithExceptionSymbol, name, value)

symbols = symbols or tuple()

Expand Down
36 changes: 36 additions & 0 deletions tests/test_license_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,42 @@ def test_LicenseSymbol(self):
# symbol euqality is based ONLY on the key
assert sym5 == sym6

def test_python_operators_simple(self):
licensing = Licensing()

sym1 = LicenseSymbol('MIT')
sym2 = LicenseSymbol('BSD-2')

assert sym1 & sym2 == licensing.AND(sym1, sym2)
assert sym1 | sym2 == licensing.OR(sym1, sym2)

sym3 = LicenseWithExceptionSymbol(LicenseSymbol("GPL-3.0-or-later"), LicenseSymbol("GCC-exception-3.1"))

# Make sure LicenseWithExceptionSymbol operation work on left and right side
assert sym3 & sym1 == licensing.AND(sym3, sym1)
assert sym1 & sym3 == licensing.AND(sym1, sym3)
assert sym3 | sym1 == licensing.OR(sym3, sym1)
assert sym1 | sym3 == licensing.OR(sym3, sym1)

def test_boolean_expression_operators(self):

# Make sure LicenseWithExceptionSymbol boolean expression are set
assert LicenseWithExceptionSymbol.Symbol is not None
assert LicenseWithExceptionSymbol.TRUE is not None
assert LicenseWithExceptionSymbol.FALSE is not None
assert LicenseWithExceptionSymbol.AND is not None
assert LicenseWithExceptionSymbol.OR is not None
assert LicenseWithExceptionSymbol.NOT is not None

# Make sure LicenseWithExceptionSymbol matches LicenseSymbol
assert LicenseWithExceptionSymbol.Symbol == LicenseSymbol
assert LicenseWithExceptionSymbol.TRUE == LicenseSymbol.TRUE
assert LicenseWithExceptionSymbol.FALSE == LicenseSymbol.FALSE
assert LicenseWithExceptionSymbol.AND == LicenseSymbol.AND
assert LicenseWithExceptionSymbol.OR == LicenseSymbol.OR
assert LicenseWithExceptionSymbol.NOT == LicenseSymbol.NOT



class LicensingTest(TestCase):

Expand Down