Repository: spyder-ide/spyder

Issue:
'Connect to existing kernel' fails if json file not in PWD
I'm using Spyder 2.3.4 on OS X, trying to connect to an existing (remote) IPython kernel.  I successfully connected to the kernel using

```
ipython qtconsole --existing /path/to/json/file/kernel-4957.json
```

but get an error **Unable to connect to IPython kernel-4957.json** when attempting to connect via Spyder.

I was eventually able to connect by moving the kernel-4957.json file to my home directory (which was also my PWD).  The requirement that the json file is in the PWD is totally unexpected, since the "Connect to an existing terminal" dialog box allows me to navigate to find a json file in any directory on my computer.



Discussion:
@SylvainCorlay ?

If your kernel file is not in

```
~/.ipython/profile_default/security
```

then it won't automatically be detected by us. I mean, if you only write `kernel-4957.json` or just `4957` in the _Connect info_ field of our _Connect to an existing kernel_ dialog, and the kernel file is not in that dir, then we can't connect to it.

But for kernel files in other places, that dialog has a _Browse_ button to browse your file system and select it.

@michaelstepner, have you used it?

It is not required for the JSON file to be in current workind directory.
- If you only type the _name_ of the file in the dialog, it is going to look into your security directory and the current working directory.
- If your connection file is elsewhere, you must specify the full path. Using the Browse button would allow you to set this up.

When I use the _Browse_ button to navigate to the json file, the Connection Info field is successfully filled with the full path `/path/to/json/file/kernel-4957.json`.  But when I hit OK, I get the error **Unable to connect to IPython kernel-4957.json**.

If I then copy the `kernel-4957.json` file to my home directory, I can repeat the process and successfully connect.  Once it's in my home directory, I successfully connect to the existing kernel **regardless** of whether I select the json file in my home directory, or the one buried in my directory tree.

If I delete the json file from my home directory, I can no longer connect to the kernel.  I get the same **Unable to connect** error again.

Thanks for detailing. This would require me to test on a mac because I am not reproducing your issue. 

Is the original location of the connection file special in that
- the path would have special characters, spaces
- it is a network drive
  Does it only work in your home directory. 

Another question: is the connection file name actually `kernel-4957.json`?

@ccordoba12 looking at the current master branch for `_create_client_for_kernel`, I see 

``` Python
if not cf.startswith('kernel') and not cf.endswith('json'):
    cf = to_text_string('kernel-' + cf + '.json')
find_connection_file(cf, profile='default')
```

while IPython's `find_connection_file` already makes that addition. (This was added in https://github.com/spyder-ide/spyder/commit/b2496c67f6eb829ca71a70647a5f98539a46b424). 

I think we would only need the last line.

@SylvainCorlay Thanks for looking into this!  Answering your questions:
- The full path has no special characters: `/Users/michael/Documents/git_dssg/kernel-4957.json`
- It's a local directory.
- I have only successfully connected to the kernel when the `kernel-4957.json` file is in my home directory. But when it is in my home directory, I can also connect to the kernel by using the json connection file that's not in my home.
- Yes, my connection file name is exactly `kernel-4957.json`


Resolving patch:
diff --git a/spyderlib/plugins/ipythonconsole.py b/spyderlib/plugins/ipythonconsole.py
--- a/spyderlib/plugins/ipythonconsole.py
+++ b/spyderlib/plugins/ipythonconsole.py
@@ -1058,8 +1058,6 @@ def _create_client_for_kernel(self, cf, hostname, kf, pw):
         # Verifying if the connection file exists
         cf = osp.basename(cf)
         try:
-            if not cf.startswith('kernel') and not cf.endswith('json'):
-                cf = to_text_string('kernel-' + cf + '.json')
             find_connection_file(cf, profile='default')
         except (IOError, UnboundLocalError):
             QMessageBox.critical(self, _('IPython'),


Test patch: