##// END OF EJS Templates
Refer to Setuptools instead of Distribute
Christoph Gohlke -
Show More
@@ -1,148 +1,148 b''
1 1 #!python
2 2 """Distutils post installation script for Windows.
3 3
4 4 http://docs.python.org/2/distutils/builtdist.html#the-postinstallation-script
5 5
6 6 """
7 7
8 8 from __future__ import print_function
9 9
10 10 import os
11 11 import sys
12 12 import shutil
13 13
14 14 try:
15 15 import setuptools
16 16 have_setuptools = True
17 17 except ImportError:
18 18 have_setuptools = False
19 19
20 20
21 21 pjoin = os.path.join
22 22
23 23 # suffix for start menu folder names
24 24 pyver = "(Py%i.%i %i bit)" % (sys.version_info[0], sys.version_info[1],
25 25 (32, 64)[sys.maxsize > 2**32])
26 26
27 27
28 28 def mkshortcut(target, description, linkdir, arguments="", iconpath='',
29 29 workdir="%HOMEDRIVE%%HOMEPATH%", iconindex=0):
30 30 """Make a shortcut if it doesn't exist and register its creation."""
31 31 filename = pjoin(linkdir, description + '.lnk')
32 32 description = "%s %s" % (description, pyver)
33 33 create_shortcut(target, description, filename, arguments, workdir,
34 34 iconpath, iconindex)
35 35 file_created(filename)
36 36
37 37
38 38 def arguments(scriptsdir, script, scriptargs=''):
39 39 """Return command line arguments to be passed to the python executable."""
40 40 cmdbase = suffix(pjoin(scriptsdir, script))
41 41 if have_setuptools:
42 42 cmdbase += '-script.py'
43 43 return '"%s" %s' % (cmdbase, scriptargs)
44 44
45 45
46 46 def suffix(s):
47 47 """Add '3' suffix to programs for Python 3."""
48 48 if sys.version_info[0] == 3:
49 49 s = s + '3'
50 50 return s
51 51
52 52
53 53 def install():
54 54 """Routine to be run by the win32 installer with the -install switch."""
55 55 # Get some system constants
56 56 python = pjoin(sys.prefix, 'python.exe')
57 57 pythonw = pjoin(sys.prefix, 'pythonw.exe')
58 58
59 59 if not have_setuptools:
60 60 # This currently doesn't work without setuptools,
61 61 # so don't bother making broken links
62 print("Distribute (setuptools) is required to"
62 print("Setuptools is required to"
63 63 " create Start Menu items.", file=sys.stderr)
64 64 print("Re-run this installer after installing"
65 " distribute to get Start Menu items.", file=sys.stderr)
65 " Setuptools to get Start Menu items.", file=sys.stderr)
66 66 return
67 67
68 68 # Lookup path to common startmenu ...
69 69 ip_start_menu = pjoin(get_special_folder_path('CSIDL_COMMON_PROGRAMS'),
70 70 'IPython %s' % pyver)
71 71
72 72 # Create IPython entry ...
73 73 if not os.path.isdir(ip_start_menu):
74 74 os.mkdir(ip_start_menu)
75 75 directory_created(ip_start_menu)
76 76
77 77 # Create .py and .bat files to make things available from
78 78 # the Windows command line. Thanks to the Twisted project
79 79 # for this logic!
80 80 programs = [
81 81 'ipython',
82 82 'iptest',
83 83 'ipcontroller',
84 84 'ipengine',
85 85 'ipcluster',
86 86 'irunner',
87 87 ]
88 88 programs = [suffix(p) for p in programs]
89 89 scripts = pjoin(sys.prefix, 'scripts')
90 90 if not have_setuptools:
91 91 # only create .bat files if we don't have setuptools
92 92 for program in programs:
93 93 raw = pjoin(scripts, program)
94 94 bat = raw + '.bat'
95 95 py = raw + '.py'
96 96 # Create .py versions of the scripts
97 97 shutil.copy(raw, py)
98 98 # Create .bat files for each of the scripts
99 99 bat_file = file(bat, 'w')
100 100 bat_file.write("@%s %s %%*" % (python, py))
101 101 bat_file.close()
102 102
103 103 # Create Start Menu shortcuts
104 104 iconpath = pjoin(scripts, 'ipython.ico')
105 105 mkshortcut(python, 'IPython', ip_start_menu,
106 106 arguments(scripts, 'ipython'), iconpath)
107 107 mkshortcut(python, 'IPython (pylab mode)', ip_start_menu,
108 108 arguments(scripts, 'ipython', '--pylab'), iconpath)
109 109 mkshortcut(python, 'IPython Controller', ip_start_menu,
110 110 arguments(scripts, 'ipcontroller'), iconpath)
111 111 mkshortcut(python, 'IPython Engine', ip_start_menu,
112 112 arguments(scripts, 'ipengine'), iconpath)
113 113 mkshortcut(pythonw, 'IPython Qt Console', ip_start_menu,
114 114 arguments(scripts, 'ipython', 'qtconsole'), iconpath)
115 115
116 116 iconpath = pjoin(scripts, 'ipython_nb.ico')
117 117 mkshortcut(python, 'IPython Notebook', ip_start_menu,
118 118 arguments(scripts, 'ipython', 'notebook'), iconpath)
119 119
120 120 mkshortcut(pythonw, 'IPython Documentation', ip_start_menu,
121 121 '-m webbrowser -t "http://ipython.org/documentation.html',
122 122 iconpath='url.dll')
123 123
124 124 # Disable pysh Start item until the profile restores functionality
125 125 # Most of this code is in IPython/deathrow, and needs to be updated
126 126 # to 0.11 APIs
127 127 #mkshortcut(python, 'IPython%s (command prompt mode)', ip_start_menu,
128 128 # arguments(scripts, 'ipython', 'profile=pysh --init'))
129 129
130 130
131 131 def remove():
132 132 """Routine to be run by the win32 installer with the -remove switch."""
133 133 pass
134 134
135 135
136 136 # main()
137 137 if len(sys.argv) > 1:
138 138 if sys.argv[1] == '-install':
139 139 try:
140 140 install()
141 141 except OSError:
142 142 print("Failed to create Start Menu items, try running the"
143 143 " installer as administrator.", file=sys.stderr)
144 144 elif sys.argv[1] == '-remove':
145 145 remove()
146 146 else:
147 147 print("Script was called with option %s" % sys.argv[1],
148 148 file=sys.stderr)
General Comments 0
You need to be logged in to leave comments. Login now