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