Show More
@@ -1,31 +1,54 b'' | |||||
1 |
|
||||
2 |
|
|
1 | import os,sys | |
3 |
|
2 | |||
4 | def selflaunch(line): |
|
3 | import ipy_rehashdir,glob | |
5 | """ Launch python script with 'this' interpreter |
|
4 | from ipy_rehashdir import selflaunch, PyLauncher | |
|
5 | ||||
|
6 | def pylaunchers(): | |||
|
7 | """Create launchers for python scripts in cwd and store them in alias table | |||
6 |
|
8 | |||
7 | e.g. d:\foo\ipython.exe a.py |
|
9 | This is useful if you want to invoke .py scripts from ipykit session, | |
|
10 | just adding .py files in PATH does not work without file association. | |||
8 |
|
11 | |||
9 | """ |
|
12 | """ | |
10 | cmd = sys.executable + ' ' + line.split(None,1)[1] |
|
13 | fs = glob.glob('*.py*') | |
11 | print ">",cmd |
|
14 | for f in fs: | |
12 | os.system(cmd) |
|
15 | l = PyLauncher(f) | |
|
16 | n = os.path.splitext(f)[0] | |||
|
17 | ip.defalias(n, l) | |||
|
18 | ip.magic('store '+n) | |||
|
19 | ||||
|
20 | ||||
|
21 | def exta_imports(): | |||
|
22 | # add some modules that you'd want to be bundled in the ipykit | |||
|
23 | # library zip file here. Do this if you get ImportErrors from scripts you | |||
|
24 | # try to launch with 'py' or pylaunchers. In theory you could include | |||
|
25 | # the whole stdlib here for full script coverage | |||
13 |
|
26 | |||
|
27 | # note that this is never run, it's just here for py2exe | |||
|
28 | import distutils.dir_util | |||
|
29 | ||||
14 | def main(): |
|
30 | def main(): | |
15 | import IPython.ipapi |
|
|||
16 | ip = IPython.ipapi.get() |
|
|||
17 |
|
||||
18 | root = os.environ.get('IPYKITROOT', None) |
|
31 | root = os.environ.get('IPYKITROOT', None) | |
19 | if not root: |
|
32 | if not root: | |
20 | print "Can't configure ipykit, IPYKITROOT should be set." |
|
33 | print "Can't configure ipykit, IPYKITROOT should be set." | |
21 | return |
|
34 | return | |
22 |
|
35 | |||
23 | os.environ["PATH"] = os.environ["PATH"] + ";" + root + "\\bin;" |
|
36 | os.environ["PATH"] = os.environ["PATH"] + ";" + root + "\\bin;" | |
|
37 | ip.to_user_ns("pylaunchers") | |||
24 |
|
38 | |||
25 | ip.defalias('py',selflaunch) |
|
|||
26 |
|
39 | |||
27 | ip.defalias('ls','ls -F') |
|
40 | def ipython_firstrun(ip): | |
|
41 | print "First run of ipykit - configuring" | |||
|
42 | ip.defalias('py',selflaunch) | |||
|
43 | ip.defalias('d','ls -F') | |||
|
44 | ip.defalias('ls','ls') | |||
|
45 | ip.magic('store py') | |||
|
46 | ip.magic('store d') | |||
|
47 | ip.magic('store ls') | |||
28 |
|
48 | |||
29 | main() |
|
49 | def init_ipython(ipy): | |
|
50 | global ip | |||
|
51 | ip = ipy | |||
|
52 | main() | |||
30 |
|
53 | |||
31 |
|
54 |
@@ -19,8 +19,31 b' import IPython.ipapi' | |||||
19 | ip = IPython.ipapi.get() |
|
19 | ip = IPython.ipapi.get() | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | import os,re,fnmatch |
|
22 | import os,re,fnmatch,sys | |
23 |
|
23 | |||
|
24 | def selflaunch(line): | |||
|
25 | """ Launch python script with 'this' interpreter | |||
|
26 | ||||
|
27 | e.g. d:\foo\ipython.exe a.py | |||
|
28 | ||||
|
29 | """ | |||
|
30 | cmd = sys.executable + ' ' + line.split(None,1)[1] | |||
|
31 | print ">",cmd | |||
|
32 | os.system(cmd) | |||
|
33 | ||||
|
34 | class PyLauncher: | |||
|
35 | """ Invoke selflanucher on the specified script | |||
|
36 | ||||
|
37 | This is mostly useful for associating with scripts using:: | |||
|
38 | _ip.defalias('foo',PyLauncher('foo_script.py')) | |||
|
39 | ||||
|
40 | """ | |||
|
41 | def __init__(self,script): | |||
|
42 | self.script = os.path.abspath(script) | |||
|
43 | def __call__(self, line): | |||
|
44 | selflaunch("py " + self.script + ' ' + line) | |||
|
45 | def __repr__(self): | |||
|
46 | return 'PyLauncher("%s")' % self.script | |||
24 | def rehashdir_f(self,arg): |
|
47 | def rehashdir_f(self,arg): | |
25 | """ Add executables in all specified dirs to alias table |
|
48 | """ Add executables in all specified dirs to alias table | |
26 |
|
49 | |||
@@ -95,4 +118,5 b' def rehashdir_f(self,arg):' | |||||
95 | finally: |
|
118 | finally: | |
96 | os.chdir(savedir) |
|
119 | os.chdir(savedir) | |
97 | return created |
|
120 | return created | |
|
121 | ||||
98 | ip.expose_magic("rehashdir",rehashdir_f) |
|
122 | ip.expose_magic("rehashdir",rehashdir_f) |
@@ -1,7 +1,7 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Magic functions for InteractiveShell. |
|
2 | """Magic functions for InteractiveShell. | |
3 |
|
3 | |||
4 |
$Id: Magic.py 266 |
|
4 | $Id: Magic.py 2668 2007-08-24 17:10:46Z vivainio $""" | |
5 |
|
5 | |||
6 | #***************************************************************************** |
|
6 | #***************************************************************************** | |
7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and | |
@@ -2298,7 +2298,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
2298 | special = False |
|
2298 | special = False | |
2299 | try: |
|
2299 | try: | |
2300 | tgt = atab[alias][1] |
|
2300 | tgt = atab[alias][1] | |
2301 | except TypeError: |
|
2301 | except (TypeError, AttributeError): | |
2302 | # unsubscriptable? probably a callable |
|
2302 | # unsubscriptable? probably a callable | |
2303 | tgt = atab[alias] |
|
2303 | tgt = atab[alias] | |
2304 | special = True |
|
2304 | special = True |
@@ -1,7 +1,7 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Release data for the IPython project. |
|
2 | """Release data for the IPython project. | |
3 |
|
3 | |||
4 |
$Id: Release.py 266 |
|
4 | $Id: Release.py 2668 2007-08-24 17:10:46Z vivainio $""" | |
5 |
|
5 | |||
6 | #***************************************************************************** |
|
6 | #***************************************************************************** | |
7 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> |
|
7 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> | |
@@ -22,7 +22,7 b" name = 'ipython'" | |||||
22 | # because bdist_rpm does not accept dashes (an RPM) convention, and |
|
22 | # because bdist_rpm does not accept dashes (an RPM) convention, and | |
23 | # bdist_deb does not accept underscores (a Debian convention). |
|
23 | # bdist_deb does not accept underscores (a Debian convention). | |
24 |
|
24 | |||
25 |
revision = '266 |
|
25 | revision = '2665' | |
26 |
|
26 | |||
27 | version = '0.8.2.svn.r' + revision.rstrip('M') |
|
27 | version = '0.8.2.svn.r' + revision.rstrip('M') | |
28 |
|
28 |
@@ -433,6 +433,16 b' class IPApi:' | |||||
433 | self.IP.rl_next_input = s |
|
433 | self.IP.rl_next_input = s | |
434 |
|
434 | |||
435 | def load(self, mod): |
|
435 | def load(self, mod): | |
|
436 | """ Load an extension. | |||
|
437 | ||||
|
438 | Some modules should (or must) be 'load()':ed, rather than just imported. | |||
|
439 | ||||
|
440 | Loading will do: | |||
|
441 | ||||
|
442 | - run init_ipython(ip) | |||
|
443 | - run ipython_firstrun(ip) | |||
|
444 | ||||
|
445 | """ | |||
436 | if mod in self.extensions: |
|
446 | if mod in self.extensions: | |
437 | # just to make sure we don't init it twice |
|
447 | # just to make sure we don't init it twice | |
438 | # note that if you 'load' a module that has already been |
|
448 | # note that if you 'load' a module that has already been | |
@@ -443,6 +453,14 b' class IPApi:' | |||||
443 | m = sys.modules[mod] |
|
453 | m = sys.modules[mod] | |
444 | if hasattr(m,'init_ipython'): |
|
454 | if hasattr(m,'init_ipython'): | |
445 | m.init_ipython(self) |
|
455 | m.init_ipython(self) | |
|
456 | ||||
|
457 | if hasattr(m,'ipython_firstrun'): | |||
|
458 | already_loaded = self.db.get('firstrun_done', set()) | |||
|
459 | if mod not in already_loaded: | |||
|
460 | m.ipython_firstrun(self) | |||
|
461 | already_loaded.add(mod) | |||
|
462 | self.db['firstrun_done'] = already_loaded | |||
|
463 | ||||
446 | self.extensions[mod] = m |
|
464 | self.extensions[mod] = m | |
447 | return m |
|
465 | return m | |
448 |
|
466 |
@@ -85,10 +85,18 b' setup(name = name,' | |||||
85 | **egg_extra_kwds |
|
85 | **egg_extra_kwds | |
86 | ) |
|
86 | ) | |
87 |
|
87 | |||
|
88 | minimal_conf = """ | |||
|
89 | import IPython.ipapi | |||
|
90 | ip = IPython.ipapi.get() | |||
|
91 | import ipy_profile_sh | |||
|
92 | ip.load('ipy_kitcfg') | |||
|
93 | ||||
|
94 | """ | |||
|
95 | ||||
88 | if not os.path.isdir("dist/_ipython"): |
|
96 | if not os.path.isdir("dist/_ipython"): | |
89 | print "Creating simple _ipython dir" |
|
97 | print "Creating simple _ipython dir" | |
90 | os.mkdir("dist/_ipython") |
|
98 | os.mkdir("dist/_ipython") | |
91 | open("dist/_ipython/ipythonrc.ini","w").write("# intentionally blank\n") |
|
99 | open("dist/_ipython/ipythonrc.ini","w").write("# intentionally blank\n") | |
92 |
open("dist/_ipython/ipy_user_conf.py","w").write( |
|
100 | open("dist/_ipython/ipy_user_conf.py","w").write(minimal_conf) | |
93 | if os.path.isdir('bin'): |
|
101 | if os.path.isdir('bin'): | |
94 | dir_util.copy_tree('bin','dist/_ipython/bin') |
|
102 | dir_util.copy_tree('bin','dist/_ipython/bin') |
General Comments 0
You need to be logged in to leave comments.
Login now