26 |
import os |
import os |
27 |
|
|
28 |
from distutils.core import setup |
from distutils.core import setup |
29 |
|
from distutils.util import change_root |
30 |
|
from distutils.sysconfig import get_python_lib |
31 |
from distutils.command.build import build |
from distutils.command.build import build |
32 |
from distutils.command.install import install |
from distutils.command.install import install |
33 |
|
from distutils.command.install_lib import install_lib |
34 |
from setupext import Data_Files, install_Data_Files |
from setupext import Data_Files, install_Data_Files |
35 |
|
|
36 |
from src import PACKAGE, VERSION |
from src import PACKAGE, VERSION |
91 |
pass |
pass |
92 |
|
|
93 |
# ----------------------------------------------------------------------------- |
# ----------------------------------------------------------------------------- |
94 |
|
# Save sys.path for later |
95 |
|
# ----------------------------------------------------------------------------- |
96 |
|
|
97 |
|
orig_sys_path = list (sys.path) # list () is needed to make a copy |
98 |
|
|
99 |
|
# ----------------------------------------------------------------------------- |
100 |
# Build files to be distributed and installed |
# Build files to be distributed and installed |
101 |
# ----------------------------------------------------------------------------- |
# ----------------------------------------------------------------------------- |
102 |
|
|
311 |
fout.close() |
fout.close() |
312 |
|
|
313 |
# --------------------------------------------------------------------------- |
# --------------------------------------------------------------------------- |
314 |
# Do it all - this is called by setu () if option install is given |
# Do it all - this is called by setup () if option install is given |
315 |
# --------------------------------------------------------------------------- |
# --------------------------------------------------------------------------- |
316 |
|
|
317 |
def finalize_options (self): |
def finalize_options (self): |
332 |
|
|
333 |
self._generate_scripts (path_line, config_line) |
self._generate_scripts (path_line, config_line) |
334 |
|
|
335 |
|
# ============================================================================= |
336 |
|
# After installation of lib, create gnue.py in python's search path |
337 |
|
# ============================================================================= |
338 |
|
|
339 |
|
class gnue_install_lib (install_lib): |
340 |
|
|
341 |
|
def run (self): |
342 |
|
install_lib.run (self) |
343 |
|
|
344 |
|
# we need gnue.py only if we don't install in python's search path |
345 |
|
if self.install_dir not in orig_sys_path: |
346 |
|
# --root parameter |
347 |
|
root = self.get_finalized_command("install").root |
348 |
|
# the location we have to add to the search path |
349 |
|
inst_dir = self.install_dir |
350 |
|
# where to install gnue.py |
351 |
|
site_dir = get_python_lib () |
352 |
|
if root: |
353 |
|
# remove --root from installation directory |
354 |
|
inst_dir = inst_dir [len(root):] |
355 |
|
# add --root to target directory for gnue.py |
356 |
|
site_dir = change_root (root, site_dir) |
357 |
|
# especially if we have --root, the directory might not exist |
358 |
|
if not os.path.isdir (site_dir): |
359 |
|
os.makedirs (site_dir) |
360 |
|
file = os.path.join (site_dir, "gnue.py") |
361 |
|
# now create the file |
362 |
|
try: |
363 |
|
output = open (file, "w") |
364 |
|
output.write ("# This file was generated during installation.\n") |
365 |
|
output.write ("import sys\n") |
366 |
|
output.write ("sys.path.insert (0, \"%s\")\n" % inst_dir) |
367 |
|
output.write ("del sys.modules [\"gnue\"]\n") |
368 |
|
output.write ("import gnue") |
369 |
|
output.close () |
370 |
|
except: |
371 |
|
# file could not be created: |
372 |
|
# simply restore original sys.path so the warning appears at the end |
373 |
|
# of the installation |
374 |
|
sys.path = orig_sys_path |
375 |
|
|
376 |
# ----------------------------------------------------------------------------- |
# ----------------------------------------------------------------------------- |
377 |
# GNUE_VERSION_SUFFIX handling |
# GNUE_VERSION_SUFFIX handling |
378 |
# ----------------------------------------------------------------------------- |
# ----------------------------------------------------------------------------- |
439 |
# Override certain command classes with our own ones |
# Override certain command classes with our own ones |
440 |
cmdclass = {"build": gnue_build, |
cmdclass = {"build": gnue_build, |
441 |
"install": gnue_install, |
"install": gnue_install, |
442 |
|
"install_lib": gnue_install_lib, |
443 |
"install_data": install_Data_Files}, |
"install_data": install_Data_Files}, |
444 |
|
|
445 |
data_files = dfiles, |
data_files = dfiles, |