Skip to content

Commit

Permalink
Refactor external licenses code
Browse files Browse the repository at this point in the history
Refactor according to the feedback.

Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
  • Loading branch information
AyanSinhaMahapatra committed Oct 28, 2022
1 parent 095c8ed commit 54fb102
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ jobs:
--ignore=tests/licensedcode/test_detection_datadriven1.py \
--ignore=tests/licensedcode/test_detection_datadriven2.py \
--ignore=tests/licensedcode/test_detection_datadriven3.py \
--ignore=tests/licensedcode/test_detection_datadriven4.py
--ignore=tests/licensedcode/test_detection_datadriven4.py \
--ignore=tests/licensedcode/test_additional_license.py \
tests/licensedcode
license_datadriven1_2: |
venv/bin/pytest -n 3 -vvs --test-suite=all \
Expand Down
6 changes: 3 additions & 3 deletions src/licensedcode/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def load_or_build(
On the side, we load cached or build license db, SPDX symbols and other
license-related data structures.
- If the cache exists, it is returned unless corrupted, ``force`` is True, or if we pass in additional
directories containing licenses that are not present in the existing cache.
- If the cache does not exist, a new index is built and cached.
- If the cache exists, it is returned unless corrupted.
- If ``force`` is True, or if the cache does not exist a new index is built
and cached.
- If ``index_all_languages`` is True, include texts in all languages when
building the license index. Otherwise, only include the English license
texts and rules (the default)
Expand Down
2 changes: 2 additions & 0 deletions src/licensedcode/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ def write(location, byte_string):
if text:
write(self.text_file(licenses_data_dir=licenses_data_dir), text.encode('utf-8'))

return self

def load(self, data_file, text_file):
"""
Populate license data from a YAML file stored in ``data_file`` and ``text_file``.
Expand Down
2 changes: 1 addition & 1 deletion src/licensedcode/reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'--only-builtin',
is_flag=True,
help='Rebuild the license index excluding any additional '
'license directory or additional license plugins which'
'license directory or additional license plugins which '
'were added previously, i.e. with only builtin scancode '
'license and rules.',
conflicting_options=['additional_directory'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"files": [
{
"path": "license_url",
"path": "scan",
"type": "directory",
"licenses": [],
"license_expressions": [],
"percentage_of_license_text": 0,
"scan_errors": []
},
{
"path": "license_url/apache-1.0.txt",
"path": "scan/apache-1.0.txt",
"type": "file",
"licenses": [
{
Expand Down
4 changes: 2 additions & 2 deletions tests/licensedcode/test_plugin_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_reindex_licenses_works():

@pytest.mark.scanslow
def test_scan_license_with_url_template():
test_dir = test_env.get_test_loc('plugin_license/license_url', copy=True)
test_dir = test_env.get_test_loc('plugin_license/license_url/scan/', copy=True)
result_file = test_env.get_temp_file('json')
args = [
'--license',
Expand All @@ -254,7 +254,7 @@ def test_scan_license_with_url_template():
'--json-pp', result_file,
test_dir,
]
test_loc = test_env.get_test_loc('plugin_license/license_url.expected.json')
test_loc = test_env.get_test_loc('plugin_license/license_url/license_url.expected.json')
run_scan_click(args)
check_json_scan(test_loc, result_file, regen=REGEN_TEST_FIXTURES)

Expand Down

0 comments on commit 54fb102

Please sign in to comment.