#NEWLINE# def run( self , * args , **kwargs ) : #NEWLINE# #INDENT# compile_dir = settings_get ( 'compileDir' ) #NEWLINE# source_file = self . view . file_name ( ) #NEWLINE# source_dir = os . path . normcase ( os . path . dirname ( source_file ) ) #NEWLINE# try : #NEWLINE# #INDENT# project_file = self . view . window ( ) . project_file_name ( ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# project_file = '' #NEWLINE# #UNINDENT# if project_file : #NEWLINE# #INDENT# project_dir = os . path . normcase ( os . path . dirname ( project_file ) ) #NEWLINE# #UNINDENT# compile_paths = settings_get ( 'compilePaths' ) #NEWLINE# compress = settings_get ( 'compress' , False ) #NEWLINE# args = [ source_file ] #NEWLINE# if compress : #NEWLINE# #INDENT# args = ( [ '-c' ] + args ) #NEWLINE# #UNINDENT# use_autoprefixer = settings_get ( 'useAutoPrefixer' , False ) #NEWLINE# if ( use_autoprefixer is True ) : #NEWLINE# #INDENT# print ( 'Using autoprefixer...' ) #NEWLINE# args = ( [ '--use' , 'autoprefixer-stylus' ] + args ) #NEWLINE# #UNINDENT# if isinstance ( compile_paths , dict ) : #NEWLINE# #INDENT# appendix_len = None #NEWLINE# for key_path in compile_paths : #NEWLINE# #INDENT# norm_path = os . path . normcase ( key_path ) #NEWLINE# if ( ( not os . path . isabs ( norm_path ) ) and project_file ) : #NEWLINE# #INDENT# norm_path = os . path . join ( project_dir , norm_path ) #NEWLINE# #UNINDENT# appendix = os . path . relpath ( source_dir , norm_path ) #NEWLINE# if ( ( not appendix . startswith ( '..' ) ) and ( ( appendix_len is None ) or ( len ( appendix ) < appendix_len ) ) ) : #NEWLINE# #INDENT# appendix_len = len ( appendix ) #NEWLINE# compile_dir = compile_paths [ key_path ] #NEWLINE# if ( not os . path . isabs ( compile_dir ) ) : #NEWLINE# #INDENT# compile_dir = os . path . join ( norm_path , compile_dir ) #NEWLINE# #UNINDENT# compile_dir = os . path . join ( compile_dir , appendix ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( source_dir and isinstance ( compile_dir , str ) ) : #NEWLINE# #INDENT# if ( not os . path . isabs ( compile_dir ) ) : #NEWLINE# #INDENT# compile_dir = os . path . join ( source_dir , compile_dir ) #NEWLINE# #UNINDENT# print ( ( 'Compile to:' + compile_dir ) ) #NEWLINE# if ( not os . path . exists ( compile_dir ) ) : #NEWLINE# #INDENT# os . makedirs ( compile_dir ) #NEWLINE# print ( ( 'Compile dir did not exist, created folder: ' + compile_dir ) ) #NEWLINE# #UNINDENT# ( folder , file_nm ) = os . path . split ( source_file ) #NEWLINE# args = ( [ '--out' , compile_dir ] + args ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# compile_dir = source_dir #NEWLINE# print ( 'Compile to same directory' ) #NEWLINE# #UNINDENT# cwd = None #NEWLINE# result = run ( 'stylus' , args = args , cwd = cwd ) #NEWLINE# if ( result [ 'okay' ] is True ) : #NEWLINE# #INDENT# status = 'Compilation Succeeded' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# lines = result [ 'err' ] . splitlines ( ) #NEWLINE# if ( len ( lines ) >= 3 ) : #NEWLINE# #INDENT# line = lines [ 2 ] #NEWLINE# if re . search ( 'throw err;$' , line ) : #NEWLINE# #INDENT# lines = lines [ 4 : ] #NEWLINE# index = 0 #NEWLINE# linenb = 0 #NEWLINE# for line in lines : #NEWLINE# #INDENT# if re . search ( '^    at ' , line ) : #NEWLINE# #INDENT# linenb = index #NEWLINE# break #NEWLINE# #UNINDENT# index += 1 #NEWLINE# #UNINDENT# if ( linenb > 0 ) : #NEWLINE# #INDENT# lines = lines [ : ( linenb - 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# status = ( 'Compilation FAILED ' + lines [ 0 ] ) #NEWLINE# sublime . error_message ( '\n' . join ( lines ) ) #NEWLINE# #UNINDENT# later = ( lambda : sublime . status_message ( status ) ) #NEWLINE# sublime . set_timeout ( later , 300 )