25 import os |
25 import os |
26 import sys |
26 import sys |
27 import shutil |
27 import shutil |
28 from os.path import exists, join, dirname |
28 from os.path import exists, join, dirname |
29 |
29 |
30 try: |
30 from setuptools import setup |
31 if os.environ.get('NO_SETUPTOOLS'): |
31 from setuptools.command import install_lib |
32 raise ImportError() # do as there is no setuptools |
|
33 from setuptools import setup |
|
34 from setuptools.command import install_lib |
|
35 USE_SETUPTOOLS = True |
|
36 except ImportError: |
|
37 from distutils.core import setup |
|
38 from distutils.command import install_lib |
|
39 USE_SETUPTOOLS = False |
|
40 from distutils.command import install_data |
32 from distutils.command import install_data |
41 |
33 |
42 |
34 |
43 # load metadata from the __pkginfo__.py file so there is no risk of conflict |
35 # load metadata from the __pkginfo__.py file so there is no risk of conflict |
44 # see https://packaging.python.org/en/latest/single_source_version.html |
36 # see https://packaging.python.org/en/latest/single_source_version.html |
66 include_dirs = pkginfo.get('include_dirs', ()) |
58 include_dirs = pkginfo.get('include_dirs', ()) |
67 data_files = pkginfo.get('data_files', None) |
59 data_files = pkginfo.get('data_files', None) |
68 ext_modules = pkginfo.get('ext_modules', None) |
60 ext_modules = pkginfo.get('ext_modules', None) |
69 dependency_links = pkginfo.get('dependency_links', ()) |
61 dependency_links = pkginfo.get('dependency_links', ()) |
70 |
62 |
71 if USE_SETUPTOOLS: |
63 requires = {} |
72 requires = {} |
64 for entry in ("__depends__",): # "__recommends__"): |
73 for entry in ("__depends__",): # "__recommends__"): |
65 requires.update(pkginfo.get(entry, {})) |
74 requires.update(pkginfo.get(entry, {})) |
66 install_requires = [("%s %s" % (d, v and v or "")).strip() |
75 install_requires = [("%s %s" % (d, v and v or "")).strip() |
67 for d, v in requires.items()] |
76 for d, v in requires.items()] |
|
77 else: |
|
78 install_requires = [] |
|
79 |
68 |
80 BASE_BLACKLIST = ('CVS', '.svn', '.hg', '.git', 'debian', 'dist', 'build') |
69 BASE_BLACKLIST = ('CVS', '.svn', '.hg', '.git', 'debian', 'dist', 'build') |
81 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~') |
70 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~') |
82 |
71 |
83 |
72 |
145 export(directory, dest, verbose=False) |
134 export(directory, dest, verbose=False) |
146 |
135 |
147 |
136 |
148 # re-enable copying data files in sys.prefix |
137 # re-enable copying data files in sys.prefix |
149 old_install_data = install_data.install_data |
138 old_install_data = install_data.install_data |
150 if USE_SETUPTOOLS: |
139 # overwrite InstallData to use sys.prefix instead of the egg directory |
151 # overwrite InstallData to use sys.prefix instead of the egg directory |
140 class MyInstallData(old_install_data): |
152 class MyInstallData(old_install_data): |
141 """A class that manages data files installation""" |
153 """A class that manages data files installation""" |
142 def run(self): |
154 def run(self): |
143 _old_install_dir = self.install_dir |
155 _old_install_dir = self.install_dir |
144 if self.install_dir.endswith('egg'): |
156 if self.install_dir.endswith('egg'): |
145 self.install_dir = sys.prefix |
157 self.install_dir = sys.prefix |
146 old_install_data.run(self) |
158 old_install_data.run(self) |
147 self.install_dir = _old_install_dir |
159 self.install_dir = _old_install_dir |
148 try: |
160 try: |
149 # only if easy_install available |
161 # only if easy_install available |
150 import setuptools.command.easy_install # noqa |
162 import setuptools.command.easy_install # noqa |
151 # monkey patch: Crack SandboxViolation verification |
163 # monkey patch: Crack SandboxViolation verification |
152 from setuptools.sandbox import DirectorySandbox as DS |
164 from setuptools.sandbox import DirectorySandbox as DS |
153 old_ok = DS._ok |
165 old_ok = DS._ok |
|
166 |
154 |
167 def _ok(self, path): |
155 def _ok(self, path): |
168 """Return True if ``path`` can be written during installation.""" |
156 """Return True if ``path`` can be written during installation.""" |
169 out = old_ok(self, path) # here for side effect from setuptools |
157 out = old_ok(self, path) # here for side effect from setuptools |
170 realpath = os.path.normcase(os.path.realpath(path)) |
158 realpath = os.path.normcase(os.path.realpath(path)) |
171 allowed_path = os.path.normcase(sys.prefix) |
159 allowed_path = os.path.normcase(sys.prefix) |
172 if realpath.startswith(allowed_path): |
160 if realpath.startswith(allowed_path): |
173 out = True |
161 out = True |
174 return out |
162 return out |
175 DS._ok = _ok |
163 DS._ok = _ok |
176 except ImportError: |
164 except ImportError: |
177 pass |
165 pass |
178 |
166 |
179 |
167 |
180 def install(**kwargs): |
168 def install(**kwargs): |
181 """setup entry point""" |
169 """setup entry point""" |
182 if USE_SETUPTOOLS: |
170 if '--force-manifest' in sys.argv: |
183 if '--force-manifest' in sys.argv: |
171 sys.argv.remove('--force-manifest') |
184 sys.argv.remove('--force-manifest') |
|
185 # install-layout option was introduced in 2.5.3-1~exp1 |
172 # install-layout option was introduced in 2.5.3-1~exp1 |
186 elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv: |
173 elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv: |
187 sys.argv.remove('--install-layout=deb') |
174 sys.argv.remove('--install-layout=deb') |
188 cmdclass = {'install_lib': MyInstallLib} |
175 cmdclass = {'install_lib': MyInstallLib} |
189 if USE_SETUPTOOLS: |
176 kwargs['install_requires'] = install_requires |
190 kwargs['install_requires'] = install_requires |
177 kwargs['dependency_links'] = dependency_links |
191 kwargs['dependency_links'] = dependency_links |
178 kwargs['zip_safe'] = False |
192 kwargs['zip_safe'] = False |
179 cmdclass['install_data'] = MyInstallData |
193 cmdclass['install_data'] = MyInstallData |
|
194 |
180 |
195 return setup(name=distname, |
181 return setup(name=distname, |
196 version=version, |
182 version=version, |
197 license=license, |
183 license=license, |
198 description=description, |
184 description=description, |