1616from warnings import warn
1717from hashlib import md5
1818
19- import IPython
2019from IPython .testing .skipdoctest import skip_doctest
2120from IPython .utils .process import system
22- from IPython .utils .importstring import import_item
2321from IPython .utils import py3compat
2422from IPython .utils .decorators import undoc
2523
@@ -256,111 +254,35 @@ def get_xdg_cache_dir():
256254 return None
257255
258256
257+ @undoc
259258def get_ipython_dir ():
260- """Get the IPython directory for this platform and user.
261-
262- This uses the logic in `get_home_dir` to find the home directory
263- and then adds .ipython to the end of the path.
264- """
265-
266- env = os .environ
267- pjoin = os .path .join
268-
269-
270- ipdir_def = '.ipython'
271-
272- home_dir = get_home_dir ()
273- xdg_dir = get_xdg_dir ()
274-
275- # import pdb; pdb.set_trace() # dbg
276- if 'IPYTHON_DIR' in env :
277- warn ('The environment variable IPYTHON_DIR is deprecated. '
278- 'Please use IPYTHONDIR instead.' )
279- ipdir = env .get ('IPYTHONDIR' , env .get ('IPYTHON_DIR' , None ))
280- if ipdir is None :
281- # not set explicitly, use ~/.ipython
282- ipdir = pjoin (home_dir , ipdir_def )
283- if xdg_dir :
284- # Several IPython versions (up to 1.x) defaulted to .config/ipython
285- # on Linux. We have decided to go back to using .ipython everywhere
286- xdg_ipdir = pjoin (xdg_dir , 'ipython' )
287-
288- if _writable_dir (xdg_ipdir ):
289- cu = compress_user
290- if os .path .exists (ipdir ):
291- warn (('Ignoring {0} in favour of {1}. Remove {0} to '
292- 'get rid of this message' ).format (cu (xdg_ipdir ), cu (ipdir )))
293- elif os .path .islink (xdg_ipdir ):
294- warn (('{0} is deprecated. Move link to {1} to '
295- 'get rid of this message' ).format (cu (xdg_ipdir ), cu (ipdir )))
296- else :
297- warn ('Moving {0} to {1}' .format (cu (xdg_ipdir ), cu (ipdir )))
298- shutil .move (xdg_ipdir , ipdir )
299-
300- ipdir = os .path .normpath (os .path .expanduser (ipdir ))
301-
302- if os .path .exists (ipdir ) and not _writable_dir (ipdir ):
303- # ipdir exists, but is not writable
304- warn ("IPython dir '{0}' is not a writable location,"
305- " using a temp directory." .format (ipdir ))
306- ipdir = tempfile .mkdtemp ()
307- elif not os .path .exists (ipdir ):
308- parent = os .path .dirname (ipdir )
309- if not _writable_dir (parent ):
310- # ipdir does not exist and parent isn't writable
311- warn ("IPython parent '{0}' is not a writable location,"
312- " using a temp directory." .format (parent ))
313- ipdir = tempfile .mkdtemp ()
314-
315- return py3compat .cast_unicode (ipdir , fs_encoding )
316-
259+ warn ("get_ipython_dir has moved to the IPython.paths module" )
260+ from IPython .paths import get_ipython_dir
261+ return get_ipython_dir ()
317262
263+ @undoc
318264def get_ipython_cache_dir ():
319- """Get the cache directory it is created if it does not exist."""
320- xdgdir = get_xdg_cache_dir ()
321- if xdgdir is None :
322- return get_ipython_dir ()
323- ipdir = os .path .join (xdgdir , "ipython" )
324- if not os .path .exists (ipdir ) and _writable_dir (xdgdir ):
325- ensure_dir_exists (ipdir )
326- elif not _writable_dir (xdgdir ):
327- return get_ipython_dir ()
328-
329- return py3compat .cast_unicode (ipdir , fs_encoding )
330-
265+ warn ("get_ipython_cache_dir has moved to the IPython.paths module" )
266+ from IPython .paths import get_ipython_cache_dir
267+ return get_ipython_cache_dir ()
331268
269+ @undoc
332270def get_ipython_package_dir ():
333- """Get the base directory where IPython itself is installed."""
334- ipdir = os .path .dirname (IPython .__file__ )
335- return py3compat .cast_unicode (ipdir , fs_encoding )
336-
271+ warn ("get_ipython_package_dir has moved to the IPython.paths module" )
272+ from IPython .paths import get_ipython_package_dir
273+ return get_ipython_package_dir ()
337274
275+ @undoc
338276def get_ipython_module_path (module_str ):
339- """Find the path to an IPython module in this version of IPython.
340-
341- This will always find the version of the module that is in this importable
342- IPython package. This will always return the path to the ``.py``
343- version of the module.
344- """
345- if module_str == 'IPython' :
346- return os .path .join (get_ipython_package_dir (), '__init__.py' )
347- mod = import_item (module_str )
348- the_path = mod .__file__ .replace ('.pyc' , '.py' )
349- the_path = the_path .replace ('.pyo' , '.py' )
350- return py3compat .cast_unicode (the_path , fs_encoding )
277+ warn ("get_ipython_module_path has moved to the IPython.paths module" )
278+ from IPython .paths import get_ipython_module_path
279+ return get_ipython_module_path (module_str )
351280
281+ @undoc
352282def locate_profile (profile = 'default' ):
353- """Find the path to the folder associated with a given profile.
354-
355- I.e. find $IPYTHONDIR/profile_whatever.
356- """
357- from IPython .core .profiledir import ProfileDir , ProfileDirError
358- try :
359- pd = ProfileDir .find_profile_dir_by_name (get_ipython_dir (), profile )
360- except ProfileDirError :
361- # IOError makes more sense when people are expecting a path
362- raise IOError ("Couldn't find profile %r" % profile )
363- return pd .location
283+ warn ("locate_profile has moved to the IPython.paths module" )
284+ from IPython .paths import locate_profile
285+ return locate_profile (profile = profile )
364286
365287def expand_path (s ):
366288 """Expand $VARS and ~names in a string, like a shell
@@ -453,36 +375,11 @@ def filehash(path):
453375 with open (path , "rU" ) as f :
454376 return md5 (py3compat .str_to_bytes (f .read ())).hexdigest ()
455377
378+ @undoc
456379def get_security_file (filename , profile = 'default' ):
457- """Return the absolute path of a security file given by filename and profile
458-
459- This allows users and developers to find security files without
460- knowledge of the IPython directory structure. The search path
461- will be ['.', profile.security_dir]
462-
463- Parameters
464- ----------
465-
466- filename : str
467- The file to be found. If it is passed as an absolute path, it will
468- simply be returned.
469- profile : str [default: 'default']
470- The name of the profile to search. Leaving this unspecified
471- The file to be found. If it is passed as an absolute path, fname will
472- simply be returned.
473-
474- Returns
475- -------
476- Raises :exc:`IOError` if file not found or returns absolute path to file.
477- """
478- # import here, because profiledir also imports from utils.path
479- from IPython .core .profiledir import ProfileDir
480- try :
481- pd = ProfileDir .find_profile_dir_by_name (get_ipython_dir (), profile )
482- except Exception :
483- # will raise ProfileDirError if no such profile
484- raise IOError ("Profile %r not found" )
485- return filefind (filename , ['.' , pd .security_dir ])
380+ warn ("get_security_file has moved to the IPython.paths module" )
381+ from IPython .paths import get_security_file
382+ return get_security_file (filename , profile = profile )
486383
487384
488385ENOLINK = 1998
0 commit comments