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