Repository: ipython/ipython

Issue:
Subcommand `profile` ignores --ipython-dir 
Hi

`ipython profile create --ipython-dir=<local-dir> --reset` ignores `--ipython-dir` option and overwrites the default profile in `$HOME/.ipython`.

I'm using IPython from the current master with Python 2.7.5 on Mac OS X.  The below is the output I got with --debug option.  It says that `IPYTHONDIR` is set to `$HOME/.ipython`, but I have not set the variable at all.

```
[~/Desktop]$ \ipython profile create --ipython-dir=tmp --reset --debug
[ProfileCreate] Config changed:
[ProfileCreate] {'ProfileCreate': {'ipython_dir': u'tmp', 'log_level': 10, 'overwrite': True}}
[ProfileCreate] Using existing profile dir: u'tmp/profile_default'
[ProfileCreate] IPYTHONDIR set to: /Users/takeshi/.ipython
[ProfileCreate] Using existing profile dir: u'/Users/takeshi/.ipython/profile_default'
[ProfileCreate] Generating default config file: u'/Users/takeshi/.ipython/profile_default/ipython_config.py'
[ProfileCreate] IPYTHONDIR set to: /Users/takeshi/.ipython
[ProfileCreate] Using existing profile dir: u'/Users/takeshi/.ipython/profile_default'
[ProfileCreate] Generating default config file: u'/Users/takeshi/.ipython/profile_default/ipython_qtconsole_config.py'
[ProfileCreate] IPYTHONDIR set to: /Users/takeshi/.ipython
[ProfileCreate] Using existing profile dir: u'/Users/takeshi/.ipython/profile_default'
[ProfileCreate] Generating default config file: u'/Users/takeshi/.ipython/profile_default/ipython_notebook_config.py'
[ProfileCreate] IPYTHONDIR set to: /Users/takeshi/.ipython
[ProfileCreate] Using existing profile dir: u'/Users/takeshi/.ipython/profile_default'
[ProfileCreate] Generating default config file: u'/Users/takeshi/.ipython/profile_default/ipython_nbconvert_config.py'
[ProfileCreate] Searching path [u'/Users/takeshi/Desktop', u'tmp/profile_default'] for config files
[ProfileCreate] Attempting to load config file: ipython_config.py
[ProfileCreate] Config file ipython_config.py not found
[ProfileCreate] Attempting to load config file: ipython_profile_config.py
[ProfileCreate] Config file not found, skipping: ipython_profile_config.py
```

Thanks,

Takeshi



Discussion:

Resolving patch:
diff --git a/IPython/core/profileapp.py b/IPython/core/profileapp.py
--- a/IPython/core/profileapp.py
+++ b/IPython/core/profileapp.py
@@ -285,8 +285,8 @@ def init_config_files(self):
             app.log = self.log
             app.overwrite = self.overwrite
             app.copy_config_files=True
-            app.profile = self.profile
-            app.init_profile_dir()
+            app.ipython_dir=self.ipython_dir
+            app.profile_dir=self.profile_dir
             app.init_config_files()
 
     def stage_default_config_file(self):


Test patch:
diff --git a/IPython/core/tests/test_profile.py b/IPython/core/tests/test_profile.py
--- a/IPython/core/tests/test_profile.py
+++ b/IPython/core/tests/test_profile.py
@@ -36,7 +36,8 @@
 from IPython.testing import decorators as dec
 from IPython.testing import tools as tt
 from IPython.utils import py3compat
-
+from IPython.utils.process import getoutput
+from IPython.utils.tempdir import TemporaryDirectory
 
 #-----------------------------------------------------------------------------
 # Globals
@@ -151,3 +152,15 @@ def test_list_bundled_profiles():
     bundled_true = [u'cluster', u'math', u'pysh', u'sympy']
     bundled = sorted(list_bundled_profiles())
     nt.assert_equal(bundled, bundled_true)
+
+
+def test_profile_create_ipython_dir():
+    """ipython profile create respects --ipython-dir"""
+    with TemporaryDirectory() as td:
+        getoutput([sys.executable, '-m', 'IPython', 'profile', 'create',
+             'foo', '--ipython-dir=%s' % td])
+        profile_dir = os.path.join(td, 'profile_foo')
+        assert os.path.exists(profile_dir)
+        ipython_config = os.path.join(profile_dir, 'ipython_config.py')
+        assert os.path.exists(ipython_config)
+        
\ No newline at end of file