forked from pyre/pyre
-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure
executable file
·216 lines (181 loc) · 5.57 KB
/
configure
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# michael a.g. aïvázis
# orthologue
# (c) 1998-2020 all rights reserved
#
# externals
import datetime, os, sys
# the location of project configuration files
pdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '.mm'))
# if it doesn't exist, make it
os.makedirs(pdir, exist_ok=True)
# attempt to
try:
# access the framework
import pyre
# if this fails
except ImportError:
# the resource
boot = 'pyre-1.0-boot.zip'
# the local file
local = os.path.join(pdir, boot)
# if it not already here
if not os.path.exists(local):
# support for URL access
import urllib.request
# form the url to the bootstrapper
url = 'http://pyre.orthologue.com/' + boot
# show me
print('downloading {!r}'.format(url))
# pull the bootstrapper from the web
with urllib.request.urlopen(url=url) as ins:
# open the local file
with open(local, 'wb') as outs:
# pull the data and write it
outs.write(ins.read())
# grab the sys module
import sys
# so we can add the bootstrapper to it
sys.path.insert(1, local)
# try importing pyre again
import pyre
# the app
class configure(pyre.application, family='pyre.applications.configure'):
"""
The pyre configuration utility
"""
# user configurable state
# packages
gsl = pyre.externals.gsl()
gsl.doc = "the GSL installation"
mpi = pyre.externals.mpi()
mpi.doc = "the MPI installation"
postgres = pyre.externals.postgres()
postgres.doc = "the client side of postgres"
python = pyre.externals.python()
python = pyre.externals.python()
python.doc = "the python installation"
# geography
config = pyre.properties.path(default=os.path.join(pdir, 'config.def'))
config.doc = 'the path to the configuration file'
# behavior
@pyre.export
def main(self, *args, **kwds):
"""
The main entry point
"""
# render the configuration in {mm} format
table = self.render()
# save the configuration
self.save(table=table)
# all done
return 0
# implementation
def render(self, table=None):
"""
Create a table with the {mm} settings for the given choices of packages
"""
# initialize
table = table or {}
# gsl
gsl = self.gsl
# update the table
if gsl:
table['GSL_DIR'] = gsl.prefix
table['GSL_VERSION'] = gsl.sigver
table['GSL_INCDIR'] = gsl.join(gsl.incdir)
table['GSL_LIBDIR'] = gsl.join(gsl.libdir)
# mpi
mpi = self.mpi
# update the table
if mpi:
table['MPI_DIR'] = mpi.prefix
table['MPI_INCDIR'] = mpi.join(mpi.incdir)
table['MPI_LIBDIR'] = mpi.join(mpi.libdir)
table['MPI_EXECUTIVE'] = mpi.launcher
table['MPI_VERSION'] = mpi.flavor
# postgres
postgres = self.postgres
# update the table
if postgres:
table['LIBPQ_DIR'] = postgres.prefix
table['LIBPQ_VERSION'] = postgres.sigver
table['LIBPQ_INCDIR'] = postgres.join(postgres.incdir)
table['LIBPQ_LIBDIR'] = postgres.join(postgres.libdir)
# python
python = self.python
# update the table
if python:
table['PYTHON'] = python.interpreter
table['PYTHON_DIR'] = python.prefix
table['PYTHON_INCDIR'] = python.join(python.incdir)
table['PYTHON_LIBDIR'] = python.join(python.libdir)
table['PYTHON_PYCFLAGS'] = '-b'
table['PYTHON_LIB'] = python.interpreter
# all done
return table
def save(self, table):
"""
Generate the file with the configuration options
"""
# open the output stream
stream = self.config.open('w')
# assemble the document
doc = '\n'.join(self.assemble(table))
# print
print(doc, file=stream)
# all done
return table
def assemble(self, table):
"""
Generate the file with the configuration settings
"""
# build a time stamp
stamp = datetime.datetime.now().ctime()
# render a preamble
yield "# -*- Makefile -*-"
yield "#"
yield "# generated by configure on {}".format(stamp)
yield "#"
yield ""
# go through all the variable names
for key in sorted(table):
# and print their values
yield '{} = {}'.format(key, table[key])
# epilogue
yield ""
yield "# end of file"
# all done
return
# pyre framework hooks
# support for the help system
def pyre_banner(self):
"""
Place the application banner in the {info} channel
"""
# show the license header
return 'configuration utility'
# interactive session management
def pyre_interactiveSessionContext(self, context):
"""
Go interactive
"""
# protect against bad contexts
if context is None:
# by initializing as an empty dict
context = {}
# set up some context
context['config'] = self
# and chain up
return super().pyre_interactiveSessionContext(context=context)
# main
if __name__ == "__main__":
# make an instance
app = configure(name='configure')
# ride
status = app.run()
# all done
raise SystemExit(status)
# end of file