##// END OF EJS Templates
rm imports
Srinivas Reddy Thatiparthy -
Show More
@@ -1,120 +1,119 b''
1 1 """Find files and directories which IPython uses.
2 2 """
3 3 import os.path
4 4 import shutil
5 5 import tempfile
6 6 from warnings import warn
7 7
8 8 import IPython
9 9 from IPython.utils.importstring import import_item
10 10 from IPython.utils.path import (
11 11 get_home_dir, get_xdg_dir, get_xdg_cache_dir, compress_user, _writable_dir,
12 ensure_dir_exists, fs_encoding, filefind
13 )
12 ensure_dir_exists, fs_encoding)
14 13 from IPython.utils import py3compat
15 14
16 15 def get_ipython_dir():
17 16 """Get the IPython directory for this platform and user.
18 17
19 18 This uses the logic in `get_home_dir` to find the home directory
20 19 and then adds .ipython to the end of the path.
21 20 """
22 21
23 22 env = os.environ
24 23 pjoin = os.path.join
25 24
26 25
27 26 ipdir_def = '.ipython'
28 27
29 28 home_dir = get_home_dir()
30 29 xdg_dir = get_xdg_dir()
31 30
32 31 # import pdb; pdb.set_trace() # dbg
33 32 if 'IPYTHON_DIR' in env:
34 33 warn('The environment variable IPYTHON_DIR is deprecated. '
35 34 'Please use IPYTHONDIR instead.')
36 35 ipdir = env.get('IPYTHONDIR', env.get('IPYTHON_DIR', None))
37 36 if ipdir is None:
38 37 # not set explicitly, use ~/.ipython
39 38 ipdir = pjoin(home_dir, ipdir_def)
40 39 if xdg_dir:
41 40 # Several IPython versions (up to 1.x) defaulted to .config/ipython
42 41 # on Linux. We have decided to go back to using .ipython everywhere
43 42 xdg_ipdir = pjoin(xdg_dir, 'ipython')
44 43
45 44 if _writable_dir(xdg_ipdir):
46 45 cu = compress_user
47 46 if os.path.exists(ipdir):
48 47 warn(('Ignoring {0} in favour of {1}. Remove {0} to '
49 48 'get rid of this message').format(cu(xdg_ipdir), cu(ipdir)))
50 49 elif os.path.islink(xdg_ipdir):
51 50 warn(('{0} is deprecated. Move link to {1} to '
52 51 'get rid of this message').format(cu(xdg_ipdir), cu(ipdir)))
53 52 else:
54 53 warn('Moving {0} to {1}'.format(cu(xdg_ipdir), cu(ipdir)))
55 54 shutil.move(xdg_ipdir, ipdir)
56 55
57 56 ipdir = os.path.normpath(os.path.expanduser(ipdir))
58 57
59 58 if os.path.exists(ipdir) and not _writable_dir(ipdir):
60 59 # ipdir exists, but is not writable
61 60 warn("IPython dir '{0}' is not a writable location,"
62 61 " using a temp directory.".format(ipdir))
63 62 ipdir = tempfile.mkdtemp()
64 63 elif not os.path.exists(ipdir):
65 64 parent = os.path.dirname(ipdir)
66 65 if not _writable_dir(parent):
67 66 # ipdir does not exist and parent isn't writable
68 67 warn("IPython parent '{0}' is not a writable location,"
69 68 " using a temp directory.".format(parent))
70 69 ipdir = tempfile.mkdtemp()
71 70
72 71 return py3compat.cast_unicode(ipdir, fs_encoding)
73 72
74 73
75 74 def get_ipython_cache_dir():
76 75 """Get the cache directory it is created if it does not exist."""
77 76 xdgdir = get_xdg_cache_dir()
78 77 if xdgdir is None:
79 78 return get_ipython_dir()
80 79 ipdir = os.path.join(xdgdir, "ipython")
81 80 if not os.path.exists(ipdir) and _writable_dir(xdgdir):
82 81 ensure_dir_exists(ipdir)
83 82 elif not _writable_dir(xdgdir):
84 83 return get_ipython_dir()
85 84
86 85 return py3compat.cast_unicode(ipdir, fs_encoding)
87 86
88 87
89 88 def get_ipython_package_dir():
90 89 """Get the base directory where IPython itself is installed."""
91 90 ipdir = os.path.dirname(IPython.__file__)
92 91 return py3compat.cast_unicode(ipdir, fs_encoding)
93 92
94 93
95 94 def get_ipython_module_path(module_str):
96 95 """Find the path to an IPython module in this version of IPython.
97 96
98 97 This will always find the version of the module that is in this importable
99 98 IPython package. This will always return the path to the ``.py``
100 99 version of the module.
101 100 """
102 101 if module_str == 'IPython':
103 102 return os.path.join(get_ipython_package_dir(), '__init__.py')
104 103 mod = import_item(module_str)
105 104 the_path = mod.__file__.replace('.pyc', '.py')
106 105 the_path = the_path.replace('.pyo', '.py')
107 106 return py3compat.cast_unicode(the_path, fs_encoding)
108 107
109 108 def locate_profile(profile='default'):
110 109 """Find the path to the folder associated with a given profile.
111 110
112 111 I.e. find $IPYTHONDIR/profile_whatever.
113 112 """
114 113 from IPython.core.profiledir import ProfileDir, ProfileDirError
115 114 try:
116 115 pd = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), profile)
117 116 except ProfileDirError:
118 117 # IOError makes more sense when people are expecting a path
119 118 raise IOError("Couldn't find profile %r" % profile)
120 119 return pd.location
@@ -1,78 +1,73 b''
1 1 """cli-specific implementation of process utilities.
2 2
3 3 cli - Common Language Infrastructure for IronPython. Code
4 4 can run on any operating system. Check os.name for os-
5 5 specific settings.
6 6
7 7 This file is only meant to be imported by process.py, not by end-users.
8 8
9 9 This file is largely untested. To become a full drop-in process
10 10 interface for IronPython will probably require you to help fill
11 11 in the details.
12 12 """
13 13
14 # Import cli libraries:
15 import clr
16 import System
17 14
18 # Import Python libraries:
15 import System
19 16 import os
20
21 # Import IPython libraries:
22 17 from IPython.utils import py3compat
23 from ._process_common import arg_split
18
24 19
25 20 def _find_cmd(cmd):
26 21 """Find the full path to a command using which."""
27 22 paths = System.Environment.GetEnvironmentVariable("PATH").Split(os.pathsep)
28 23 for path in paths:
29 24 filename = os.path.join(path, cmd)
30 25 if System.IO.File.Exists(filename):
31 26 return py3compat.bytes_to_str(filename)
32 27 raise OSError("command %r not found" % cmd)
33 28
34 29 def system(cmd):
35 30 """
36 31 system(cmd) should work in a cli environment on Mac OSX, Linux,
37 32 and Windows
38 33 """
39 34 psi = System.Diagnostics.ProcessStartInfo(cmd)
40 35 psi.RedirectStandardOutput = True
41 36 psi.RedirectStandardError = True
42 37 psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
43 38 psi.UseShellExecute = False
44 39 # Start up process:
45 40 reg = System.Diagnostics.Process.Start(psi)
46 41
47 42 def getoutput(cmd):
48 43 """
49 44 getoutput(cmd) should work in a cli environment on Mac OSX, Linux,
50 45 and Windows
51 46 """
52 47 psi = System.Diagnostics.ProcessStartInfo(cmd)
53 48 psi.RedirectStandardOutput = True
54 49 psi.RedirectStandardError = True
55 50 psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
56 51 psi.UseShellExecute = False
57 52 # Start up process:
58 53 reg = System.Diagnostics.Process.Start(psi)
59 54 myOutput = reg.StandardOutput
60 55 output = myOutput.ReadToEnd()
61 56 myError = reg.StandardError
62 57 error = myError.ReadToEnd()
63 58 return output
64 59
65 60 def check_pid(pid):
66 61 """
67 62 Check if a process with the given PID (pid) exists
68 63 """
69 64 try:
70 65 System.Diagnostics.Process.GetProcessById(pid)
71 66 # process with given pid is running
72 67 return True
73 68 except System.InvalidOperationException:
74 69 # process wasn't started by this object (but is running)
75 70 return True
76 71 except System.ArgumentException:
77 72 # process with given pid isn't running
78 73 return False
@@ -1,25 +1,21 b''
1 1 """
2 2 This module has been deprecated since IPython 6.0.
3 3
4 4 Wrapper around linecache which decodes files to unicode according to PEP 263.
5 5 """
6 6 import functools
7 7 import linecache
8 import sys
9 8 from warnings import warn
10 9
11 from IPython.utils import py3compat
12 from IPython.utils import openpy
13
14 10 getline = linecache.getline
15 11
16 12 # getlines has to be looked up at runtime, because doctests monkeypatch it.
17 13 @functools.wraps(linecache.getlines)
18 14 def getlines(filename, module_globals=None):
19 15 """
20 16 Deprecated since IPython 6.0
21 17 """
22 18 warn(("`IPython.utils.ulinecache.getlines` is deprecated since"
23 19 " IPython 6.0 and will be removed in future versions."),
24 20 DeprecationWarning, stacklevel=2)
25 21 return linecache.getlines(filename, module_globals=module_globals)
General Comments 0
You need to be logged in to leave comments. Login now