-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup.py
executable file
·150 lines (117 loc) · 3.59 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python
from __future__ import print_function
import warnings
warnings.filterwarnings('ignore')
from distutils.core import setup
from distutils.command.sdist import sdist as _sdist
from distutils.command.build import build as _build
from distutils.command.clean import clean as _clean
import os
import g_octave
current_dir = os.path.dirname(os.path.realpath(__file__))
manpages = {
'g-octave.1.rst': 'g-octave.1',
}
html = {
'README.rst': 'g-octave.html',
}
outputs = list(manpages.values()) + list(html.values())
def bdoc():
try:
from docutils import core
except ImportError:
return
from codecs import open
from io import StringIO
from datetime import date
print('building the manpages')
for rst in manpages:
path_rst = os.path.join(current_dir, rst)
path = os.path.join(current_dir, manpages[rst])
man_rst = open(path_rst, 'r', encoding='utf-8')
manpage = man_rst.read()
man_rst.close()
man_tmp = StringIO(manpage % {
'author_email': g_octave.__email__,
'date': date.today().strftime('%Y-%m-%d'),
'copyright': g_octave.__author__,
'version': g_octave.__version__,
})
man = open(path, 'w', encoding='utf-8')
try:
core.publish_file(
source = man_tmp,
source_path = path_rst,
destination = man,
destination_path = path,
writer_name = 'manpage',
)
man_tmp.close()
man.close()
except Exception as error:
raise RuntimeError('Failed to build the manpage: %s' % error)
print('building the html docs')
for rst in html:
path_rst = os.path.join(current_dir, rst)
path = os.path.join(current_dir, html[rst])
readme_rst = open(path_rst, 'r', encoding='utf-8')
readme = open(path, 'w', encoding='utf-8')
try:
core.publish_file(
source = readme_rst,
source_path = path_rst,
destination = readme,
destination_path = path,
writer_name = 'html',
)
readme_rst.close()
readme.close()
except Exception as error:
raise RuntimeError('Failed to build the html doc: %s' % error)
class sdist(_sdist):
def run(self):
bdoc()
_sdist.run(self)
class build(_build):
def run(self):
_build.run(self)
for i in outputs:
if os.path.exists(os.path.join(current_dir, i)):
return
bdoc()
class clean(_clean):
def run(self):
_clean.run(self)
if self.all:
for i in outputs:
my_path = os.path.join(current_dir, i)
if os.path.exists(my_path):
print('removing %s' % my_path)
os.remove(my_path)
setup(
name = 'g-octave',
version = g_octave.__version__,
license = g_octave.__license__,
description = g_octave.__description__,
long_description = open('README.rst').read(),
author = g_octave.__author__,
author_email = g_octave.__email__,
url = g_octave.__url__,
packages = ['g_octave'],
scripts = ['scripts/g-octave'],
data_files = [
('/etc', ['etc/g-octave.cfg']),
('share/g-octave', ['share/g-octave.eclass']),
('share/g-octave/contrib', [
'contrib/manage_pkgdb.py',
'contrib/manage_info.py',
'contrib/tinderbox.py',
]),
],
requires = ['portage'],
cmdclass = {
'sdist': sdist,
'build': build,
'clean': clean,
}
)