Skip to content

Commit 095c8ed

Browse files
Update docs for external licenses
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent f201faa commit 095c8ed

11 files changed

+216
-103
lines changed

docs/source/cli-reference/core-options.rst

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -69,74 +69,6 @@ Comparing Progress Message Options
6969

7070
----
7171

72-
``--reindex-licenses`` Option
73-
-----------------------------
74-
75-
ScanCode maintains a license index to search for and detect licenses. When Scancode is
76-
configured for the first time, a license index is built and used in every scan thereafter.
77-
78-
This ``--reindex-licenses`` option rebuilds the license index. Running a scan with this option
79-
displays the following message to the terminal in addition to what it normally shows::
80-
81-
Checking and rebuilding the license index...
82-
83-
..
84-
[ToDo] Research and Write Better
85-
86-
``--additional-license-directory`` Option
87-
-----------------------------------------
88-
89-
.. admonition:: Dependency
90-
91-
The option ``--additional-license-directory`` requires the option ``-reindex--licenses``.
92-
93-
The ``--additional-license-directory`` option allows the user to include additional directories
94-
of licenses to use in license detection.
95-
96-
This command only needs to be run once for each set of additional directories; in all subsequent
97-
runs of Scancode with the same directories all the licenses in the directories will be cached.
98-
99-
The directory structure should look something like this::
100-
101-
licenses/
102-
├── privateLicense1/
103-
│ ├── license/
104-
│ │ ├── privateLicense1.LICENSE
105-
│ │ └── privateLicense1.yml
106-
│ └── rule/
107-
│ ├── privateLicense1.RULE
108-
│ └── privateLicense1.yml
109-
└── privateLicense2/
110-
├── license/
111-
│ ├── privateLicense2.LICENSE
112-
│ └── privateLicense2.yml
113-
└── rule/
114-
├── privateLicense2.RULE
115-
└── privateLicense2.yml
116-
117-
Here is an example of reindexing the license cache using the ``--additional-license-directory PATH`` option with a single directory.
118-
Note that ``--reindex-licenses`` **must** come after ``--additional-license-directory``::
119-
120-
scancode --additional-license-directory /home/user/external_licenses/license1 --reindex-licenses
121-
122-
You can also include multiple directories like so::
123-
124-
scancode --additional-license-directory /home/user/external_licenses/external1 --additional-license-directory /home/user/external_licenses/external2 --reindex-licenses
125-
126-
If you want to continue running scans with ``/home/user/external_licenses/external1`` and ``/home/user/external_licenses/external2``,
127-
you can simply run scans after reindexing with those directories and they will be included. ::
128-
129-
scancode -clpieu --json-pp output.json samples
130-
131-
However, if you wanted to run a scan with a new set of directories, such as ``home/user/external_licenses/external1``
132-
and ``home/user/external_licenses/external3``, you would need to reindex the license index with those directories as parameters. ::
133-
134-
scancode --additional-license-directory /home/user/external_licenses/external1 --additional-license-directory /home/user/external_licenses/external3 --reindex-licenses
135-
136-
..
137-
138-
----
139-
14072
``--from-json`` Option
14173
----------------------
14274

docs/source/cli-reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
help-text-options
99
list-options
1010
simple-examples
11+
other-commands
1112
basic-options
1213
core-options
1314
output-format

docs/source/cli-reference/list-options.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ available in the command line.
3030

3131
----
3232

33+
.. include:: /rst_snippets/scancode-reindex-licenses.rst
34+
35+
----
36+
3337
.. include:: /rst_snippets/core_options.rst
3438

3539
----
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
Other available CLIs
2+
====================
3+
4+
.. _other_cli:
5+
6+
----
7+
8+
.. include:: /rst_snippets/scancode-reindex-licenses.rst
9+
10+
----
11+
12+
.. include:: /rst_snippets/extract.rst
13+
14+
----
15+
16+
``scancode-reindex-licenses`` command
17+
-------------------------------------
18+
19+
ScanCode maintains a license index to search for and detect licenses. When Scancode is
20+
configured for the first time, a license index is built and used in every scan thereafter.
21+
22+
This ``scancode-reindex-licenses`` command rebuilds the license index. Running this command
23+
displays the following message to the terminal::
24+
25+
Checking and rebuilding the license index...
26+
27+
This has several CLI options as follows:
28+
29+
``--additional-directory`` Option:
30+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
32+
The ``--additional-directory`` option allows the user to include additional directories
33+
of licenses to use in license detection.
34+
35+
This command only needs to be run once for each set of additional directories, in all subsequent
36+
runs of Scancode with the same directories all the licenses in the directories will be cached
37+
and used in License detection. But reindexing removes these directories, if they aren't
38+
reintroduced as additional directories.
39+
40+
The directory structure should look something like this::
41+
42+
additional_license_directory/
43+
├── licenses/
44+
│ ├── example-installed-1.LICENSE
45+
│ └── example-installed-1.yaml
46+
├── rules/
47+
│ ├── example-installed-1.RULE
48+
│ └── example-installed-1.yaml
49+
50+
Here is an example of reindexing the license cache using the ``--additional-directory PATH`` option
51+
with a single directory::
52+
53+
scancode-reindex-licenses --additional-directory tests/licensedcode/data/additional_licenses/additional_dir/
54+
55+
You can also include multiple directories like so::
56+
57+
scancode-reindex-licenses --additional-directory /home/user/external_licenses/external1 --additional-directory /home/user/external_licenses/external2
58+
59+
If you want to continue running scans with ``/home/user/external_licenses/external1`` and
60+
``/home/user/external_licenses/external2``, you can simply run scans after the command above
61+
reindexing with those directories and they will be included. ::
62+
63+
scancode -l --license-text --json-pp output.json samples
64+
65+
However, if you wanted to run a scan with a new set of directories, such as
66+
``home/user/external_licenses/external1`` and ``home/user/external_licenses/external3``, you would
67+
need to reindex the license index with those directories as parameters::
68+
69+
scancode --additional-directory /home/user/external_licenses/external1 --additional-directory /home/user/external_licenses/external3
70+
71+
.. include:: /rst_snippets/note_snippets/additional_directory_is_temp.rst
72+
73+
74+
.. note::
75+
76+
You can also install external licenses through a plugin for
77+
better reproducibility and distribution of those license/rules
78+
for use in conjunction with scancode-toolkit licenses.
79+
See :ref:`install_new_license_plugin`
80+
81+
82+
``--only-builtin`` Option:
83+
^^^^^^^^^^^^^^^^^^^^^^^^^^
84+
85+
Rebuild the license index excluding any additional license directory or additional
86+
license plugins which were added previously, i.e. with only builtin scancode license and rules.
87+
88+
This is applicable when there are additional license plugins installed already and you want to
89+
reindex the licenses without these licenses from the additional plugins.
90+
91+
.. note::
92+
93+
Running the ``--only-builtin`` command won't get rid of the installed license plugins, it
94+
would just reindex without the licenses from these plugins for once. Another reindex afterwards
95+
without this option would bring back the licenses from the plugins again in the index.
96+
97+
98+
``--all-languages`` Option:
99+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
100+
101+
Rebuild the license index including texts all languages (and not only
102+
English) and exit. This is an EXPERIMENTAL option.

docs/source/how-to-guides/install_new_license_plugin.rst

Lines changed: 70 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
.. _install_new_license_plugin:
1+
.. _install_external_licenses:
2+
3+
How to Install External Licenses to Use in License Detection
4+
============================================================
25

3-
How to Install External License Plugins to Use in License Detection
4-
===================================================================
6+
Users can install external licenses and rules in the form of:
57

6-
Users can install external licenses and rules in the form of plugins. These
7-
licenses and rules are then used in license detection.
8+
1. reusable plugins
9+
2. license directories
810

9-
How to create a plugin containing external licenses and/or rules
10-
----------------------------------------------------------------
11+
These licenses and rules are then used in license detection.
12+
13+
.. _install_new_license_plugin:
14+
15+
How to install a plugin containing external licenses and/or rules
16+
-----------------------------------------------------------------
1117

1218
To create a plugin with external licenses or rules, we must create a Python package
1319
containing the license and/or rule files. Python packages can have many different
14-
file structures. You can find an example package in
15-
``tests/licensedcode/data/example_external_licenses/licenses_to_install1``.
20+
file structures. You can find an example package in:
21+
22+
``tests/licensedcode/data/additional_licenses/additional_plugin_1``.
1623

1724
This is the basic structure of the example plugin::
1825

@@ -26,14 +33,11 @@ This is the basic structure of the example plugin::
2633
│ │ ├── example-installed-1.RULE
2734
│ │ └── example-installed-1.yaml
2835
│ └── __init__.py
29-
├── gpl-1.0.LICENSE
36+
├── apache-2.0.LICENSE
3037
├── MANIFEST.in
3138
├── setup.cfg
3239
└── setup.py
3340

34-
Key points to note
35-
------------------
36-
3741
Entry points definition in ``setup.py``
3842
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3943

@@ -75,18 +79,27 @@ After creating this plugin, you can upload it to PyPI so that others can use it,
7579
leave it as a local directory.
7680

7781
Installing and using the plugin
78-
-------------------------------
79-
To use the plugin in license detection, all you need to do is install it using ``pip``.
82+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
83+
84+
To use the plugin in license detection, all you need to do is:
85+
86+
1. Configure the scancode-toolkit virtualenv and activate.
87+
2. Install the package with `pip` like the following:
88+
``pip install tests/licensedcode/data/additional_licenses/additional_plugin_2/``
89+
3. Reindex licenses using `scancode-reindex-licenses`.
90+
91+
.. include:: /rst_snippets/note_snippets/license_plugin_needs_reindex.rst
92+
8093
Once it is installed, the contained licenses and rules will automatically be used in
8194
license detection assuming the plugin follows the correct directory structure conventions.
8295

8396
Writing tests for new installed licenses
84-
----------------------------------------
97+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8598

8699
Look at ``tests/licensedcode/data/example_external_licenses/licenses_to_install1`` to see
87100
an example of a plugin with tests. The tests are contained in the ``tests`` directory::
88101

89-
licenses_to_install1/
102+
licenses_to_install1/
90103
├── src/
91104
│ └── licenses_to_install1/
92105
│ ├── licenses/
@@ -132,8 +145,44 @@ Then you can define a test class and call the ``build_tests`` method defined in
132145
The ``tests/data`` directory contains a pair of files for each license:
133146
a license text file and a YAML file specifying the expected license expressions from the test.
134147

135-
Finally, to run the test, do the following:
148+
Finally, install the plugin and run the test:
149+
150+
``pytest -vvs tests/test_detection_datadriven.py``.
151+
152+
.. include:: /rst_snippets/note_snippets/license_plugin_delete.rst
153+
154+
----
155+
156+
.. _add_new_license_directory:
157+
158+
How to add external licenses and/or rules from a directory
159+
----------------------------------------------------------
160+
161+
This is the basic structure of the example license directory::
162+
163+
additional_license_directory/
164+
├── licenses/
165+
│ ├── example-installed-1.LICENSE
166+
│ └── example-installed-1.yaml
167+
├── rules/
168+
│ ├── example-installed-1.RULE
169+
│ └── example-installed-1.yaml
170+
171+
Adding the licenses to the index
172+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
173+
174+
To add the licenses in the directory to the index, all you need to do is:
175+
176+
1. Configure the scancode-toolkit virtualenv and activate.
177+
2. Run ``scancode-reindex-licenses`` with:
178+
179+
``--additional-directory tests/licensedcode/data/additional_licenses/additional_dir/``
180+
181+
.. include:: /rst_snippets/note_snippets/additional_directory_is_temp.rst
182+
183+
184+
Once the licenses/rules are in the index, they will automatically be used in license detection.
185+
186+
----
136187

137-
1. Create a virtual environment to install the package into.
138-
2. Install the package using ``pip``, e.g. ``pip install ./licenses_to_install1``.
139-
3. Run the tests, e.g. ``py.test tests/test_detection_datadriven.py``.
188+
.. include:: /rst_snippets/scancode-reindex-licenses.rst

docs/source/rst_snippets/core_options.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ All "Core" Scan Options
1111
--timeout FLOAT Stop scanning a file if scanning takes longer
1212
than a timeout in seconds. [Default: 120]
1313

14-
--reindex-licenses Force a check and possible reindexing of the
15-
cached license index.
16-
17-
--additional-license-directory PATH
18-
19-
Include paths to directories containing additional licenses and rules to use
20-
in license detection. This can be used multiple times for multiple directories.
21-
2214
--from-json Load codebase from an existing JSON scan
2315

2416
--max-in-memory INTEGER Maximum number of files and directories scan
@@ -33,5 +25,3 @@ All "Core" Scan Options
3325
including and below the starting point. INTEGER
3426
must be positive or zero for no limit.
3527
[Default: 0]
36-
37-
.. include:: /rst_snippets/note_snippets/core_indep.rst
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. note::
2+
3+
Adding licenses/rules from an additional directory is not permanent.
4+
Another reindexing without the additional directory option would
5+
just use the builtin scancode licenses and rules, and will not have
6+
these additonal licenses/rules anymore.

docs/source/rst_snippets/note_snippets/core_indep.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. note::
2+
3+
Once you install a external license plugin, you have to reconfigure
4+
scancode-toolkit (or use pip uninstall) to uninstall the plugin to
5+
completely remove it. Otherwise using the --only-builtin option only
6+
regenerates the index without the installed plugins, but another Reindex
7+
would have the licenses/rules from the installed plugins.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. note::
2+
3+
Installing the plugin will not add the licenses/rules to the
4+
index automatically, they will be indexed only after running
5+
`scancode-reindex-licenses`.

0 commit comments

Comments
 (0)