-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
112 lines (94 loc) · 4.26 KB
/
setup.py
File metadata and controls
112 lines (94 loc) · 4.26 KB
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
#!/usr/bin/env python3
from __future__ import print_function
import distutils.core, \
distutils.command.install, \
distutils.command.install_data, \
distutils.command.build_py
import os, sys
PACKAGE_NAME = 'new_script'
## @TODO Figure out how this should get set by default. (Maybe
## initialize it to $HOME/.local ?)
_prefix = None
class MyInstall(distutils.command.install.install):
def run(self, *args, **kwargs):
'''Persist the installation prefix so that it can be used in
:class:`MyBuildPy. <MyBuildPy>`
'''
assert not (self.home is not None and self.prefix is not None), \
'distutils enforces that either home or prefix is specified, ' \
' but not both.'
global _prefix
if self.home is not None:
_prefix = self.home
elif self.prefix is not None:
_prefix = self.prefix
_prefix = os.path.abspath(os.path.expanduser(_prefix))
#return super().run(*args, **kwargs)
return distutils.command.install.install.run(self, *args, **kwargs)
class MyInstallData(distutils.command.install_data.install_data):
def run(self, *args, **kwargs):
'''Create a directory for log files.
'''
dirs = (os.path.join(self.install_dir, 'var', 'log', PACKAGE_NAME),
)
for target in dirs:
if not os.path.isdir(target):
print('creating', target)
os.makedirs(target)
#return super().run(*args, **kwargs)
return distutils.command.install_data.install_data.run(self, *args,
**kwargs)
class MyBuildPy(distutils.command.build_py.build_py):
def run(self, *args, **kwargs):
'''Create a local_conf.py file that supplies where the program is
installed. This functionality is helpful for
e.g. automatically inferring the location of config files.
(Playing games with the __file__ variable may not work for all
systems.) We write it to our own lib directory so that the
build_py machinery autodiscovers local_conf.py and does all
the usual stuff and copies into the build/ directory.
'''
ret = None
thisDir = os.path.dirname(__file__)
filename = os.path.join(thisDir, 'bin', PACKAGE_NAME, 'local_conf.py')
try:
print('Writing:', filename)
with open(filename, 'w') as fout:
fout.write("prefix='{prefix}'\nversion='{version}'\n"
"".format(prefix=_prefix, version=version))
#ret = super().run(*args, **kwargs)
ret = distutils.command.build_py.build_py.run(self, *args,
**kwargs)
finally:
print('Deleting:', filename)
os.remove(filename)
pass
return ret
with open(os.path.join(os.path.dirname(__file__), 'VERSION')) as fin:
version = fin.read().strip()
distutils.core.setup(name=PACKAGE_NAME,
version=version,
description='Do something.',
author='John Doe',
author_email='john.doe@example.com',
url='example.com',
cmdclass={'install_data':MyInstallData,
'build_py':MyBuildPy,
'install':MyInstall,
},
package_dir={PACKAGE_NAME:os.path.join('bin',PACKAGE_NAME),
},
packages=[PACKAGE_NAME,
],
scripts=[os.path.join('bin', 'script'),
],
# Note: We can't use package_data for stuff in
# share because relative paths don't play well
# with it.
#package_data={PACKAGE_NAME:['test.dat']},
data_files=[(os.path.join('etc', PACKAGE_NAME),
[os.path.join('etc', PACKAGE_NAME,
'script_logging.conf'),
],
)],
)