Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ce58241
Organize imports
pombredanne May 13, 2022
07df33c
Add new methods to collect package files
pombredanne May 13, 2022
4d0a38b
Recognize either app or system packages or both
pombredanne May 13, 2022
7062b3b
Use new commoncode
pombredanne May 13, 2022
69c17ce
Organize imports
pombredanne May 14, 2022
59b6ce3
Use new DATAFILE_HANDLERS in doc and code
pombredanne May 14, 2022
69a86a8
Bump version to 31.0.0b5
pombredanne May 16, 2022
6731d24
Use pre-released version of commoncode
pombredanne May 16, 2022
27fb42e
Use new resource for license reference
pombredanne May 16, 2022
e0f9167
Correct test expectations
pombredanne May 16, 2022
b82c5de
Bump commoncode to latest beta2
pombredanne May 16, 2022
7c1ea0d
Format CHANGELOG correctly.
pombredanne May 16, 2022
9a78cd7
Use new commoncode
pombredanne May 16, 2022
4eaeb73
Fix code syntax in deprecated code
pombredanne May 17, 2022
2e7afc4
Adjust help test for new --system-package option
pombredanne May 17, 2022
44c209a
Drop using Codebase(strip_root)
pombredanne May 17, 2022
040d3ae
Do not use removed Resource.pid
pombredanne May 17, 2022
9dcc1ff
Use new VirtualCode approach
pombredanne May 17, 2022
f4f1564
Adapt datafile_path handling to new Resource.path
pombredanne May 17, 2022
4b1fa75
Bump plugincode and commoncode
pombredanne May 17, 2022
7cfe7c7
Rename debian system-package tests
pombredanne May 17, 2022
22c2007
Rename win_reg system-package tests
pombredanne May 17, 2022
6c825a5
Use the --system-package option correctly
pombredanne May 17, 2022
4f9affd
Detect alpine installed packages end-to-end
pombredanne May 17, 2022
050a76d
Improve how we search for Windows roots
pombredanne May 17, 2022
a035084
Pin commoncode and plugincode for now
pombredanne May 17, 2022
80a46b6
Remove unused test file
pombredanne May 17, 2022
455c1ac
Ensure we can detect installed RPMs end to end
pombredanne May 17, 2022
3ed8e7f
Do not check headers in RPM tests
pombredanne May 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,61 +172,61 @@ Package detection:
License Clarity Scoring Update
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- We are moving away from the license clarity scoring defined by ClearlyDefined
in the license clarity score plugin. The previous license clarity scoring
logic produced a score that was misleading when it would return a low score
due to the stringent scoring criteria. We are now
using more general criteria to get a sense of what provenance information has
been provided and whether or not there is a conflict in licensing between
what licenses were declared at the top-level key files and what licenses have
been detected in the files under the top-level.
- We are moving away from the license clarity scoring defined by ClearlyDefined
in the license clarity score plugin. The previous license clarity scoring
logic produced a score that was misleading when it would return a low score
due to the stringent scoring criteria. We are now
using more general criteria to get a sense of what provenance information has
been provided and whether or not there is a conflict in licensing between
what licenses were declared at the top-level key files and what licenses have
been detected in the files under the top-level.

- The license clarity score is a value from 0-100 calculated by combining the
weighted values determined for each of the scoring elements:
- The license clarity score is a value from 0-100 calculated by combining the
weighted values determined for each of the scoring elements:

- Declared license:
- Declared license:

- When true, indicates that the software package licensing is documented at
top-level or well-known locations in the software project, typically in a
package manifest, NOTICE, LICENSE, COPYING or README file.
- Scoring Weight = 40
- When true, indicates that the software package licensing is documented at
top-level or well-known locations in the software project, typically in a
package manifest, NOTICE, LICENSE, COPYING or README file.
- Scoring Weight = 40

- Identification precision:
- Identification precision:

- Indicates how well the license statement(s) of the software identify known
licenses that can be designated by precise keys (identifiers) as provided in
a publicly available license list, such as the ScanCode LicenseDB, the SPDX
license list, the OSI license list, or a URL pointing to a specific license
text in a project or organization website.
- Scoring Weight = 40
- Indicates how well the license statement(s) of the software identify known
licenses that can be designated by precise keys (identifiers) as provided in
a publicly available license list, such as the ScanCode LicenseDB, the SPDX
license list, the OSI license list, or a URL pointing to a specific license
text in a project or organization website.
- Scoring Weight = 40

- License texts:
- License texts:

- License texts are provided to support the declared license expression in
files such as a package manifest, NOTICE, LICENSE, COPYING or README.
- Scoring Weight = 10
- License texts are provided to support the declared license expression in
files such as a package manifest, NOTICE, LICENSE, COPYING or README.
- Scoring Weight = 10

- Declared copyright:
- Declared copyright:

- When true, indicates that the software package copyright is documented at
top-level or well-known locations in the software project, typically in a
package manifest, NOTICE, LICENSE, COPYING or README file.
- Scoring Weight = 10
- When true, indicates that the software package copyright is documented at
top-level or well-known locations in the software project, typically in a
package manifest, NOTICE, LICENSE, COPYING or README file.
- Scoring Weight = 10

- Ambiguous compound licensing:
- Ambiguous compound licensing:

- When true, indicates that the software has a license declaration that
makes it difficult to construct a reliable license expression, such as in
the case of multiple licenses where the conjunctive versus disjunctive
relationship is not well defined.
- Scoring Weight = -10
- When true, indicates that the software has a license declaration that
makes it difficult to construct a reliable license expression, such as in
the case of multiple licenses where the conjunctive versus disjunctive
relationship is not well defined.
- Scoring Weight = -10

- Conflicting license categories:
- Conflicting license categories:

- When true, indicates that the declared license expression of the software is in
the permissive category, but that other potentially conflicting categories,
such as copyleft and proprietary, have been detected in lower level code.
- Scoring Weight = -20
- When true, indicates that the declared license expression of the software is in
the permissive category, but that other potentially conflicting categories,
such as copyleft and proprietary, have been detected in lower level code.
- Scoring Weight = -20


Summary Plugin Update
Expand Down Expand Up @@ -258,7 +258,7 @@ Outputs:
Output version
--------------

Scancode Data Output Version is now 3.0.0.
Scancode Data Output Version is now 1.0.0.

Changes:

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ chardet==4.0.0
charset-normalizer==2.0.12
click==8.0.4
colorama==0.4.4
commoncode==30.2.0
commoncode==31.0.0b4
construct==2.10.68
container-inspector==31.0.0
cryptography==36.0.2
Expand Down Expand Up @@ -49,7 +49,7 @@ pefile==2021.9.3
pip-requirements-parser==31.2.0
pkginfo2==30.0.0
pluggy==1.0.0
plugincode==30.0.0
plugincode==31.0.0b1
ply==3.11
publicsuffix2==2.20191221
pyahocorasick==2.0.0b1
Expand Down
12 changes: 6 additions & 6 deletions setup-mini.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = scancode-toolkit-mini
version = 31.0.0b4
version = 31.0.0b5
license = Apache-2.0 AND CC-BY-4.0 AND LicenseRef-scancode-other-permissive AND LicenseRef-scancode-other-copyleft

# description must be on ONE line https://github.com/pypa/setuptools/issues/1390
Expand Down Expand Up @@ -65,11 +65,11 @@ python_requires = >=3.6.*
install_requires =
attrs >= 18.1, !=20.1.0
Beautifulsoup4 >= 4.0.0
boolean.py >= 3.5
boolean.py >= 4.0
chardet >= 3.0.0
click >= 6.7, !=7.0
colorama >= 0.3.9
commoncode >= 30.2.0
commoncode==31.0.0b4
container-inspector >= 31.0.0
debian-inspector >= 30.0.0
dparse2 >= 0.6.1
Expand All @@ -84,7 +84,7 @@ install_requires =
javaproperties >= 0.5
jinja2 >= 2.7.0
jsonstreams >= 0.5.0
license_expression >= 21.6.14
license_expression >= 30.0.0
lxml >= 4.6.5
MarkupSafe >= 1.0
packageurl_python >= 0.9.0
Expand All @@ -96,7 +96,7 @@ install_requires =
pkginfo2 >= 30.0.0
pip-requirements-parser >= 31.2.0
pluggy >= 1.0.0
plugincode >= 30.0.0
plugincode==31.0.0b1
publicsuffix2
pyahocorasick >= 2.0.0b1
pygmars >= 0.7.0
Expand Down Expand Up @@ -126,7 +126,7 @@ full =
testing =
pytest >= 6, != 7.0.0
pytest-xdist >= 2
aboutcode-toolkit >= 6.0.0
aboutcode-toolkit >= 7.0.2
twine

docs =
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = scancode-toolkit
version = 31.0.0b4
version = 31.0.0b5
license = Apache-2.0 AND CC-BY-4.0 AND LicenseRef-scancode-other-permissive AND LicenseRef-scancode-other-copyleft

# description must be on ONE line https://github.com/pypa/setuptools/issues/1390
Expand Down Expand Up @@ -69,7 +69,7 @@ install_requires =
chardet >= 3.0.0
click >= 6.7, !=7.0
colorama >= 0.3.9
commoncode >= 30.2.0
commoncode==31.0.0b4
container-inspector >= 31.0.0
debian-inspector >= 30.0.0
dparse2 >= 0.6.1
Expand All @@ -96,7 +96,7 @@ install_requires =
pkginfo2 >= 30.0.0
pip-requirements-parser >= 31.2.0
pluggy >= 1.0.0
plugincode >= 30.0.0
plugincode==31.0.0b1
publicsuffix2
pyahocorasick >= 2.0.0b1
pygmars >= 0.7.0
Expand Down
29 changes: 19 additions & 10 deletions src/licensedcode/plugin_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
# See https://aboutcode.org for more information about nexB OSS projects.
#

import posixpath
from functools import partial

import attr

from plugincode.scan import ScanPlugin
from plugincode.scan import scan_impl
from commoncode.cliutils import MISC_GROUP
from commoncode.cliutils import PluggableCommandLineOption
from commoncode.cliutils import SCAN_OPTIONS_GROUP
from commoncode.cliutils import SCAN_GROUP
from commoncode.fileutils import file_name
from scancode.api import SCANCODE_LICENSEDB_URL
from commoncode.resource import clean_path
from plugincode.scan import ScanPlugin
from plugincode.scan import scan_impl

from scancode.api import SCANCODE_LICENSEDB_URL

TRACE = False


def logger_debug(*args): pass


Expand Down Expand Up @@ -274,8 +275,16 @@ def find_referenced_resource(referenced_filename, resource, codebase, **kwargs):
``resource``. ``referenced_filename`` is the path or filename referenced in
a LicenseMatch of ``resource``,
"""
# this can be a path
ref_filename = file_name(referenced_filename)
for child in resource.parent(codebase).children(codebase):
if child.name == ref_filename:
return child
if not resource:
return

parent_path = resource.parent_path()
if not parent_path:
return

# this can be a path or a plain name
referenced_filename = clean_path(referenced_filename)
path = posixpath.join(parent_path, referenced_filename)
resource = codebase.get_resource(path=path)
if resource:
return resource
44 changes: 29 additions & 15 deletions src/packagedcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@

# Note: the order matters: from the most to the least specific parser.
# a handler classes MUST be added to this list to be active
PACKAGE_DATAFILE_HANDLERS = [
APPLICATION_PACKAGE_DATAFILE_HANDLERS = [
about.AboutFileHandler,

alpine.AlpineApkArchiveHandler,
alpine.AlpineApkbuildHandler,
alpine.AlpineInstalledDatabaseHandler,

bower.BowerJsonHandler,

Expand Down Expand Up @@ -78,14 +77,7 @@
cran.CranDescriptionFileHandler,

debian_copyright.DebianCopyrightFileInPackageHandler,
debian_copyright.DebianCopyrightFileInSourceHandler,
# TODO: consider activating? debian_copyright.StandaloneDebianCopyrightFileHandler,

debian.DebianDscFileHandler,
debian.DebianDistrolessInstalledDatabaseHandler,
debian.DebianInstalledFilelistHandler,
debian.DebianInstalledMd5sumFilelistHandler,
debian.DebianInstalledStatusDatabaseHandler,

debian.DebianControlFileInExtractedDebHandler,
debian.DebianControlFileInSourceHandler,
Expand Down Expand Up @@ -182,9 +174,6 @@
readme.ReadmeHandler,

rpm.RpmArchiveHandler,
rpm.RpmInstalledBdbDatabaseHandler,
rpm.RpmInstalledSqliteDatabaseHandler,
rpm.RpmInstalledNdbDatabaseHandler,
rpm.RpmSpecfileHandler,

rubygems.GemMetadataArchiveExtractedHandler,
Expand All @@ -206,15 +195,40 @@
windows.MicrosoftUpdateManifestHandler,

win_pe.WindowsExecutableHandler,
]


SYSTEM_PACKAGE_DATAFILE_HANDLERS = [
alpine.AlpineInstalledDatabaseHandler,

debian_copyright.DebianCopyrightFileInPackageHandler,
debian_copyright.DebianCopyrightFileInSourceHandler,

# TODO: consider activating? debian_copyright.StandaloneDebianCopyrightFileHandler,

debian.DebianDistrolessInstalledDatabaseHandler,

debian.DebianInstalledFilelistHandler,
debian.DebianInstalledMd5sumFilelistHandler,
debian.DebianInstalledStatusDatabaseHandler,

rpm.RpmInstalledBdbDatabaseHandler,
rpm.RpmInstalledSqliteDatabaseHandler,
rpm.RpmInstalledNdbDatabaseHandler,

win_reg.InstalledProgramFromDockerSoftwareDeltaHandler,
win_reg.InstalledProgramFromDockerFilesSoftwareHandler,
win_reg.InstalledProgramFromDockerUtilityvmSoftwareHandler,
]

HANDLER_BY_DATASOURCE_ID = {
handler.datasource_id: handler for handler in PACKAGE_DATAFILE_HANDLERS
}
ALL_DATAFILE_HANDLERS= (
APPLICATION_PACKAGE_DATAFILE_HANDLERS + [
p for p in SYSTEM_PACKAGE_DATAFILE_HANDLERS
if p not in APPLICATION_PACKAGE_DATAFILE_HANDLERS
]
)

HANDLER_BY_DATASOURCE_ID = {handler.datasource_id: handler for handler in ALL_DATAFILE_HANDLERS}


class UnknownPackageDatasource(Exception):
Expand Down
2 changes: 1 addition & 1 deletion src/packagedcode/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def assemble(cls, package_data, resource, codebase):

yield package

if resource.pid is not None and package_data.file_references:
if resource.has_parent() and package_data.file_references:
parent_resource = resource.parent(codebase)
if parent_resource and package_data.file_references:
root_path = Path(parent_resource.path)
Expand Down
6 changes: 5 additions & 1 deletion src/packagedcode/alpine.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ class AlpineInstalledDatabaseHandler(models.DatafileHandler):

@classmethod
def parse(cls, location):
yield from parse_alpine_installed_db(location)
yield from parse_alpine_installed_db(
location=location,
datasource_id=cls.datasource_id,
package_type=cls.default_package_type,
)

@classmethod
def assemble(cls, package_data, resource, codebase):
Expand Down
4 changes: 2 additions & 2 deletions src/packagedcode/debian_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
# See https://github.com/nexB/scancode-toolkit for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
import fnmatch
import os
import sys
from collections import defaultdict
from itertools import chain
from pathlib import Path

import attr
from debian_inspector.copyright import CatchAllParagraph
Expand All @@ -33,8 +35,6 @@
from packagedcode.licensing import get_license_matches_from_query_string
from packagedcode.utils import combine_expressions
from textcode.analysis import unicode_text
import fnmatch
from pathlib import Path

"""
Detect licenses and copyright in Debian copyright files. Can handle dep-5
Expand Down
Loading