Repository navigation
Skip unnecessary regex matching for emails and URLs - #5408
Shrashti1234 wants to merge 3 commits into
Conversation
Add an optional line prefilter to the shared finder. Skip email matching without @ and URL matching without a scheme separator or dot, preserving generic pattern searches and source line numbers. Fixes aboutcode-org#595 Assisted-by: OpenAI Codex Signed-off-by: Shrashti1234 <sharishhtia@gmail.com>
|
Took a look through the changes in \cluecode/finder.py\ and tested the prefilter logic. Adding the optional \prefilter\ check directly inside the Filtering for @\ before running the email regex and requiring either ://\ or .\ for URLs catches the vast majority of non-matching lines early. Testing this against plain text lines confirms it avoids regex calls as intended, while still keeping coverage for scheme-based URLs without dots (like \http://localhost\) as well as scheme-less hostnames. The unit tests in \ est_finder.py\ verifying \pattern.findall.call_args_list\ make the skipped invocations easy to verify. Nice work on this fix! |
Both reference rules contain the FSL template URL but did not declare it in ignorable_urls. This caused the license_validate_ignorables_2 CI job to fail before the finder optimization as well. Register the detected URL so the metadata agrees with the existing validator. Assisted-by: OpenAI Codex Signed-off-by: Shrashti1234 <sharishhtia@gmail.com>
Update pytest-xdist to 3.8.0 and execnet to 2.1.1. The older pinned runner can schedule tests outside the interpreter main thread, causing POSIX SIGALRM timeout tests to fail with ValueError. xdist 3.6 introduced the main_thread_only execution model; 3.8 retains that fix and supports all Python versions used here. Validated the finder, scanner integration, API email/URL, and interrupt tests with three workers: 388 passed and two expected failures on Windows/Python 3.14.2. POSIX validation is left to the hosted CI jobs. Assisted-by: OpenAI Codex Signed-off-by: Shrashti1234 <sharishhtia@gmail.com>
Fixes #595.
Email and URL extraction currently runs its regular expression on every text line. Add an optional prefilter to
find()so email extraction skips lines without@, and URL extraction skips lines containing neither://nor..The URL check is deliberately conservative: scheme-based URLs, including dotless hosts and IP literals, pass through
://; scheme-less www/ftp prefixes and git-style URLs ending in .git pass through the dot check. Existing extraction, filtering, uniqueness, and source line numbers are unchanged. Generic pattern searches retain their existing behavior when no prefilter is supplied.Add regression tests that check actual detections and regex invocation counts, plus coverage for generic pattern searches. Update the changelog and contributor list.
The first CI run also exposed two pre-existing license metadata failures. A separate follow-up commit registers the missing FSL template URL as an ignorable clue in
fsl-1.1_1.RULEandfsl-1.1_2.RULE. The same failures are present in the unmodified base build. Both rules now pass a direct comparison ofmodels.get_ignorables(rule.text)withmodels.get_normalized_ignorables(rule), matching the CI validator's comparison. Tests remain enabled.The other failed CI group reported
ValueError: signal only works in main thread. The pinned pytest-xdist 2.5.0/execnet 1.9.0 combination can run worker tests outside the main thread. Update those test-only pins to pytest-xdist 3.8.0 and execnet 2.1.1, which use themain_thread_onlyworker execution model introduced in xdist 3.6. See the upstream changelog. No tests have been disabled.Validation
Windows 11, CPython 3.14.2:
python -m pytest tests/cluecode/test_finder.py -q: 63 passed, 2 expected failures.python -m pytest tests/cluecode/test_plugin_email_url.py tests/cluecode/test_finder_data.py tests/scancode/test_api.py -q -k "email or url": 321 passed.git diff --check: passed._find_testerhelper already triggers D401.python -m pytest -n 3 tests/cluecode/test_finder.py tests/cluecode/test_plugin_email_url.py tests/cluecode/test_finder_data.py tests/scancode/test_interrupt.py tests/scancode/test_api.py -q -k 'finder or email or url or interrupt': 388 passed, 2 expected failures.Hosted CI result
Azure build 19676 completed successfully with 30/30 jobs passed. GitHub reports 32/32 successful checks, including DCO and the aggregate pipeline check, and the documentation build is also successful. This validates the test-runner and rule-metadata corrections alongside the finder optimization.
Performance measurement
Compared against
05a98f66b4b07290fd34325b694aa59069bc3e71using all 165 Python files under src/, excluding_vendordirectories. Loaded the original finder and modified finder into the same interpreter, warmed file/type-detection caches, then alternated three baseline and modified batches for each mode. Each batch calledfind_emails()and/orfind_urls()on every file and materialized the results.Median batch times:
Every batch produced identical detections and line numbers. These measurements cover finder calls on this source corpus; they are not timings for a full CLI scan or a Linux/LibreOffice corpus.
AI disclosure: OpenAI Codex implemented this change, wrote the tests and PR description, and ran the validation at my request.
Tasks
9a98644857001467329ac74a68689e64c2a95f0b.