Home Download Buy Blog Forum Support

lookup_symbol_in_index and filename problem in Windows

lookup_symbol_in_index and filename problem in Windows

Postby erichard on Sun Apr 14, 2013 11:26 am

Hi folks !

I'm the author of the PHPCompanion plugin and I have a strange issue on windows platform.

Basically the problem is that Python can't open a unix-like filename on Windows. The filename I use is given by the lookup_symbol_in_index method and the error look like :

Code: Select all
FileNotFoundError: [Errno 2] No such file or directory: '/C/wamp/www/subdomains/laravel-develop/vendor/laravel/framework/src/Illuminate/Routing/Route.php'


Maybe I need some sort of path conversion but I can't find any clue on the web. Any ideas ?
erichard
 
Posts: 3
Joined: Sun Apr 14, 2013 11:15 am

Re: lookup_symbol_in_index and filename problem in Windows

Postby skuroda on Sun Apr 14, 2013 6:15 pm

Think this would work, but you should probably test it just to make sure. I'm far from a regex expert, so there's probably a better way to do it. Perhaps someone will post it.

Code: Select all
win_path = re.sub(r"/([A-Za-z])/(.+)", r"\1:/\2", nix_path)
win_path = re.sub(r"/", r"\\", win_path)


It converts the posted path to
Code: Select all
C:\wamp\www\subdomains\laravel-develop\vendor\laravel\framework\src\Illuminate\Routing\Route.php
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: lookup_symbol_in_index and filename problem in Windows

Postby erichard on Mon Apr 15, 2013 1:11 pm

Hi,

I would like to avoid platform specific code. Your solution may work on Window but not on Unix system.
erichard
 
Posts: 3
Joined: Sun Apr 14, 2013 11:15 am

Re: lookup_symbol_in_index and filename problem in Windows

Postby skuroda on Mon Apr 15, 2013 5:16 pm

True, but since I'm sure you would want to get your plugin up and running in for windows users also, wouldn't it be beneficial to have a short term solution like this?
Code: Select all
def normalize_to_system_style_path(path)
    if sublime.platform() == "windows":
        path= re.sub(r"/([A-Za-z])/(.+)", r"\1:/\2", path)
        path= re.sub(r"/", r"\\", path)
    return path


Then if/when the API return value gets changed, you can remove this method?
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: lookup_symbol_in_index and filename problem in Windows

Postby erichard on Mon Apr 15, 2013 7:14 pm

Yeah, you're right.

Your code works fine, thank for the help :-)
erichard
 
Posts: 3
Joined: Sun Apr 14, 2013 11:15 am


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 6 guests