Skip to content

Commit 655d8e9

Browse files
authored
Also look in static for license files (#238)
1 parent dac0a55 commit 655d8e9

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

jupyterlab_server/licenses_handler.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ class LicensesManager(LoggingConfigurable):
3838

3939
third_party_licenses_files = List(
4040
Unicode(),
41-
default_value=[DEFAULT_THIRD_PARTY_LICENSE_FILE],
41+
default_value=[
42+
DEFAULT_THIRD_PARTY_LICENSE_FILE,
43+
f"static/{DEFAULT_THIRD_PARTY_LICENSE_FILE}"
44+
],
4245
help="the license report data in built app and federated extensions",
4346
)
4447

@@ -156,14 +159,13 @@ def report_markdown(self, bundles, full_text=True):
156159
def license_bundle(self, path, bundle):
157160
"""Return the content of a packages's license bundles"""
158161
bundle_json = {"packages": []}
162+
checked_paths = []
159163

160164
for license_file in self.third_party_licenses_files:
161165
licenses_path = path / license_file
162166
self.log.debug("Loading licenses from %s", licenses_path)
163167
if not licenses_path.exists():
164-
self.log.warning(
165-
"Third-party licenses not found for %s: %s", bundle, licenses_path
166-
)
168+
checked_paths += [licenses_path]
167169
continue
168170

169171
try:
@@ -188,6 +190,11 @@ def license_bundle(self, path, bundle):
188190
)
189191
continue
190192

193+
if not bundle_json["packages"]:
194+
self.log.warning(
195+
"Third-party licenses not found for %s: %s", bundle, checked_paths
196+
)
197+
191198
return bundle_json
192199

193200
def app_static_info(self):
@@ -222,7 +229,7 @@ def bundles(self, bundles_pattern=".*"):
222229
bundles[app_name] = self.license_bundle(app_path, app_name)
223230

224231
if not bundles:
225-
self.log.warn("No license bundles found at all")
232+
self.log.warning("No license bundles found at all")
226233

227234
return bundles
228235

jupyterlab_server/tests/test_licenses_api.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import mistune
1010

1111
from .. import LicensesApp
12-
from ..licenses_handler import DEFAULT_THIRD_PARTY_LICENSE_FILE
12+
from ..licenses_handler import DEFAULT_THIRD_PARTY_LICENSE_FILE, LicensesManager
1313

1414
# utilities
1515

@@ -166,3 +166,33 @@ async def test_licenses_cli(licenses_app, capsys, mime_format_parser):
166166

167167
captured = capsys.readouterr()
168168
assert parse(captured.out) is not None
169+
170+
171+
@pytest.fixture
172+
def a_fake_labextension(tmp_path):
173+
"""just enough of an extension to be parsed"""
174+
ext_name = "@an-org/an-extension"
175+
ext_path = tmp_path / ext_name
176+
package_data = {"name": ext_name}
177+
bundle_data = {"packages": [dict(FULL_ENTRY)]}
178+
179+
package_json = ext_path / "package.json"
180+
third_party_licenses = ext_path / "static" / DEFAULT_THIRD_PARTY_LICENSE_FILE
181+
182+
third_party_licenses.parent.mkdir(parents=True)
183+
184+
package_json.write_text(json.dumps(package_data), encoding="utf-8")
185+
third_party_licenses.write_text(json.dumps(bundle_data), encoding="utf-8")
186+
187+
yield ext_path, ext_name
188+
189+
190+
@pytest.fixture
191+
def a_licenses_manager():
192+
yield LicensesManager()
193+
194+
195+
def test_labextension_bundle(a_fake_labextension, a_licenses_manager):
196+
ext_path, ext_name = a_fake_labextension
197+
bundle = a_licenses_manager.license_bundle(ext_path, ext_name)
198+
assert bundle["packages"][0]["name"] == dict(FULL_ENTRY)["name"]

0 commit comments

Comments
 (0)