Skip to content

Commit 637ad9b

Browse files
Update How-to-Guides with license updates
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 1fd2a7f commit 637ad9b

3 files changed

Lines changed: 114 additions & 56 deletions

File tree

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

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,75 @@ How To Add a New License for Detection
66
How to add a new license for detection?
77
---------------------------------------
88

9-
To add new license, you first need to select a new and unique license key (mit
10-
and gpl-2.0 are some of the existing license keys). All licenses are stored as
11-
plain text files in the src/licensedcode/data/licenses directory using their key
12-
as base for the file name(s).
9+
To add new license, you first need to select a new and unique license `key` (mit
10+
and gpl-2.0 are some of the existing license keys).
1311

14-
You need to create a pair of files:
12+
The key name can contain only these symbols:
1513

16-
- a file with the text of the license saved in a plain text file named
17-
key.LICENSE
14+
- lowercase letters from a to z,
15+
- numbers from 0 to 9,and
16+
- dash - and . period signs. No spaces or underscore.
1817

19-
- a small text data file (in YAML format) named key.yml that contains license
20-
information such as::
18+
The license key also has to be less than 50 characters (same for `short_name`).
2119

22-
key: my-license
23-
name: My License
20+
We also have to add a `spdx_license_key` which is either a valid SPDX license key at
21+
` The SPDX license list <https://spdx.org/licenses/>`_, or a `Licenseref-scancode-<key>`.
2422

25-
The key name can contain only these symbols:
23+
All licenses are stored as a plain text file in the `src/licensedcode/data/licenses`
24+
directory using their key as base for the file name. I.e. the filename for a license
25+
with `key: mit` would be `mit.LICENSE`.
2626

27-
- lowercase letters from a to z,
28-
- numbers from 0 to 9,and
29-
- dash - and . period signs. No spaces.
27+
You need to create a file with:
28+
29+
- the text of the license saved in plain text. We usually get rid of HTML tags or
30+
other special characters, copyrights and only keep the original text as is,
31+
with the original formatting intact.
32+
33+
- the data attributes for the license in YAML format as YAML frontmatter.
34+
35+
See an example license: `apache-2.0.LICENSE <https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/apache-2.0.LICENSE>`_
36+
37+
There are a couple of mandatory attributes:
38+
39+
- `key`
40+
- `spdx_license_key`
41+
- `short_name`
42+
- `name`
43+
- `category` (Use "Unstated License" if not known)
44+
- `owner` (Use "Unspecified" if not known)
45+
46+
And more attributes which are not mandatory but nice to have always (if applicable):
47+
48+
- `other_spdx_license_keys`
49+
- `osi_license_key`
50+
- `minimum_coverage`
51+
- `standard_notice`
52+
- `notes`
53+
54+
We want to use `minimum_coverage` when there are other licenses which are very similar
55+
and we want to make sure we match correctly these licenses, and `notes` for interesting
56+
cases of licenses with descriptions to help identify origin, similarities to other licenses,
57+
notes about the SPDX keys and others.
58+
59+
Some URLs:
60+
61+
- `homepage_url`
62+
- `text_urls`
63+
- `osi_url`
64+
- `faq_url`
65+
- `other_urls`
66+
67+
Also attributes having ignorables in the license text:
68+
69+
- `ignorable_urls`
70+
- `ignorable_copyrights`
71+
- `ignorable_authors`
72+
- `ignorable_holders`
73+
- `ignorable_emails`
3074

31-
Save these two files in the ``src/licensedcode/data/licenses/`` directory.
75+
See the ``src/licensedcode/data/licenses/`` directory for many more examples.
3276

33-
Done!
77+
.. note::
3478

35-
See the ``src/licensedcode/data/licenses/`` directory for many examples.
79+
Add licenses in a local developement installation and run `scancode-reindex-licenses`
80+
to make sure we reindex the licenses and this validates the new licenses.

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

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,83 @@ How to Add New License Rules for Enhanced Detection
44
===================================================
55

66
ScanCode relies on license rules to detect licenses. A rule is a simple text
7-
file containing a license text or notice or mention; And a small companion YAML
8-
text file that tells ScanCode which license expression to report when the text
9-
is detected.
7+
file containing a license text or notice or mention with YAML frontmatter with data
8+
attributes that tells ScanCode which license expression to report when the text
9+
is detected, and other properties.
1010

11-
See the :ref:`faq` for a high level description of :ref:`add_new_license_det_rule`.
11+
See the :ref:`faq` for a high level description of adding license detection rules.
1212

1313
How to add a new license detection rule?
1414
----------------------------------------
1515

16-
A license detection rule is a pair of files:
16+
A license detection rule is a file with:
1717

18-
- a plain text rule file that is typically a variant of a license text, notice
19-
or license mention.
18+
- a plain text that is typically a variant of a license text, notice or license
19+
mention.
2020

21-
- a small text data file (in YAML format) documenting which license expression
22-
should be detected when the rule text is found in a codebase.
21+
- data as YAML frontmatter documenting license expression and other
22+
rule attributes.
2323

2424
To add a new rule, you need to pick a unique base file name. As a convention, we
2525
like to include the license expression that should be detected in that name to
2626
make it more descriptive. For example: mit_and_gpl-2.0 is a good base name for a
2727
rule that would detect an MIT and GPL-2.0 license combination at once. Add a
28-
suffix to make it unique if there is already a rule with this base name. Do not
29-
use spaces or special characters in that name.
28+
suffix (usually numeric) to make it unique if there is already a rule with
29+
this base name. Do not use spaces or special characters in that name.
3030

31-
Then create the rule file in the src/licensedcode/data/rules/ directory using
32-
this name, replacing selected_base_name with the base name you selected::
31+
Then create the rule file in the `src/licensedcode/data/rules/` directory using
32+
this name, for example a rule with `license_expression` as `mit AND apache-2.0`
33+
might have a filename: `mit_and_apache-2.0_10.RULE`.
3334

34-
selected_base_name.RULE
35+
Save your rule text in this file, if there are specific words like company names,
36+
projects or other, it is better to have rules with and without these so we have
37+
better detection.
3538

36-
Save your rule text in this file.
39+
For a simple `mit AND apache-2.0` license expression detection, here is an example
40+
rule file::
3741

38-
Then create the YAML data file in the src/licensedcode/data/rules/ directory
39-
using this name::
4042

41-
selected_base_name.yml
42-
43-
For a simple mit and gpl-2.0 license expression detection, the content of
44-
this file can be this YAML snippet::
45-
46-
license_expression: mit AND gpl-2.0
43+
---
44+
license_expression: mit AND apache-2.0
4745
is_license_notice: yes
46+
relevance: 100
47+
referenced_filenames:
48+
- LICENSE
49+
---
4850

49-
Save these two files in the ``src/licensedcode/data/licenses/`` directory and
50-
you are done!
51+
## License
52+
The MIT License (MIT) + Apache 2.0. Read [LICENSE](LICENSE).
5153

5254
See the ``src/licensedcode/data/rules/`` directory for many examples.
5355

5456
More (advanced) rules options:
5557

56-
- you can use a notes: text field to document this rule and explain where you
58+
- you can use a `notes` text field to document this rule and explain where you
5759
found it first.
5860

5961
- if no license should be detected for your .RULE text, do not add a license expression,
6062
just add a ``notes`` field.
6163

62-
- Each rules needs have one flag such as is_license_notice. See the
63-
``src/licensedcode/models.py`` directory for a list of all possible values and
64-
other options.
64+
- Each rules needs have one flag to describe the type of license rule, the options are:
65+
66+
- `is_license_notice`
67+
- `is_license_text`
68+
- `is_license_tag`
69+
- `is_license_reference`
70+
- `is_license_intro`
71+
72+
- There can also be false positive rules, which if detected in the file scanned, will not
73+
be present in the result license detections. These just have the license text and a
74+
`is_false_positive` flag set to True.
6575

6676
- you can specify key phrases by surrounding one or more words between the `{{`
6777
and `}}` tags. Key phrases are words that **must** be matched/present in order
6878
for a RULE to be considered a match.
79+
80+
See the ``src/licensedcode/models.py`` directory for a list of all possible values
81+
and other options.
82+
83+
.. note::
84+
85+
Add rules in a local developement installation and run `scancode-reindex-licenses`
86+
to make sure we reindex the rules and this validates the new licenses.

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ This is the basic structure of the example plugin::
2828
│ └── licenses_to_install1/
2929
│ ├── licenses/
3030
│ │ ├── example-installed-1.LICENSE
31-
│ │ └── example-installed-1.yaml
3231
| ├── rules/
3332
│ │ ├── example-installed-1.RULE
34-
│ │ └── example-installed-1.yaml
3533
│ └── __init__.py
3634
├── apache-2.0.LICENSE
3735
├── MANIFEST.in
@@ -104,17 +102,15 @@ an example of a plugin with tests. The tests are contained in the ``tests`` dire
104102
│ └── licenses_to_install1/
105103
│ ├── licenses/
106104
│ │ ├── example-installed-1.LICENSE
107-
│ │ └── example-installed-1.yaml
108105
│ ├── rules/
109106
│ │ ├── example-installed-1.RULE
110-
│ │ └── example-installed-1.yaml
111107
│ └── __init__.py/
112108
├── tests/
113109
│ ├── data/
114110
│ │ ├── example-installed-1.txt
115111
│ │ └── example-installed-1.txt.yml
116112
│ └── test_detection_datadriven.py
117-
├── gpl-1.0.LICENSE
113+
├── apache-2.0.LICENSE
118114
├── MANIFEST.in
119115
├── setup.cfg
120116
└── setup.py
@@ -142,8 +138,9 @@ Then you can define a test class and call the ``build_tests`` method defined in
142138
TEST_DIR,
143139
clazz=TestLicenseDataDriven1, regen=scancode_config.REGEN_TEST_FIXTURES)
144140

145-
The ``tests/data`` directory contains a pair of files for each license:
146-
a license text file and a YAML file specifying the expected license expressions from the test.
141+
The ``tests/data`` directory contains a file for each license:
142+
a license text file with a YAML frontmatter specifying the expected license expression
143+
from the test.
147144

148145
Finally, install the plugin and run the test:
149146

@@ -163,10 +160,8 @@ This is the basic structure of the example license directory::
163160
additional_license_directory/
164161
├── licenses/
165162
│ ├── example-installed-1.LICENSE
166-
│ └── example-installed-1.yaml
167163
├── rules/
168164
│ ├── example-installed-1.RULE
169-
│ └── example-installed-1.yaml
170165

171166
Adding the licenses to the index
172167
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)