Skip to content

Commit

Permalink
Reports: License report improvements
Browse files Browse the repository at this point in the history
* Only put license text block if we find the text.

* In cases of "UNKNOWN" license, discover it from the classifiers instead.

* When a distribution includes package names different from its name,
  output them to make them recognizable.
  • Loading branch information
kayhayen committed Feb 7, 2023
1 parent f11a136 commit 577d3bd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
10 changes: 8 additions & 2 deletions nuitka/reports/LicenseReport.rst.j2
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ This software was compiled with Nuitka and contains parts of the following softw
===================================

Version {{ distribution.metadata["Version"] }} of {{ distribution.metadata["Name"] }} was included and is
under license {{ distribution.metadata["License"] }}.
under license "{{ get_distribution_license(distribution) }}".

{% if distribution_modules[distribution] != [distribution.metadata["Name"]] %}
The contained {{"packages are" if len(distribution_modules[distribution]) > 1 else "package is"}} {{" ,".join(quoted(distribution_modules[distribution]))}}.
{% endif %}

{% if distribution.read_text("LICENSE.txt") %}
.. code::

{{ (distribution.read_text("LICENSE.txt") or "") | indent(4, True) }}
{{ distribution.read_text("LICENSE.txt") | indent(4, True) }}
{% endif %}

{% endfor %}
51 changes: 46 additions & 5 deletions nuitka/reports/Reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sys

from nuitka import TreeXML
from nuitka.containers.OrderedSets import OrderedSet
from nuitka.freezer.IncludedDataFiles import getIncludedDataFiles
from nuitka.freezer.IncludedEntryPoints import getStandaloneEntryPoints
from nuitka.importing.Importing import getPackageSearchPath
Expand Down Expand Up @@ -71,10 +72,17 @@ def _getReportInputData():
for module in getDoneModules()
)

module_distributions = dict(
(module.getFullName(), getDistributionsFromModuleName(module.getFullName()))
for module in getDoneModules()
)
module_distributions = {}
distribution_modules = {}
for module in getDoneModules():
module_distributions[module.getFullName()] = getDistributionsFromModuleName(
module.getFullName()
)
for _distribution in module_distributions[module.getFullName()]:
if _distribution not in distribution_modules:
distribution_modules[_distribution] = OrderedSet()

distribution_modules[_distribution].add(module.getFullName())

module_usages = dict(
(module.getFullName(), module.getUsedModules()) for module in getDoneModules()
Expand Down Expand Up @@ -286,7 +294,40 @@ def writeCompilationReportFromTemplate(
extensions=("jinja2.ext.do",),
)

report_text = template.render(**report_input_data)
def get_distribution_license(distribution):
license_name = distribution.metadata["License"]

if license_name == "UNKNOWN":
for classifier in (
value
for (key, value) in distribution.metadata.items()
if "Classifier" in key
):
parts = [part.strip() for part in classifier.split("::")]
if not parts:
continue

if parts[0] == "License":
license_name = parts[-1]
break

return license_name

def quoted(value):
if isinstance(value, str):
return "'%s'" % value
else:
return [quoted(element) for element in value]

report_text = template.render(
# Get the license text.
get_distribution_license=get_distribution_license,
# Quote a list of strings.
quoted=quoted,
# For checking length of lists.
len=len,
**report_input_data
)

try:
putTextFileContents(filename=report_filename, contents=report_text)
Expand Down

0 comments on commit 577d3bd

Please sign in to comment.