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

Function find_dunder_version

src/packagedcode/pypi.py:2694–2707  ·  view source on GitHub ↗

Return a "dunder" __version__ string or None from searching the module file at `location`. Code inspired and heavily modified from: https://github.com/pyserial/pyserial/blob/d867871e6aa333014a77498b4ac96fdd1d3bf1d8/setup.py#L34 SPDX-License-Identifier: BSD-3-Clause (C) 2001

(location)

Source from the content-addressed store, hash-verified

2692
2693
2694def find_dunder_version(location):
2695 """
2696 Return a "dunder" __version__ string or None from searching the module file
2697 at `location`.
2698
2699 Code inspired and heavily modified from:
2700 https://github.com/pyserial/pyserial/blob/d867871e6aa333014a77498b4ac96fdd1d3bf1d8/setup.py#L34
2701 SPDX-License-Identifier: BSD-3-Clause
2702 (C) 2001-2020 Chris Liechti <cliechti@gmx.net>
2703 """
2704 pattern = re.compile(r"^__version__\s*=\s*['\"]([^'\"]*)['\"]", re.MULTILINE)
2705 match = find_pattern(location, pattern)
2706 if TRACE: logger_debug('find_dunder_version:', 'location:', location, 'match:', match)
2707 return match
2708
2709
2710def find_plain_version(location):

Callers 1

detect_version_attributeFunction · 0.85

Calls 2

find_patternFunction · 0.70
logger_debugFunction · 0.70

Tested by

no test coverage detected