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 小时
- 30 天内合并 PR
- 7
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aboutcode-org/scancode-toolkit 的其他 Issue
-
bug: Unreachable JSON extension and format validation in validate_input_path可能已有人在做 @0Cymantek0 于 18 天前认领。 未关闭
难度 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 于 17 天前认领。 未关闭
难度 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 于 45 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
aboutcode-org/scancode-toolkit#5319 · 2 条评论 ·
维护者通常 3 天内回复
-
Duplicate autogen.sh entry in commoncode default ignores可能已有人在做 @Daksha1611 于 47 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 92/100
aboutcode-org/scancode-toolkit#5316 ·
维护者通常 3 天内回复
-
Duplicate LGPL key in rubygems LICENSES_MAPPING makes one mapping unreachable可能已有人在做 @Daksha1611 于 48 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
aboutcode-org/scancode-toolkit#5314 · 1 条评论 ·
维护者通常 3 天内回复
查看 aboutcode-org/scancode-toolkit 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 68/100
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
ClockGU/clockwork-backend#169 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
aws-samples/sample-per-model-bedrock#616 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
chnm/teachinghistory-hugo#47 ·
-
good first issue
难度 2/5 1-3 小时 新手友好度 67/100
pandas-dev/pandas-stubs#2047 · 2 条评论 ·
维护者通常 1 天内回复