From 7fcd25da7005f8b9c9baf63399a445b7475bdcad Mon Sep 17 00:00:00 2001 From: Ayan Sinha Mahapatra Date: Mon, 18 Mar 2024 14:41:30 +0530 Subject: [PATCH] Update CHANGELOG, docs and CLI option tests Signed-off-by: Ayan Sinha Mahapatra --- CHANGELOG.rst | 6 ++++ docs/source/rst_snippets/basic_options.rst | 4 +++ src/packagedcode/plugin_package.py | 6 ++-- tests/packagedcode/test_plugin_package.py | 36 ++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d7775a298b2..c0da1d326ac 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -37,6 +37,12 @@ v33.0.0 (next next, roadmap) v32.1.0 (next, roadmap) ---------------------------- +New CLI options: + +- A new CLI option ``--package-only`` has been added which performs + a faster package scan by skipping the package assembly step and + also skipping license/copyright detection on package metadata. + Major API/other changes: - Output Format Version updated to 3.1.0 (minor version bump) diff --git a/docs/source/rst_snippets/basic_options.rst b/docs/source/rst_snippets/basic_options.rst index b4c3eb408ec..d01fbf72a6c 100644 --- a/docs/source/rst_snippets/basic_options.rst +++ b/docs/source/rst_snippets/basic_options.rst @@ -33,6 +33,10 @@ documenting a program's options. For example: --system-package Scan ```` for installed system package databases. +--package-only Scan ```` for system and application + only for package metadata, without license/ + copyright detection and package assembly. + -e, --email Scan ```` for emails. Sub-Options: diff --git a/src/packagedcode/plugin_package.py b/src/packagedcode/plugin_package.py index 09f300453e9..1e7c46c3b57 100644 --- a/src/packagedcode/plugin_package.py +++ b/src/packagedcode/plugin_package.py @@ -166,9 +166,11 @@ class PackageScanner(ScanPlugin): ), is_flag=True, default=False, + conflicting_options=['license', 'summary', 'package', 'system_package'], help=( - 'Only detect package information and skip license/copyright detection steps, ' - 'in application package and dependency manifests, lockfiles and related data.' + 'Only detect package metadata and skip license/copyright detection steps, ' + 'and skip package assembly in package and dependency manifests, lockfiles ' + 'and related data.' ), help_group=SCAN_GROUP, sort_order=22, diff --git a/tests/packagedcode/test_plugin_package.py b/tests/packagedcode/test_plugin_package.py index 2ca1bfe54b7..2594b4fbd64 100644 --- a/tests/packagedcode/test_plugin_package.py +++ b/tests/packagedcode/test_plugin_package.py @@ -227,6 +227,42 @@ def test_package_list_command(self, regen=REGEN_TEST_FIXTURES): ef.write(result.output) assert result.output == open(expected_file).read() + def test_plugin_package_only_fails_with_license_scan(self): + test_dir = self.get_test_loc('maven2') + result_file = self.get_temp_file('json') + try: + run_scan_click(['--package-only', '--license', test_dir, '--json', result_file]) + raise Exception("This SCAN should raise an AssertionError for conflicting CLI options") + except AssertionError: + pass + + def test_plugin_package_only_fails_with_summary_scan(self): + test_dir = self.get_test_loc('maven2') + result_file = self.get_temp_file('json') + try: + run_scan_click(['--package-only', '--summary', '--classify', test_dir, '--json', result_file]) + raise Exception("This SCAN should raise an AssertionError for conflicting CLI options") + except AssertionError: + pass + + def test_plugin_package_only_fails_with_package_scan(self): + test_dir = self.get_test_loc('maven2') + result_file = self.get_temp_file('json') + try: + run_scan_click(['--package-only', '--package', test_dir, '--json', result_file]) + raise Exception("This SCAN should raise an AssertionError for conflicting CLI options") + except AssertionError: + pass + + def test_plugin_package_only_fails_with_system_package_scan(self): + test_dir = self.get_test_loc('maven2') + result_file = self.get_temp_file('json') + try: + run_scan_click(['--package-only', '--system-package', test_dir, '--json', result_file]) + raise Exception("This SCAN should raise an AssertionError for conflicting CLI options") + except AssertionError: + pass + def test_system_package_get_installed_packages(self): test_dir = self.extract_test_tar('debian/basic-rootfs.tar.gz') expected_file = self.get_test_loc('plugin/get_installed_packages-expected.json')