ignored_dependency_scopes does not exclude npm devDependencies
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
scanpipe/pipes/__init__.py の ignore_dependency_scope() を調べ、パッケージタイプと scope について依存関係メタデータがどのように抽出されるかを確認します。既存の ignored_dependency_scopes の作業でこのパスをカバーしているテストを確認して現在の前提を把握し、その後、purl と scope しか提供しない npm 依存関係の回帰ケースを追加または調整します。依存関係フィルターのテストを実行し、package_type: npm および scope: devDependencies の ignored_dependency_scopes ルールによって、それらの devDependencies が作成も解決もされなくなったら完了としてマークします。
索引モデルが issue の本文から書いたものです。
説明
Description
The ignored_dependency_scopes setting in scancode-config.yml does not appear to exclude npm devDependencies during a ScanCode.io scan.
I encountered this while scanning ScanCode Workbench 4.0.2. I intentionally used the same configuration that is documented in the official ScanCode.io end-to-end tutorial:
product_name: scancode-workbench
product_version: '4.0.2'
ignored_patterns:
- 'tests/*'
ignored_dependency_scopes:
- package_type: npm
scope: devDependencies
The scancode-config.yml is located at the root of the project inside a single uploaded source archive.
The scan completes successfully, but dependencies with the scope devDependencies are still included instead of being ignored.
This seems to affect the ignored_dependency_scopes filtering itself rather than npm dependency detection, since ScanCode Toolkit correctly identifies these dependencies with the scope devDependencies.
How To Reproduce
Steps:
- Use ScanCode Workbench 4.0.2 as the npm project.
- Add the following
scancode-config.ymlto the project root:
product_name: scancode-workbench
product_version: '4.0.2'
ignored_patterns:
- 'tests/*'
ignored_dependency_scopes:
- package_type: npm
scope: devDependencies
- Create a source archive containing the project and configuration.
- Create a ScanCode.io project and upload the archive as a single input.
- Run package inspection/scanning so that npm dependencies from
package-lock.jsonare collected. - Inspect the resulting dependencies.
Dependencies with:
scope: devDependencies
are still present even though they should be ignored by the project configuration.
The provided package-lock.json uses lockfile version 3 and contains a large number of dependencies marked as development dependencies, so the behavior is easy to reproduce.
Expected behavior
npm dependencies with the scope devDependencies should be ignored when the following configuration is present:
ignored_dependency_scopes:
- package_type: npm
scope: devDependencies
According to the ScanCode.io documentation, dependencies matching an ignored package type and scope should not be created or resolved.
This configuration is also the exact example currently used in the ScanCode.io tutorial with ScanCode Workbench 4.0.2.
Actual behavior
npm dependencies with scope: devDependencies are still created/included in the scan results.
Suspected root cause
I looked into the implementation and suspect that the issue is in ignore_dependency_scope() in:
scanpipe/pipes/__init__.py
The function currently retrieves the package type and scope from the dependency data:
dependency_package_type = dependency_data.get("package_type")
dependency_scope = dependency_data.get("scope")
and only evaluates the ignore rule when both values are present.
However, ScanCode Toolkit's DependentPackage / Dependency model does not appear to contain a package_type field.
The dependency model contains fields such as:
purl
extracted_requirement
scope
is_runtime
is_optional
is_pinned
is_direct
resolved_package
extra_data
For an npm dependency, the package type is already represented by the PURL, for example:
pkg:npm/...
while the dependency scope is correctly represented as:
devDependencies
Therefore, for a normal dependency generated by ScanCode Toolkit, this lookup appears to result in:
dependency_data.get("package_type") # None
As a consequence, the following condition is not entered:
if dependency_package_type and dependency_scope:
and the configured ignore rule is never evaluated.
Relation to the original implementation
ignored_dependency_scopes was introduced as part of #1197 and implemented in #1235.
There is another interesting detail in the tests added with #1235: for the positive ignore_dependency_scope() test case, package_type appears to be manually added to the dependency dictionary before calling the function.
In other words, the test verifies the behavior with something similar to:
dependency_data["package_type"] = "pypi"
dependency_data["scope"] = "tests"
This may explain why the implementation passes its unit test even though a normal dependency produced by ScanCode Toolkit does not contain that package_type field.
A regression test using an actual ScanCode Toolkit Dependency / DependentPackage object may expose the problem.
Possible approach
One possible solution could be to derive the package type from the dependency PURL when package_type is not explicitly available.
For example, a dependency such as:
pkg:npm/[email protected]
already provides the required package type (npm).
Alternatively, the dependency data could be normalized so that the package type is populated before ignore_dependency_scope() is called.
The exact implementation is of course up to the maintainers.
Related issues / changes
- #1197 – Enhance and create detailed documentation for
scancode-config.yml - #1235 – Add support for
ignored_dependency_scopesfield for configuration - #1236 – Support storing
scancode-config.ymlfiles in the scanned codebase
#1236 specifically documents that, for a single archive input, a scancode-config.yml located at the root should be used.
The official ScanCode.io end-to-end tutorial also currently uses ScanCode Workbench 4.0.2 together with:
ignored_dependency_scopes:
- package_type: npm
scope: devDependencies
which makes this project a convenient reproducer.
System configuration
- ScanCode.io: 37.2.0
- ScanCode Toolkit: 32.5.0
- Installation: Docker
- Package ecosystem: npm
- npm lockfile:
package-lock.json, lockfile version 3 - Input: single source code archive containing
scancode-config.yml
I also checked the current ScanCode.io main branch, and ignore_dependency_scope() still appears to use dependency_data.get("package_type") in the same way.
- 主要言語
- Python
- スター
- 223
- フォーク
- 214
- 平均マージ
- 2日 3時間
- マージ済み PR(30日)
- 13
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
aboutcode-org/scancode.io のほかの issue
-
Delivery Error in scan_single_package: No connection adapters were found for '/notifications/send_scan_notification/再び着手できるかも @akshat-lakhera が 11 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
aboutcode-org/scancode.io#2206 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
update `run` cli command to run pipelines without an input対応中かも @NoiceHax が 76 日前に担当しました。 オープンnice-to-have
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
aboutcode-org/scancode.io#2203 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Local developement docs are outdated対応中かも @nik-767 が 106 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
aboutcode-org/scancode.io#2197 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
maven-heaven: `map_shaded_classes_to_maven_packages` ignores POMs present only in the from/ codebase, leaving all shaded .class resources unmapped対応中かも @chinyeungli が 3 日前に担当しました。 オープン
aboutcode-org/scancode.io#2284 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
maven-heaven: Update Maven Pipeline's steps再び着手できるかも @saksham-rathore が 8 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 58/100
aboutcode-org/scancode.io#2269 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
aboutcode-org/scancode.io の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
NousResearch/hermes-agent#147104 ·
メンテナーはふだん 1 日以内に返信
-
[oblt-aw][autodoc] Document new required `shared-org-key` input for `obs-aw-dependency-review`対応中かも @github-actions が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
bot-triaged module: inductor oncall: pt2 topic: fuzzer triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
getchaintips leaves out the active tip once a header is staged on it, where Core always lists itオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
btclib-org/btclib-node#2158 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
patrick-hudson/put.gd-desktop#979 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信