Stack metadata version 4
[stgit.git] / setup.py
blob7ed43e9e0eaeea2c4ca33481d4b1d23030fa1b10
1 #!/usr/bin/env python3
2 import os
3 import sys
4 from distutils.core import setup
5 from glob import glob
7 from stgit import commands, version
8 from stgit.completion.bash import write_bash_completion
9 from stgit.completion.fish import write_fish_completion
12 def __version_to_list(version):
13 """Convert a version string to a list of numbers or strings"""
14 ver_list = []
15 for p in version.split('.'):
16 try:
17 n = int(p)
18 except ValueError:
19 n = p
20 ver_list.append(n)
21 return ver_list
24 def __check_min_version(min_ver, ver):
25 """Check whether ver is greater or equal to min_ver"""
26 min_ver_list = __version_to_list(min_ver)
27 ver_list = __version_to_list(ver)
28 return min_ver_list <= ver_list
31 def __check_python_version():
32 """Check the minimum Python version"""
33 pyver = '.'.join(map(str, sys.version_info))
34 if not __check_min_version(version.python_min_ver, pyver):
35 print(
36 'Python version %s or newer required. Found %s'
37 % (version.python_min_ver, pyver),
38 file=sys.stderr,
40 sys.exit(1)
43 def __check_git_version():
44 """Check the minimum GIT version"""
45 from stgit.run import Run
47 gitver = Run('git', '--version').output_one_line().split()[2]
48 if not __check_min_version(version.git_min_ver, gitver):
49 print(
50 'GIT version %s or newer required. Found %s'
51 % (version.git_min_ver, gitver),
52 file=sys.stderr,
54 sys.exit(1)
57 # Check the minimum versions required
58 __check_python_version()
59 __check_git_version()
61 # ensure readable template files
62 old_mask = os.umask(0o022)
64 for get_ver in [
65 version.git_describe_version,
66 version.git_archival_version,
67 version.get_builtin_version,
69 try:
70 ver = get_ver()
71 except version.VersionUnavailable:
72 continue
73 else:
74 break
75 else:
76 print('StGit version unavailable', file=sys.stderr)
77 sys.exit(1)
79 with open('stgit/builtin_version.py', 'w') as f:
80 print(
81 '# This file is automatically generated. Do not edit.',
82 'version = {ver!r}'.format(ver=ver),
83 sep='\n',
84 file=f,
87 # generate the python command list
88 with open('stgit/commands/cmdlist.py', 'w') as f:
89 commands.py_commands(commands.get_commands(allow_cached=False), f)
91 if not os.path.exists('completion'):
92 os.mkdir('completion')
94 # generate the bash completion script
95 with open(os.path.join('completion', 'stgit.bash'), 'w') as f:
96 write_bash_completion(f)
98 # generate the fish completion script
99 with open(os.path.join('completion', 'stg.fish'), 'w') as f:
100 write_fish_completion(f)
102 setup(
103 name='stgit',
104 version=ver,
105 license='GPLv2',
106 author='Catalin Marinas',
107 author_email='catalin.marinas@gmail.com',
108 url='http://stacked-git.github.io',
109 download_url='https://github.com/stacked-git/stgit.git',
110 description='Stacked Git',
111 long_description='Application for managing Git commits as a stack of patches.',
112 scripts=['stg'],
113 packages=list(
114 map(
115 str,
117 'stgit',
118 'stgit.commands',
119 'stgit.completion',
120 'stgit.lib',
121 'stgit.lib.git',
125 data_files=[
126 ('share/stgit/templates', glob('stgit/templates/*.tmpl')),
127 ('share/stgit/examples', glob('examples/*.tmpl')),
128 ('share/stgit/examples', ['examples/gitconfig']),
129 ('share/stgit/contrib', ['contrib/stgbashprompt.sh']),
130 ('share/stgit/completion', ['completion/stg.fish']),
131 ('share/stgit/completion', ['completion/stgit.bash']),
132 ('share/stgit/completion', ['completion/stgit.zsh']),
134 package_data={
135 'stgit': [
136 'templates/covermail.tmpl',
137 'templates/mailattch.tmpl',
138 'templates/patchandattch.tmpl',
139 'templates/patchexport.tmpl',
140 'templates/patchmail.tmpl',
143 classifiers=[
144 'Development Status :: 5 - Production/Stable',
145 'Environment :: Console',
146 'Intended Audience :: Developers',
147 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)'
148 'Natural Language :: English',
149 'Operating System :: OS Independent',
150 'Programming Language :: Python',
151 'Programming Language :: Python :: 3',
152 'Programming Language :: Python :: 3.5',
153 'Programming Language :: Python :: 3.6',
154 'Programming Language :: Python :: 3.7',
155 'Programming Language :: Python :: 3.8',
156 'Programming Language :: Python :: 3.9',
157 'Programming Language :: Python :: Implementation :: CPython',
158 'Programming Language :: Python :: Implementation :: PyPy',
159 'Topic :: Software Development :: Version Control',
163 # restore the old mask
164 os.umask(old_mask)