From 0d0d20882e45c41b0d37d1cecf73c89a5e0aa5f7 2012-06-10 21:51:53 From: Fernando Perez Date: 2012-06-10 21:51:53 Subject: [PATCH] Merge pull request #1762 from minrk/locate 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. --- diff --git a/IPython/core/profileapp.py b/IPython/core/profileapp.py index 4520c4a..f83fd13 100644 --- a/IPython/core/profileapp.py +++ b/IPython/core/profileapp.py @@ -85,6 +85,8 @@ ipython profile create foo --parallel # also stage parallel config files _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' """ #----------------------------------------------------------------------------- @@ -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 @@ -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): diff --git a/IPython/frontend/terminal/ipapp.py b/IPython/frontend/terminal/ipapp.py index 310944d..e33e309 100755 --- a/IPython/frontend/terminal/ipapp.py +++ b/IPython/frontend/terminal/ipapp.py @@ -78,6 +78,9 @@ ipython help notebook # show the help for the notebook subcmd 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` """ #----------------------------------------------------------------------------- @@ -180,6 +183,21 @@ aliases.update(shell_aliases) # 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 @@ -219,6 +237,9 @@ class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): 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. diff --git a/docs/source/config/overview.txt b/docs/source/config/overview.txt index a0f6a0b..759fe4b 100644 --- a/docs/source/config/overview.txt +++ b/docs/source/config/overview.txt @@ -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` @@ -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