/
setup.py
executable file
·169 lines (144 loc) · 5.51 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# For further info, check http://www.prymatex.org/
"""Build tar.gz for prymatex.
Needed packages to run (using Debian/Ubuntu package names):
"""
import sys, os
from distutils.command.install import install
from distutils.command.build import build
from distutils.core import setup
#======================================
# VALIDATE THE NEEDED MODULES
#======================================
# This modules can't be easy installed
# Syntax: [(module, url of the tutorial)...]
if sys.platform == 'win32':
NEEDED_MODULES = [("PyQt4",
"http://www.riverbankcomputing.co.uk/software/pyqt/intro"),
('win32con', "http://sourceforge.net/projects/pywin32/files/pywin32/")]
else:
NEEDED_MODULES = [("PyQt4",
"http://www.riverbankcomputing.co.uk/software/pyqt/intro"), ]
for mn, urlm in NEEDED_MODULES:
try:
__import__(mn)
except ImportError:
print(("Module '%s' not found. For more details: '%s'.\n" % (mn, urlm)))
sys.exit(1)
class CustomInstall(install):
"""Custom installation class on package files.
It copies all the files into the "PREFIX/share/PROJECTNAME" dir.
"""
def run(self):
"""Run parent install, and then save the install dir in the script."""
install.run(self)
for script in self.distribution.scripts:
script_path = os.path.join(self.install_scripts, os.path.basename(script))
with open(script_path, 'rb') as fh:
content = fh.read()
content = content.replace('@ INSTALLED_BASE_DIR @', self._custom_data_dir)
with open(script_path, 'wb') as fh:
fh.write(content)
def finalize_options(self):
"""Alter the installation path."""
install.finalize_options(self)
data_dir = os.path.join(self.prefix, "share", self.distribution.get_name())
# if we have 'root', put the building path also under it (used normally by pbuilder)
if self.root is None:
build_dir = data_dir
else:
build_dir = os.path.join(self.root, data_dir[1:])
# change the lib install directory so all package files go inside here
self.install_lib = build_dir
# save this custom data dir to later change the scripts
self._custom_data_dir = data_dir
def fullsplit(path, result=None):
"""
Split a pathname into components (the opposite of os.path.join) in a platform-neutral way.
"""
if result is None:
result = []
head, tail = os.path.split(path)
if head == '':
return [tail] + result
if head == path:
return result
return fullsplit(head, [tail] + result)
# Compile the list of packages available, because distutils doesn't have an easy way to do this.
packages, package_data = [], {}
root_dir = os.path.dirname(__file__)
if root_dir != '':
os.chdir(root_dir)
prymatex_dir = 'prymatex'
share_dir = os.path.join('prymatex', 'share')
for dirpath, dirnames, filenames in os.walk(prymatex_dir):
# Ignore dirnames that start with '.'
for i, dirname in enumerate(dirnames):
if dirname.startswith('.'): del dirnames[i]
# Ignore share dir
if dirpath.startswith(share_dir):
continue
if '__init__.py' in filenames:
package = '.'.join(fullsplit(dirpath))
packages.append(package)
package_data.setdefault(package, [])
elif filenames:
#Find package
parts = fullsplit(dirpath)
while '.'.join(parts) not in packages:
parts = parts[:-1]
#Build patterns
patterns = []
for file in filenames:
name, ext = os.path.splitext(file)
pattern = '*%s' % ext
if not ext:
patterns.append(name)
elif pattern not in patterns:
patterns.append(pattern)
#Build basename
basename = os.path.join(*fullsplit(dirpath)[1:])
package_data['.'.join(parts)].extend([os.path.join(basename, p) for p in patterns])
import prymatex
setup(
name = prymatex.__name__,
version = str(prymatex.__version__.replace(' ', '-')),
license = prymatex.__license__,
author = prymatex.__author__,
author_email = prymatex.__mail__,
description = prymatex.__doc__,
url = prymatex.__url__,
long_description=open('README.txt').read(),
packages = packages,
package_data = package_data,
scripts = ['bin/prymatex.py', 'bin/pmx'],
keywords = "editor python prymatex development",
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: X11 Applications",
"Topic :: Text Editors",
"Topic :: Utilities",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
],
install_requires = [
'regex',
],
cmdclass = {
'install': CustomInstall
}
)