Skip to content

Commit 437f9a0

Browse files
committed
fix(cluecode): detect glued Author:Name C++ tags
- fix(cluecode): narrow Frankie.Chu author grammar to NAME-DOT - fix(ci): stop PyPI commoncode from shadowing in-tree sources - fix(ci): make Windows latest_from_pip uninstall sequential - fix(cluecode): dual-home NAME-DOT for copyright holders - fix(cluecode): reject sentence-glue NAME-DOT holders Signed-off-by: Alex Chen <l46983284@gmail.com>
1 parent 6ba5908 commit 437f9a0

6 files changed

Lines changed: 52 additions & 5 deletions

File tree

azure-pipelines.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,39 +194,39 @@ jobs:
194194
image_name: ubuntu-22.04
195195
python_versions: ['3.10', '3.11', '3.12', '3.13', '3.14']
196196
test_suites:
197-
all: venv/bin/pip install --upgrade-strategy eager --force-reinstall --upgrade -e .[testing] && venv/bin/pytest -n 2 -vvs tests/scancode/test_cli.py
197+
all: venv/bin/pip install --upgrade-strategy eager --force-reinstall --upgrade -e .[testing] && (venv/bin/pip uninstall -y commoncode || true) && venv/bin/pytest -n 2 -vvs tests/scancode/test_cli.py
198198

199199
- template: etc/ci/azure-posix.yml
200200
parameters:
201201
job_name: ubuntu24_cpython_latest_from_pip
202202
image_name: ubuntu-24.04
203203
python_versions: ['3.10', '3.11', '3.12', '3.13', '3.14']
204204
test_suites:
205-
all: venv/bin/pip install --upgrade-strategy eager --force-reinstall --upgrade -e .[testing] && venv/bin/pytest -n 2 -vvs tests/scancode/test_cli.py
205+
all: venv/bin/pip install --upgrade-strategy eager --force-reinstall --upgrade -e .[testing] && (venv/bin/pip uninstall -y commoncode || true) && venv/bin/pytest -n 2 -vvs tests/scancode/test_cli.py
206206

207207
- template: etc/ci/azure-posix.yml
208208
parameters:
209209
job_name: macos14_cpython_latest_from_pip
210210
image_name: macos-14
211211
python_versions: ['3.10', '3.11', '3.12', '3.13', '3.14']
212212
test_suites:
213-
all: venv/bin/pip install --upgrade-strategy eager --force-reinstall --upgrade -e .[testing] && venv/bin/pytest -n 2 -vvs tests/scancode/test_cli.py
213+
all: venv/bin/pip install --upgrade-strategy eager --force-reinstall --upgrade -e .[testing] && (venv/bin/pip uninstall -y commoncode || true) && venv/bin/pytest -n 2 -vvs tests/scancode/test_cli.py
214214

215215
- template: etc/ci/azure-win.yml
216216
parameters:
217217
job_name: win2019_cpython_latest_from_pip
218218
image_name: windows-2025-vs2026
219219
python_versions: ['3.10', '3.11', '3.12', '3.13', '3.14']
220220
test_suites:
221-
all: venv\Scripts\pip install --upgrade-strategy eager --force-reinstall --upgrade -e .[testing] && venv\Scripts\pytest -n 2 -vvs tests\scancode\test_cli.py
221+
all: venv\Scripts\pip install --upgrade-strategy eager --force-reinstall --upgrade -e .[testing] && (venv\Scripts\pip uninstall -y commoncode || echo.) && venv\Scripts\pytest -n 2 -vvs tests\scancode\test_cli.py
222222

223223
- template: etc/ci/azure-win.yml
224224
parameters:
225225
job_name: win2022_cpython_latest_from_pip
226226
image_name: windows-2022
227227
python_versions: ['3.10', '3.11', '3.12', '3.13', '3.14']
228228
test_suites:
229-
all: venv\Scripts\pip install --upgrade-strategy eager --force-reinstall --upgrade -e .[testing] && venv\Scripts\pytest -n 2 -vvs tests\scancode\test_cli.py
229+
all: venv\Scripts\pip install --upgrade-strategy eager --force-reinstall --upgrade -e .[testing] && (venv\Scripts\pip uninstall -y commoncode || echo.) && venv\Scripts\pytest -n 2 -vvs tests\scancode\test_cli.py
230230

231231

232232
################################################################################

configure

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ find_python
314314
create_virtualenv "$VIRTUALENV_DIR"
315315
install_packages "$FLOT_REQUIREMENTS"
316316
install_packages "$CFG_REQUIREMENTS"
317+
# After commoncode was merged back (#5116), transitive deps still install PyPI
318+
# commoncode (e.g. 32.5.2) into site-packages. That package shadows the in-tree
319+
# src/commoncode from the editable install (clean_path uses rstrip on PyPI vs
320+
# strip in-tree), which breaks --full-root CLI tests. Drop the PyPI dist so the
321+
# in-tree sources on the editable path win.
322+
"$CFG_BIN_DIR/pip" uninstall -y commoncode >/dev/null 2>&1 || true
317323
. "$CFG_BIN_DIR/activate"
318324
"$CFG_BIN_DIR/scancode-train-gibberish-model"
319325

configure.bat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ if %ERRORLEVEL% neq 0 (
168168
%PIP_EXTRA_ARGS% ^
169169
%CFG_REQUIREMENTS%
170170

171+
@rem After commoncode was merged back (#5116), transitive deps still install PyPI
172+
@rem commoncode into site-packages and shadow in-tree src/commoncode. Uninstall
173+
@rem the PyPI dist so the editable path sources win (needed for --full-root tests).
174+
"%CFG_BIN_DIR%\pip" uninstall -y commoncode >nul 2>&1
175+
171176
"%CFG_BIN_DIR%\scancode-train-gibberish-model"
172177

173178
@rem ################################

src/cluecode/copyrights.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ def get_tokens(numbered_lines, splitter=re.compile(r'[\t =;]+').split):
428428
if TRACE_TOK:
429429
logger_debug(' get_tokens: preped line: ' + repr(line))
430430

431+
# Split glued Author:/Authors: tags so "Author:Frankie.Chu" tokenizes as AUTH + name.
432+
# Keep ordinary tokens intact; only introduce a space after the tag when missing.
433+
line = re.sub(r'(?i)\b(authors?|@authors?)(:)(?=\S)', r'\1\2 ', line)
434+
431435
for tok in splitter(line):
432436
# strip trailing quotes+comma
433437
if tok.endswith("',"):
@@ -2227,6 +2231,16 @@ def build_detection_from_node(
22272231
# proper noun with some separator and trailing comma
22282232
(r'^[A-Z]+\.[A-Z][a-z]+,?$', 'NNP'),
22292233

2234+
# Mixed-case dotted personal/product name token, e.g. Frankie.Chu / Rocket.Chat.
2235+
# Keep this after exact NNP exceptions (Xiph.Org) and exclude common domain/org suffixes
2236+
# so tokens like Xiph.Org/Iotacoffee.Com still fall through to URL/NNP patterns.
2237+
# NAME-DOT is intentionally not NNP: AUTHOR only matches AUTH + NAME-DOT for
2238+
# single-token Author:Name tags, avoiding false authors from bare AUTH NNP.
2239+
# Also reject sentence-glue tails from missing spaces in license prose
2240+
# (Assignment.This, Remedies.In, Corporation.All) so dual-home copyright
2241+
# grammar cannot invent holders from section headers.
2242+
(r'^[A-Z][a-z0-9]+(?:\.(?!Org,?$|Com,?$|Net,?$|Edu,?$|Gov,?$|Inc,?$|Ltd,?$|Co,?$|This,?$|In,?$|All,?$|The,?$|Of,?$|And,?$|For,?$|By,?$|With,?$|From,?$|To,?$|As,?$|Or,?$|An,?$|At,?$|On,?$|Is,?$|Are,?$|Was,?$|Be,?$|If,?$|Not,?$|No,?$|Any,?$|Such,?$|That,?$|These,?$|Those,?$|When,?$|Where,?$|Which,?$|Who,?$|Will,?$|Shall,?$|May,?$|Can,?$|Must,?$|Should,?$|Would,?$|Could,?$|Rights,?$|Reserved,?$|Agreement,?$|Event,?$|Breach,?$|License,?$|Software,?$|Source,?$|Code,?$|File,?$|Files,?$|Notice,?$|Notices,?$|Subject,?$|Terms,?$|Conditions,?$|Section,?$|Clause,?$|Party,?$|Parties,?$)[A-Z][a-z0-9]+)+,?$', 'NAME-DOT'),
2243+
22302244
# proper noun with apostrophe ': D'Orleans, D'Arcy, T'so, Ts'o
22312245
(r"^[A-Z][a-z]?'[A-Z]?[a-z]+[,\.]?$", 'NNP'),
22322246

@@ -2552,6 +2566,9 @@ def build_detection_from_node(
25522566
25532567
# NAME-YEAR starts or ends with a YEAR range
25542568
NAME-YEAR: {<YR-RANGE> <NNP> <NNP>+} #350
2569+
# 2015-2020 Rocket.Chat Technologies Corp. (NAME-DOT accepted where NNP is needed)
2570+
NAME-YEAR: {<YR-RANGE> <NAME-DOT> <COMP|COMPANY|NNP|NN>+} #350.05
2571+
NAME-YEAR: {<YR-RANGE> <NAME-DOT>} #350.06
25552572
25562573
COPYRIGHT: {<COPY> <YR-RANGE> <NNP> <NN> <NNP> <NNP> <NNP> <EMAIL>} #350.1
25572574
@@ -2699,6 +2716,11 @@ def build_detection_from_node(
26992716
# Companies
27002717
COMPANY: {<NAME|NAME-EMAIL|NAME-YEAR|NNP>+ <OF> <NN>? <COMPANY|COMP> <NNP>?} #770
27012718
COMPANY: {<NNP> <COMP|COMPANY> <COMP|COMPANY>} #780
2719+
# Rocket.Chat Technologies Corp. / Foo.Bar Systems Inc. (NAME-DOT + company words)
2720+
# Do NOT accept bare {NAME-DOT} as COMPANY: license prose like Assignment.This
2721+
# / Remedies.In would become fake holders. Bare Rocket.Chat still works via
2722+
# NAME-YEAR {YR-RANGE NAME-DOT} when a year is present.
2723+
COMPANY: {<NAME-DOT> <COMP|COMPANY>+} #780.1
27022724
COMPANY: {<NN>? <COMPANY|NAME|NAME-EMAIL> <CC> <COMPANY|NAME|NAME-EMAIL>} #790
27032725
COMPANY: {<COMP|COMPANY|NNP> <NN> <COMPANY|COMPANY> <NNP>+} #800
27042726
@@ -3475,6 +3497,9 @@ def build_detection_from_node(
34753497
# author (Panagiotis Tsirigotis)
34763498
AUTHOR: {<AUTH> <NNP><NNP>+} #author Foo Bar
34773499
3500+
# Author:Frankie.Chu / Author: Frankie.Chu (single mixed-case dotted name token)
3501+
AUTHOR: {<AUTH> <NAME-DOT>} #author Frankie.Chu
3502+
34783503
# Author: Tim (xtimor@gmail.com)
34793504
AUTHOR: {<AUTH> <NNP>+ <EMAIL>+} #Author Foo joe@email.com
34803505
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Date:9 April,2012
2+
// Author:Frankie.Chu
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
what:
2+
- authors
3+
- authors_summary
4+
authors:
5+
- Frankie.Chu
6+
authors_summary:
7+
- value: Frankie.Chu
8+
count: 1
9+
notes: Detect glued C++ Author:Name tags without space after colon (issue #4229)

0 commit comments

Comments
 (0)