You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Support detecting multiple product versions (#4911)
This patch refactors the core version checker code to support detecting
multiple versions of the same product in a single file. There was some
code already present that indicated an earlier intention to make this
work, but the version checker logic was written to exit early after
matching one version in a given file.
While doing this refactor, I also discovered that the version filename
parser test suite was broken, allowing faulty checkers and faulty
checker test cases to pass. I fixed the broken test, then Shan and I
fixed the handful of checkers that were found to be defective.
Roughly exhaustive list of changes:
* Rename `Checker.get_version()` to `get_versions()` to reflect its new
abilities. Replace the name across code and documentation.
* Create a new `VersionMatchInfo` class to capture the return from
`get_versions()`. For a given file, the checker will now report
whether it matched on the filename, the contents, or both, as well as a
list of all version numbers detected.
* Add some type hints! `get_versions()` is now explicit about what it returns.
Previously, the intent was to return either a dict or a list of dicts,
and the caller had to apply some fragile logic to figure out which.
* Fix the test bug caused by that fragile logic.
`TestCheckerVersionParser::test_filename_is` was failing to assert
anything when the checker returned an empty dict, and therefore was
allowing bad test cases and bad checkers alike to pass the test.
* After fixing that test, also fix the handful of filename version
checkers that were broken all along but flying under the radar.
* Update `regex_find` in `util.py` to exhaust `pattern.finditer()`
instead of exiting after finding one result with `pattern.search()`.
Return a list of strings instead of a string.
* Tweak the ignore checker logic to do a true regex search for the
ignore pattern instead of some sketchy `str(a) in str(b)` stuff. The
ignore patterns are a `list[Pattern[str]]` so we should probably be
doing actual regex lookups here.
Fixes#4184.
---------
Signed-off-by: Steve Miller <[email protected]>
Co-authored-by: Shan Lee <[email protected]>
0 commit comments