Skip to content

Commit 46c1308

Browse files
committed
Fixed #329 template processing error
The problem was I "hard-coded" to treat only the `and` and `or` as the operator, but missing the `with`. Also, the previous implementation is incorrect. We are now using the correct `parse_license_expression()` function to get the license. Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 348b7da commit 46c1308

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/attributecode/attrib.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,28 @@ def generate(abouts, template_string=None):
7575

7676
# Convert/map the key in license expression to license name
7777
if about.license_expression.value and about.license_name.value:
78-
# Split the license expression into list with license key and condition keyword
79-
lic_expression_list = about.license_expression.value.split()
80-
81-
78+
special_char_in_expression, lic_list = parse_license_expression(about.license_expression.value)
8279
lic_name_list = about.license_name.value
8380
lic_name_expression_list = []
8481

8582
# The order of the license_name and key should be the same
86-
# The length for both list should be the same excluding the condition keyword
87-
# such as 'and' and 'or'
88-
assert len(lic_name_list) <= len(lic_expression_list)
83+
# The length for both list should be the same
84+
assert len(lic_name_list) == len(lic_list)
8985

90-
# Map the licence key to license name
86+
# Map the license key to license name
9187
index_for_license_name_list = 0
92-
for key in lic_expression_list:
93-
if key.lower() == 'and' or key.lower() == 'or':
94-
lic_name_expression_list.append(key)
88+
for key in lic_list:
89+
license_key_to_license_name[key] = lic_name_list[index_for_license_name_list]
90+
license_name_to_license_key[lic_name_list[index_for_license_name_list]] = key
91+
index_for_license_name_list = index_for_license_name_list + 1
92+
93+
# Create a license expression with license name instead of key
94+
for segment in about.license_expression.value.split():
95+
if segment in license_key_to_license_name:
96+
lic_name_expression_list.append(license_key_to_license_name[segment])
9597
else:
96-
lic_name_expression_list.append(lic_name_list[index_for_license_name_list])
97-
license_key_to_license_name[key] = lic_name_list[index_for_license_name_list]
98-
license_name_to_license_key[lic_name_list[index_for_license_name_list]] = key
99-
index_for_license_name_list = index_for_license_name_list + 1
98+
lic_name_expression_list.append(segment)
99+
100100
# Join the license name expression into a single string
101101
lic_name_expression = ' '.join(lic_name_expression_list)
102102

0 commit comments

Comments
 (0)