MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / find_pattern

Function find_pattern

src/packagedcode/pypi.py:2675–2691  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2673
2674
2675def 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
2694def find_dunder_version(location):

Callers 3

find_dunder_versionFunction · 0.70
find_plain_versionFunction · 0.70

Calls 3

groupMethod · 0.80
readMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected