Duplicate keys in alpine DECLARED_TO_SPDX silently discard two license mappings
メンテナーはふだん 3 日以内に返信
評価
調査の方向性
src/packagedcode/alpine.py を開き、DECLARED_TO_SPDX と、issue に示されている派生 DECLARED_TO_SPDX_SUBS 内包表記を調べます。指定された行にある重複キー 'as-is' と 'custom:tu-berlin-2.0' を確認し、曖昧さを追加せずに各キーが一度だけ現れるよう調整します。重複がなくなったことを確認するため、提供されている AST 重複キー検査(または同等のスクリプト)を変更前と変更後に実行します。重複キーの警告がなくなり、mapping の動作が意図された値に明示的に一致していれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
DECLARED_TO_SPDX in src/packagedcode/alpine.py has two duplicate keys. A dict literal keeps only the last value for a repeated key, so the earlier entry of each pair is dead at import time.
'as-is':
- line 1619:
'as-is': 'licenseref-scancode-free-unknown', - line 1701:
'as-is': 'licenseref-scancode-unknown-license-reference',
'custom:tu-berlin-2.0':
- line 1690:
'custom:tu-berlin-2.0': 'licenseref-scancode-unknown-license-reference', - line 1715:
'custom:tu-berlin-2.0': 'tu-berlin-2.0',
Each of the four entries carries its own comment, so the two pairs look like they were added independently without noticing the collision.
This mapping is turned straight into the substitution table applied to every Alpine package license expression:
DECLARED_TO_SPDX_SUBS = {
licensing.parse(src, simple=True): licensing.parse(tgt, simple=True)
for src, tgt in DECLARED_TO_SPDX.items()
}
So which value wins is decided by position in the file rather than by intent. For 'as-is' the surviving value is the less specific licenseref-scancode-unknown-license-reference, and the licenseref-scancode-free-unknown mapping never applies.
How To Reproduce
import ast, collections
src = open('src/packagedcode/alpine.py').read()
for node in ast.walk(ast.parse(src)):
if isinstance(node, ast.Dict):
counts = collections.Counter(
k.value for k in node.keys
if isinstance(k, ast.Constant) and isinstance(k.value, str)
)
for key, n in counts.items():
if n > 1:
print(f'line {node.lineno}: duplicate key {key!r} x{n}')
line 1568: duplicate key 'as-is' x2
line 1568: duplicate key 'custom:tu-berlin-2.0' x2
Suggested fix
Drop the dead lines so each key appears once. Which of the two values is actually wanted for each key needs a maintainer decision, since right now it is settled by line order — I have opened a PR that removes the unreachable entries and keeps the currently-winning values, so behaviour does not change.
System configuration
- What OS are you running on? Linux (x86_64)
- What version of scancode-toolkit was used? 33.0.0rc1,
developat 5ebebf2 - What installation method was used to install/run scancode? source checkout
- Python version: 3.x
- 主要言語
- Python
- スター
- 2.7k
- フォーク
- 831
- 平均マージ
- 3日 4時間
- マージ済み PR(30日)
- 7
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
aboutcode-org/scancode-toolkit のほかの issue
-
bug: Unreachable JSON extension and format validation in validate_input_path対応中かも @0Cymantek0 が 19 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
aboutcode-org/scancode-toolkit#5351 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
CycloneDX output: metadata.properties[].value emits JSON array instead of string対応中かも @0Cymantek0 が 18 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
aboutcode-org/scancode-toolkit#5349 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
Duplicate 'COPYLEFT' entries in legal file classification names in legal.py and classify.py対応中かも @Pradeepbeleri が 46 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
aboutcode-org/scancode-toolkit#5319 · コメント 2 件 ·
メンテナーはふだん 3 日以内に返信
-
Duplicate autogen.sh entry in commoncode default ignores対応中かも @Daksha1611 が 49 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
aboutcode-org/scancode-toolkit#5316 ·
メンテナーはふだん 3 日以内に返信
-
Duplicate LGPL key in rubygems LICENSES_MAPPING makes one mapping unreachable対応中かも @Daksha1611 が 49 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
aboutcode-org/scancode-toolkit#5314 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
aboutcode-org/scancode-toolkit の issue をすべて見る
似ている issue
-
infrastructure
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
NatLabRockies/H2Integrate#977 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
topoteretes/cognee#6470 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
area:docs priority:p2 type:docs wave:9
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
jejjohnson/radtrax#293 ·
メンテナーはふだん 1 日以内に返信
-
bug core plugins
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
bunkerity/bunkerweb#4121 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信