File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- #!/usr/bin/env python
2-
3- import codecs
1+ import ast
42import os .path
3+ import re
54
65from setuptools import setup
76
87
9- def read (rel_path ):
10- here = os .path .abspath (os .path .dirname (__file__ ))
11- with codecs .open (os .path .join (here , rel_path ), 'r' ) as fp :
12- return fp .read ()
13-
14-
15- def get_version (rel_path ):
16- for line in read (rel_path ).splitlines ():
17- if line .startswith ('__version__' ):
18- delim = '"' if '"' in line else "'"
19- return line .split (delim )[1 ]
20- else :
21- raise RuntimeError ("Unable to find version string." )
8+ def get_version (rel_path : str ) -> str :
9+ """
10+ Parse a version string from a __version__ = ... line in the given file.
11+ """
12+ with open (os .path .join (os .path .dirname (__file__ ), rel_path )) as infp :
13+ match = re .search ("__version__ = (.+?)$" , infp .read (), re .M )
14+ if not match :
15+ raise ValueError ("No version could be found" )
16+ return ast .literal_eval (match .group (1 ))
2217
2318
2419with open ('README.md' ) as f :
You can’t perform that action at this time.
0 commit comments