##// END OF EJS Templates
Merge PR #1143 (Python3 StartMenu items)...
MinRK -
r5682:5047149d merge
parent child Browse files
Show More
@@ -1,87 +1,91 b''
1 """Tab-completion over zmq"""
1 """Tab-completion over zmq"""
2
2
3 # Trying to get print statements to work during completion, not very
3 # Trying to get print statements to work during completion, not very
4 # successfully...
4 # successfully...
5 from __future__ import print_function
5 from __future__ import print_function
6
6
7 import itertools
7 import itertools
8 import readline
8 try:
9 import readline
10 except ImportError:
11 readline = None
9 import rlcompleter
12 import rlcompleter
10 import time
13 import time
11
14
12 import session
15 import session
13
16
14 class KernelCompleter(object):
17 class KernelCompleter(object):
15 """Kernel-side completion machinery."""
18 """Kernel-side completion machinery."""
16 def __init__(self, namespace):
19 def __init__(self, namespace):
17 self.namespace = namespace
20 self.namespace = namespace
18 self.completer = rlcompleter.Completer(namespace)
21 self.completer = rlcompleter.Completer(namespace)
19
22
20 def complete(self, line, text):
23 def complete(self, line, text):
21 # We'll likely use linel later even if now it's not used for anything
24 # We'll likely use linel later even if now it's not used for anything
22 matches = []
25 matches = []
23 complete = self.completer.complete
26 complete = self.completer.complete
24 for state in itertools.count():
27 for state in itertools.count():
25 comp = complete(text, state)
28 comp = complete(text, state)
26 if comp is None:
29 if comp is None:
27 break
30 break
28 matches.append(comp)
31 matches.append(comp)
29 return matches
32 return matches
30
33
31
34
32 class ClientCompleter(object):
35 class ClientCompleter(object):
33 """Client-side completion machinery.
36 """Client-side completion machinery.
34
37
35 How it works: self.complete will be called multiple times, with
38 How it works: self.complete will be called multiple times, with
36 state=0,1,2,... When state=0 it should compute ALL the completion matches,
39 state=0,1,2,... When state=0 it should compute ALL the completion matches,
37 and then return them for each value of state."""
40 and then return them for each value of state."""
38
41
39 def __init__(self, client, session, socket):
42 def __init__(self, client, session, socket):
40 # ugly, but we get called asynchronously and need access to some
43 # ugly, but we get called asynchronously and need access to some
41 # client state, like backgrounded code
44 # client state, like backgrounded code
45 assert readline is not None, "ClientCompleter depends on readline"
42 self.client = client
46 self.client = client
43 self.session = session
47 self.session = session
44 self.socket = socket
48 self.socket = socket
45 self.matches = []
49 self.matches = []
46
50
47 def request_completion(self, text):
51 def request_completion(self, text):
48 # Get full line to give to the kernel in case it wants more info.
52 # Get full line to give to the kernel in case it wants more info.
49 line = readline.get_line_buffer()
53 line = readline.get_line_buffer()
50 # send completion request to kernel
54 # send completion request to kernel
51 msg = self.session.send(self.socket,
55 msg = self.session.send(self.socket,
52 'complete_request',
56 'complete_request',
53 dict(text=text, line=line))
57 dict(text=text, line=line))
54
58
55 # Give the kernel up to 0.5s to respond
59 # Give the kernel up to 0.5s to respond
56 for i in range(5):
60 for i in range(5):
57 ident,rep = self.session.recv(self.socket)
61 ident,rep = self.session.recv(self.socket)
58 rep = Message(rep)
62 rep = Message(rep)
59 if rep is not None and rep.msg_type == 'complete_reply':
63 if rep is not None and rep.msg_type == 'complete_reply':
60 matches = rep.content.matches
64 matches = rep.content.matches
61 break
65 break
62 time.sleep(0.1)
66 time.sleep(0.1)
63 else:
67 else:
64 # timeout
68 # timeout
65 print ('TIMEOUT') # Can't see this message...
69 print ('TIMEOUT') # Can't see this message...
66 matches = None
70 matches = None
67 return matches
71 return matches
68
72
69 def complete(self, text, state):
73 def complete(self, text, state):
70
74
71 if self.client.backgrounded > 0:
75 if self.client.backgrounded > 0:
72 print("\n[Not completing, background tasks active]")
76 print("\n[Not completing, background tasks active]")
73 print(readline.get_line_buffer(), end='')
77 print(readline.get_line_buffer(), end='')
74 return None
78 return None
75
79
76 if state==0:
80 if state==0:
77 matches = self.request_completion(text)
81 matches = self.request_completion(text)
78 if matches is None:
82 if matches is None:
79 self.matches = []
83 self.matches = []
80 print('WARNING: Kernel timeout on tab completion.')
84 print('WARNING: Kernel timeout on tab completion.')
81 else:
85 else:
82 self.matches = matches
86 self.matches = matches
83
87
84 try:
88 try:
85 return self.matches[state]
89 return self.matches[state]
86 except IndexError:
90 except IndexError:
87 return None
91 return None
@@ -1,133 +1,142 b''
1 #!python
1 #!python
2 """Windows-specific part of the installation"""
2 """Windows-specific part of the installation"""
3
3
4 from __future__ import print_function
5
4 import os, sys, shutil
6 import os, sys, shutil
5 pjoin = os.path.join
7 pjoin = os.path.join
6
8
7 # import setuptools if we can
9 # import setuptools if we can
8 try:
10 try:
9 import setuptools
11 import setuptools
10 except ImportError:
12 except ImportError:
11 pass
13 pass
12
14
13
15
14 def mkshortcut(target,description,link_file,*args,**kw):
16 def mkshortcut(target,description,link_file,*args,**kw):
15 """make a shortcut if it doesn't exist, and register its creation"""
17 """make a shortcut if it doesn't exist, and register its creation"""
16
18
17 create_shortcut(target, description, link_file,*args,**kw)
19 create_shortcut(target, description, link_file,*args,**kw)
18 file_created(link_file)
20 file_created(link_file)
19
21
22 def suffix(s):
23 """add '3' suffix to programs for Python 3"""
24 if sys.version_info[0] == 3:
25 s = s+'3'
26 return s
20
27
21 def install():
28 def install():
22 """Routine to be run by the win32 installer with the -install switch."""
29 """Routine to be run by the win32 installer with the -install switch."""
23
30
24 from IPython.core.release import version
25
26 # Get some system constants
31 # Get some system constants
27 prefix = sys.prefix
32 prefix = sys.prefix
28 python = pjoin(prefix, 'python.exe')
33 python = pjoin(prefix, 'python.exe')
29 pythonw = pjoin(prefix, 'pythonw.exe')
34 pythonw = pjoin(prefix, 'pythonw.exe')
30 have_setuptools = 'setuptools' in sys.modules
35 have_setuptools = 'setuptools' in sys.modules
31
36
32 if not have_setuptools:
37 if not have_setuptools:
33 # This currently doesn't work without setuptools,
38 # This currently doesn't work without setuptools,
34 # so don't bother making broken links
39 # so don't bother making broken links
35 return
40 return
36
41
37 # Lookup path to common startmenu ...
42 # Lookup path to common startmenu ...
38 ip_start_menu = pjoin(get_special_folder_path('CSIDL_COMMON_PROGRAMS'),
43 ip_start_menu = pjoin(get_special_folder_path('CSIDL_COMMON_PROGRAMS'),
39 'IPython (Py%i.%i %i bit)' % (sys.version_info[0],
44 'IPython (Py%i.%i %i bit)' % (sys.version_info[0],
40 sys.version_info[1],
45 sys.version_info[1],
41 8*tuple.__itemsize__))
46 8*tuple.__itemsize__))
42 # Create IPython entry ...
47 # Create IPython entry ...
43 if not os.path.isdir(ip_start_menu):
48 if not os.path.isdir(ip_start_menu):
44 os.mkdir(ip_start_menu)
49 os.mkdir(ip_start_menu)
45 directory_created(ip_start_menu)
50 directory_created(ip_start_menu)
46
51
47 # Create .py and .bat files to make things available from
52 # Create .py and .bat files to make things available from
48 # the Windows command line. Thanks to the Twisted project
53 # the Windows command line. Thanks to the Twisted project
49 # for this logic!
54 # for this logic!
50 programs = [
55 programs = [
51 'ipython',
56 'ipython',
52 'iptest',
57 'iptest',
53 'ipcontroller',
58 'ipcontroller',
54 'ipengine',
59 'ipengine',
55 'ipcluster',
60 'ipcluster',
56 'irunner'
61 'irunner'
57 ]
62 ]
63 programs = [ suffix(p) for p in programs ]
58 scripts = pjoin(prefix,'scripts')
64 scripts = pjoin(prefix,'scripts')
59 if not have_setuptools:
65 if not have_setuptools:
60 # only create .bat files if we don't have setuptools
66 # only create .bat files if we don't have setuptools
61 for program in programs:
67 for program in programs:
62 raw = pjoin(scripts, program)
68 raw = pjoin(scripts, program)
63 bat = raw + '.bat'
69 bat = raw + '.bat'
64 py = raw + '.py'
70 py = raw + '.py'
65 # Create .py versions of the scripts
71 # Create .py versions of the scripts
66 shutil.copy(raw, py)
72 shutil.copy(raw, py)
67 # Create .bat files for each of the scripts
73 # Create .bat files for each of the scripts
68 bat_file = file(bat,'w')
74 bat_file = file(bat,'w')
69 bat_file.write("@%s %s %%*" % (python, py))
75 bat_file.write("@%s %s %%*" % (python, py))
70 bat_file.close()
76 bat_file.close()
71
77
72 # Now move onto setting the Start Menu up
78 # Now move onto setting the Start Menu up
73 ipybase = pjoin(scripts, 'ipython')
79 ipybase = suffix(pjoin(scripts, 'ipython'))
74 if have_setuptools:
80 if have_setuptools:
75 # let setuptools take care of the scripts:
81 # let setuptools take care of the scripts:
76 ipybase = ipybase + '-script.py'
82 ipybase = ipybase + '-script.py'
77 workdir = "%HOMEDRIVE%%HOMEPATH%"
83 workdir = "%HOMEDRIVE%%HOMEPATH%"
78
84
79 link = pjoin(ip_start_menu, 'IPython.lnk')
85 link = pjoin(ip_start_menu, 'IPython.lnk')
80 cmd = '"%s"' % ipybase
86 cmd = '"%s"' % ipybase
81 mkshortcut(python, 'IPython', link, cmd, workdir)
87 mkshortcut(python, 'IPython', link, cmd, workdir)
82
88
83 # Disable pysh Start item until the profile restores functionality
89 # Disable pysh Start item until the profile restores functionality
84 # Most of this code is in IPython/deathrow, and needs to be updated
90 # Most of this code is in IPython/deathrow, and needs to be updated
85 # to 0.11 APIs
91 # to 0.11 APIs
86
92
87 # link = pjoin(ip_start_menu, 'pysh.lnk')
93 # link = pjoin(ip_start_menu, 'pysh.lnk')
88 # cmd = '"%s" profile=pysh --init' % ipybase
94 # cmd = '"%s" profile=pysh --init' % ipybase
89 # mkshortcut(python, 'IPython (command prompt mode)', link, cmd, workdir)
95 # mkshortcut(python, 'IPython (command prompt mode)', link, cmd, workdir)
90
96
91 link = pjoin(ip_start_menu, 'pylab.lnk')
97 link = pjoin(ip_start_menu, 'pylab.lnk')
92 cmd = '"%s" profile=pylab --init' % ipybase
98 cmd = '"%s" profile=pylab --init' % ipybase
93 mkshortcut(python, 'IPython (pylab profile)', link, cmd, workdir)
99 mkshortcut(python, 'IPython (pylab profile)', link, cmd, workdir)
94
100
95 link = pjoin(ip_start_menu, 'ipcontroller.lnk')
101 link = pjoin(ip_start_menu, 'ipcontroller.lnk')
96 cmdbase = pjoin(scripts, 'ipcontroller')
102 cmdbase = suffix(pjoin(scripts, 'ipcontroller'))
97 if have_setuptools:
103 if have_setuptools:
98 cmdbase += '-script.py'
104 cmdbase += '-script.py'
99 cmd = '"%s"' % cmdbase
105 cmd = '"%s"' % cmdbase
100 mkshortcut(python, 'IPython controller', link, cmd, workdir)
106 mkshortcut(python, 'IPython controller', link, cmd, workdir)
101
107
102 link = pjoin(ip_start_menu, 'ipengine.lnk')
108 link = pjoin(ip_start_menu, 'ipengine.lnk')
103 cmdbase = pjoin(scripts, 'ipengine')
109 cmdbase = suffix(pjoin(scripts, 'ipengine'))
104 if have_setuptools:
110 if have_setuptools:
105 cmdbase += '-script.py'
111 cmdbase += '-script.py'
106 cmd = '"%s"' % cmdbase
112 cmd = '"%s"' % cmdbase
107 mkshortcut(python, 'IPython engine', link, cmd, workdir)
113 mkshortcut(python, 'IPython engine', link, cmd, workdir)
108
114
109 link = pjoin(ip_start_menu, 'ipythonqt.lnk')
115 link = pjoin(ip_start_menu, 'ipythonqt.lnk')
110 cmdbase = pjoin(scripts, 'ipython-qtconsole')
116 cmdbase = suffix(pjoin(scripts, 'ipython')) + '-qtconsole'
111 if have_setuptools:
117 if have_setuptools:
112 cmdbase += '-script.pyw'
118 cmdbase += '-script.pyw'
113 cmd = '"%s"' % cmdbase
119 cmd = '"%s"' % cmdbase
114 mkshortcut(pythonw, 'IPython Qt Console', link, cmd, workdir)
120 mkshortcut(pythonw, 'IPython Qt Console', link, cmd, workdir)
115 # Create documentation shortcuts ...
121 # Create documentation shortcuts ...
116 t = prefix + r'\share\doc\ipython\manual\index.html'
122 t = prefix + r'\share\doc\ipython\manual\index.html'
117 f = ip_start_menu + r'\Manual in HTML.lnk'
123 f = ip_start_menu + r'\Manual in HTML.lnk'
118 mkshortcut(t,'IPython Manual - HTML-Format',f)
124 mkshortcut(t,'IPython Manual - HTML-Format',f)
119
125
120
126
121 def remove():
127 def remove():
122 """Routine to be run by the win32 installer with the -remove switch."""
128 """Routine to be run by the win32 installer with the -remove switch."""
123 pass
129 pass
124
130
125
131
126 # main()
132 # main()
127 if len(sys.argv) > 1:
133 if len(sys.argv) > 1:
128 if sys.argv[1] == '-install':
134 if sys.argv[1] == '-install':
129 install()
135 try:
136 install()
137 except OSError:
138 print("Failed to create Start Menu items, try running installer as administrator.", file=sys.stderr)
130 elif sys.argv[1] == '-remove':
139 elif sys.argv[1] == '-remove':
131 remove()
140 remove()
132 else:
141 else:
133 print "Script was called with option %s" % sys.argv[1]
142 print("Script was called with option %s" % sys.argv[1], file=sys.stderr)
@@ -1,21 +1,36 b''
1 import os.path
1 import os.path
2 import sys
2 from setuptools import setup
3 from setuptools import setup
3 from setuptools.command.build_py import build_py
4 from setuptools.command.build_py import build_py
4
5
5 from setupbase import (setup_args,
6 from setupbase import (setup_args,
6 find_scripts,
7 find_scripts,
7 find_packages,
8 find_packages,
8 find_package_data,
9 find_package_data,
9 record_commit_info,
10 record_commit_info,
10 )
11 )
11
12
12 setup_args['entry_points'] = find_scripts(True, suffix='3')
13 setup_args['entry_points'] = find_scripts(True, suffix='3')
13 setup_args['packages'] = find_packages()
14 setup_args['packages'] = find_packages()
14 setup_args['package_data'] = find_package_data()
15 setup_args['package_data'] = find_package_data()
15 setup_args['cmdclass'] = {'build_py': record_commit_info('IPython', build_cmd=build_py)}
16 setup_args['cmdclass'] = {'build_py': record_commit_info('IPython', build_cmd=build_py)}
16
17
18 # Script to be run by the windows binary installer after the default setup
19 # routine, to add shortcuts and similar windows-only things. Windows
20 # post-install scripts MUST reside in the scripts/ dir, otherwise distutils
21 # doesn't find them.
22 if 'bdist_wininst' in sys.argv:
23 if len(sys.argv) > 2 and \
24 ('sdist' in sys.argv or 'bdist_rpm' in sys.argv):
25 print >> sys.stderr, "ERROR: bdist_wininst must be run alone. Exiting."
26 sys.exit(1)
27 setup_args['scripts'] = [os.path.join('scripts','ipython_win_post_install.py')]
28 setup_args['options'] = {"bdist_wininst":
29 {"install_script":
30 "ipython_win_post_install.py"}}
31
17 def main():
32 def main():
18 setup(use_2to3 = True, **setup_args)
33 setup(use_2to3 = True, **setup_args)
19
34
20 if __name__ == "__main__":
35 if __name__ == "__main__":
21 main()
36 main()
General Comments 0
You need to be logged in to leave comments. Login now