Search the file at `location` for a patern regex on a single line and return this or None if not found. Reads the supplied location as text without importing it. Code inspired and heavily modified from: https://github.com/pyserial/pyserial/blob/d867871e6aa333014a77498b4ac96fdd1
(location, pattern)
| 2673 | |
| 2674 | |
| 2675 | def find_pattern(location, pattern): |
| 2676 | """ |
| 2677 | Search the file at `location` for a patern regex on a single line and return |
| 2678 | this or None if not found. Reads the supplied location as text without |
| 2679 | importing it. |
| 2680 | |
| 2681 | Code inspired and heavily modified from: |
| 2682 | https://github.com/pyserial/pyserial/blob/d867871e6aa333014a77498b4ac96fdd1d3bf1d8/setup.py#L34 |
| 2683 | SPDX-License-Identifier: BSD-3-Clause |
| 2684 | (C) 2001-2020 Chris Liechti <cliechti@gmx.net> |
| 2685 | """ |
| 2686 | with open(location) as fp: |
| 2687 | content = fp.read() |
| 2688 | |
| 2689 | match = re.search(pattern, content) |
| 2690 | if match: |
| 2691 | return match.group(1).strip() |
| 2692 | |
| 2693 | |
| 2694 | def find_dunder_version(location): |
no test coverage detected