Skip to content

Commit

Permalink
Merge pull request ipython#1762 from minrk/locate
Browse files Browse the repository at this point in the history
Add `locate` entry points; these would be useful for quickly locating IPython directories and profiles from other (non-Python) applications.

Examples:

    $> ipython locate
    /Users/me/.ipython
    
    $> ipython locate profile foo
    /Users/me/.ipython/profile_foo
    
    $> ipython locate profile 
    /Users/me/.ipython/profile_default
    
    $> ipython locate profile dne
    [ProfileLocate] Profile u'dne' not found.
  • Loading branch information
fperez committed Jun 10, 2012
2 parents e068d67 + 8d40a95 commit 9d29756
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
18 changes: 16 additions & 2 deletions IPython/core/profileapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
_main_examples = """
ipython profile create -h # show the help string for the create subcommand
ipython profile list -h # show the help string for the list subcommand
ipython locate profile foo # print the path to the directory for profile 'foo'
"""

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -115,6 +117,18 @@ def list_bundled_profiles():
return profiles


class ProfileLocate(BaseIPythonApplication):
description = """print the path an IPython profile dir"""

def parse_command_line(self, argv=None):
super(ProfileLocate, self).parse_command_line(argv)
if self.extra_args:
self.profile = self.extra_args[0]

def start(self):
print self.profile_dir.location


class ProfileList(Application):
name = u'ipython-profile'
description = list_help
Expand Down Expand Up @@ -277,8 +291,8 @@ class ProfileApp(Application):
examples = _main_examples

subcommands = Dict(dict(
create = (ProfileCreate, "Create a new profile dir with default config files"),
list = (ProfileList, "List existing profiles")
create = (ProfileCreate, ProfileCreate.description.splitlines()[0]),
list = (ProfileList, ProfileList.description.splitlines()[0]),
))

def start(self):
Expand Down
21 changes: 21 additions & 0 deletions IPython/frontend/terminal/ipapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
ipython profile create foo # create profile foo w/ default config files
ipython help profile # show the help for the profile subcmd
ipython locate # print the path to the IPython directory
ipython locate profile foo # print the path to the directory for profile `foo`
"""

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -180,6 +183,21 @@ def make_report(self,traceback):
# Main classes and functions
#-----------------------------------------------------------------------------


class LocateIPythonApp(BaseIPythonApplication):
description = """print the path to the IPython dir"""
subcommands = Dict(dict(
profile=('IPython.core.profileapp.ProfileLocate',
"print the path to an IPython profile directory",
),
))
def start(self):
if self.subapp is not None:
return self.subapp.start()
else:
print self.ipython_dir


class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
name = u'ipython'
description = usage.cl_usage
Expand Down Expand Up @@ -219,6 +237,9 @@ def _classes_default(self):
console=('IPython.frontend.terminal.console.app.ZMQTerminalIPythonApp',
"""Launch the IPython terminal-based Console."""
),
locate=('IPython.frontend.terminal.ipapp.LocateIPythonApp',
LocateIPythonApp.description
),
))

# *do* autocreate requested profile, but don't create the config file.
Expand Down
21 changes: 20 additions & 1 deletion docs/source/config/overview.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ configuration, and by default, all profiles will be stored in the so called
"IPython directory". The location of this directory is determined by the
following algorithm:

* If the ``ipython_dir`` command line flag is given, its value is used.
* If the ``ipython-dir`` command line flag is given, its value is used.

* If not, the value returned by :func:`IPython.utils.path.get_ipython_dir`
is used. This function will first look at the :envvar:`IPYTHONDIR`
Expand Down Expand Up @@ -324,6 +324,25 @@ under :file:`profile_default`. If you want the default config files for the
:mod:`IPython.parallel` applications, add ``--parallel`` to the end of the
command-line args.


Locating these files
--------------------

From the command-line, you can quickly locate the IPYTHONDIR or a specific
profile with:

.. sourcecode:: bash

$> ipython locate
/home/you/.ipython

$> ipython locate profile foo
/home/you/.ipython/profile_foo

These map to the utility functions: :func:`IPython.utils.path.get_ipython_dir`
and :func:`IPython.utils.path.locate_profile` respectively.


.. _Profiles:

Profiles
Expand Down

0 comments on commit 9d29756

Please sign in to comment.