Debian Codegraph @

version.py

raw
1 #!/usr/bin/env python
2 #
3 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4 # Copyright (c) 2022-2026 The Uncertainty Quantification Foundation.
5 # License: 3-clause BSD. The full license text is available at:
6 # - https://github.com/uqfoundation/klepto/blob/master/LICENSE
7
8 __version__ = '0.2.8'#.dev0'
9 __author__ = 'Mike McKerns'
10 __contact__ = '[email protected]'
11
12
13 def get_license_text(filepath):
14 "open the LICENSE file and read the contents"
15 try:
16 LICENSE = open(filepath).read()
17 except:
18 LICENSE = ''
19 return LICENSE
20
21
22 def get_readme_as_rst(filepath):
23 "open the README file and read the markdown as rst"
24 try:
25 fh = open(filepath)
26 name, null = fh.readline().rstrip(), fh.readline()
27 tag, null = fh.readline(), fh.readline()
28 tag = "%s: %s" % (name, tag)
29 split = '-'*(len(tag)-1)+'\n'
30 README = ''.join((null,split,tag,split,'\n'))
31 skip = False
32 for line in fh:
33 if line.startswith('['):
34 continue
35 elif skip and line.startswith(' http'):
36 README += '\n' + line
37 elif line.startswith('* '):
38 README += line.replace('* ',' - ',1)
39 elif line.startswith('-'):
40 README += line.replace('-','=') + '\n'
41 elif line.startswith('!['): # image
42 alt,img = line.split('](',1)
43 if img.startswith('docs'): # relative path
44 img = img.split('docs/source/',1)[-1] # make is in docs
45 README += '.. image:: ' + img.replace(')','')
46 README += ' :alt: ' + alt.replace('![','') + '\n'
47 #elif ')[http' in line: # alt text link (`text <http://url>`_)
48 else:
49 README += line
50 skip = line.endswith(':\n')
51 fh.close()
52 except:
53 README = ''
54 return README
55
56
57 def write_info_file(dirpath, modulename, **info):
58 """write the given info to 'modulename/__info__.py'
59
60 info expects:
61 doc: the module's long_description
62 version: the module's version string
63 author: the module's author string
64 license: the module's license contents
65 """
66 import os
67 infofile = os.path.join(dirpath, '%s/__info__.py' % modulename)
68 header = '''#!/usr/bin/env python
69 #
70 # Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
71 # Copyright (c) 2026 The Uncertainty Quantification Foundation.
72 # License: 3-clause BSD. The full license text is available at:
73 # - https://github.com/uqfoundation/%s/blob/master/LICENSE
74 ''' % modulename #XXX: author and email are hardwired in the header
75 doc = info.get('doc', None)
76 version = info.get('version', None)
77 author = info.get('author', None)
78 license = info.get('license', None)
79 with open(infofile, 'w') as fh:
80 fh.write(header)
81 if doc is not None: fh.write("'''%s'''\n\n" % doc)
82 if version is not None: fh.write("__version__ = %r\n" % version)
83 if author is not None: fh.write("__author__ = %r\n\n" % author)
84 if license is not None: fh.write("__license__ = '''\n%s'''\n" % license)
85 return