Add formal handling of file pattern matching for tools.

Review Request #11531 — Created March 17, 2021 and submitted

Information

ReviewBot
release-3.0.x

Reviewers

Most tools only operate on certain file types, and all tools had to
implement their own logic for this. This meant that some were checking
if a file ends with a pattern, some were splitting file extensions, and
not all could agree on case-sensitive vs. case-insensitive matching.

In an attempt to standardize this, a new
BaseTool.get_can_handle_file() method has been added, which defaults
to checking a new BaseTool.file_patterns for glob patterns.

Comparison is case-insensitive. This is the right default behavior, but
subclasses can always override get_can_handle_file() to perform their
own logic, or continue just checking directly in handle_file() as they
have in the past.

We can extend this further down the road, if needed, to support other
entries in file_patterns, such as compiled regex objects, to extend
capabilities in a consistent way.

As of this change, no tool uses this new functionality, but changes will
be made to add support over time.

Unit tests passed.

Did some light testing with other in-progress tool work.

Summary ID
Add formal handling of file pattern matching for tools.
Most tools only operate on certain file types, and all tools had to implement their own logic for this. This meant that some were checking if a file ends with a pattern, some were splitting file extensions, and not all could agree on case-sensitive vs. case-insensitive matching. In an attempt to standardize this, a new `BaseTool.get_can_handle_file()` method has been added, which defaults to checking a new `BaseTool.file_patterns` for glob patterns. Comparison is case-insensitive. This is the right default behavior, but subclasses can always override `get_can_handle_file()` to perform their own logic, or continue just checking directly in `handle_file()` as they have in the past. We can extend this further down the road, if needed, to support other entries in `file_patterns`, such as compiled regex objects, to extend capabilities in a consistent way. As of this change, no tool uses this new functionality, but changes will be made to add support over time.
885696bebf6d1c424b2a5500068c93e9ef6da7fd
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-3.0.x (59bb335)