From 80d5150b12f337eff6ddbac90a13cf70965d0364 Mon Sep 17 00:00:00 2001 From: Thijs Busser Date: Mon, 10 Jun 2013 21:52:22 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Fixed=20an=20error=20when=20a=20file=20name?= =?UTF-8?q?=20contains=20a=20special=20char=20like=20=C3=A9.=20Tested=20in?= =?UTF-8?q?=20both=20ST2=20and=20ST3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesscompiler.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lesscompiler.py b/lesscompiler.py index 90b2181..9a5e458 100644 --- a/lesscompiler.py +++ b/lesscompiler.py @@ -281,6 +281,12 @@ def parseBaseDirs(self, base_dir='./', output_dir=''): proj_folders = window.folders() # loop through all the top level folders in the project for folder in proj_folders: + # there was a problem when fn contains a special char like é. An error would + # occur when checking if fn starts with the folder. Converting folder to utf_8 + # seems to fix this error + if sys.version_info < (3, 0, 0) and not platform.system() is 'Windows': + print('Had to encode folder with utf_8 to ' + folder) + folder = folder.encode('utf_8') # we will have found the project folder when it matches with the start of the current file name if fn.startswith(folder): # keep the current folder as the project folder From e06622f50c781f8a4c6a0683722658ad70ade9c9 Mon Sep 17 00:00:00 2001 From: Thijs Busser Date: Mon, 10 Jun 2013 22:57:24 +0200 Subject: [PATCH 2/2] Some fixes after testing on Windows 7. --- lesscompiler.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lesscompiler.py b/lesscompiler.py index 9a5e458..4d33063 100644 --- a/lesscompiler.py +++ b/lesscompiler.py @@ -164,6 +164,11 @@ def convertLess2Css(self, lessc_command, dirs, file='', minimised=True, outputFi if not lessc_command: lessc_command = "lessc" + # by trying it on both OSX and Windows this seems to be the combination that works + if sys.version_info < (3, 0, 0) and platform.system() is 'Windows': + less = less.encode(sys.getfilesystemencoding()) + css = css.encode(sys.getfilesystemencoding()) + # get the name of the platform (ie are we running on windows) platform_name = platform.system() # check if the compiler should create a minified CSS file @@ -240,8 +245,8 @@ def parseBaseDirs(self, base_dir='./', output_dir=''): fn = self.view.file_name() # in Python 3 all string are Unicode by default, we only have to encode when running on something lower than 3 # in addition Windows uses UTF-16 for its file names so we don't encode to UTF-8 on Windows - if sys.version_info < (3, 0, 0) and not platform.system() is "Windows": - fn = fn.encode("utf_8") + if sys.version_info < (3, 0, 0): # and not platform.system() is "Windows": + fn = fn.encode(sys.getfilesystemencoding()) # get the folder of the current file file_dir = os.path.dirname(fn) @@ -284,9 +289,8 @@ def parseBaseDirs(self, base_dir='./', output_dir=''): # there was a problem when fn contains a special char like é. An error would # occur when checking if fn starts with the folder. Converting folder to utf_8 # seems to fix this error - if sys.version_info < (3, 0, 0) and not platform.system() is 'Windows': - print('Had to encode folder with utf_8 to ' + folder) - folder = folder.encode('utf_8') + if sys.version_info < (3, 0, 0): # and not platform.system() is 'Windows': + folder = folder.encode(sys.getfilesystemencoding()) # we will have found the project folder when it matches with the start of the current file name if fn.startswith(folder): # keep the current folder as the project folder