35
35
36
36
.. versionadded:: 0.4.0
37
37
38
- .. option:: -w, --watch
39
-
40
- Watch file for changes. Requires the second argument (output CSS
41
- filename).
42
-
43
- .. note:: Note that ``--watch`` does not understand imports. Due to this, the
44
- option is scheduled for removal in a future version. It is suggested to
45
- use a third party tool which implements intelligent watching functionality.
46
-
47
- .. versionadded:: 0.4.0
48
- .. deprecated:: 0.11.2
49
-
50
38
.. option:: -p, --precision
51
39
52
40
Set the precision for numbers. Default is 5.
77
65
import optparse
78
66
import os
79
67
import sys
80
- import time
81
68
82
69
import sass
83
70
@@ -107,9 +94,6 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
107
94
dest = 'include_paths' , action = 'append' ,
108
95
help = 'Path to find "@import"ed (S)CSS source files. '
109
96
'Can be multiply used.' )
110
- parser .add_option ('-w' , '--watch' , action = 'store_true' ,
111
- help = 'Watch file for changes. Requires the second '
112
- 'argument (output css filename).' )
113
97
parser .add_option (
114
98
'-p' , '--precision' , action = 'store' , type = 'int' , default = 5 ,
115
99
help = 'Set the precision for numbers. [default: %default]'
@@ -136,73 +120,46 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
136
120
error ('-m/-g/--sourcemap requires the second argument, the output '
137
121
'css filename.' )
138
122
return 2
139
- elif options .watch and len (args ) < 2 :
140
- parser .print_usage (stderr )
141
- error ('-w/--watch requires the second argument, the output css '
142
- 'filename.' )
143
- return 2
144
- else :
145
- pass
146
- while True :
147
- try :
148
- mtime = os .stat (filename ).st_mtime
149
- if options .source_map :
150
- source_map_filename = args [1 ] + '.map' # FIXME
151
- css , source_map = sass .compile (
152
- filename = filename ,
153
- output_style = options .style ,
154
- source_comments = options .source_comments ,
155
- source_map_filename = source_map_filename ,
156
- output_filename_hint = args [1 ],
157
- include_paths = options .include_paths ,
158
- precision = options .precision
159
- )
160
- else :
161
- source_map_filename = None
162
- source_map = None
163
- css = sass .compile (
164
- filename = filename ,
165
- output_style = options .style ,
166
- source_comments = options .source_comments ,
167
- include_paths = options .include_paths ,
168
- precision = options .precision
169
- )
170
- except (IOError , OSError ) as e :
171
- error (e )
172
- return 3
173
- except sass .CompileError as e :
174
- error (e )
175
- if not options .watch :
176
- return 1
177
- except KeyboardInterrupt :
178
- break
123
+
124
+ try :
125
+ if options .source_map :
126
+ source_map_filename = args [1 ] + '.map' # FIXME
127
+ css , source_map = sass .compile (
128
+ filename = filename ,
129
+ output_style = options .style ,
130
+ source_comments = options .source_comments ,
131
+ source_map_filename = source_map_filename ,
132
+ output_filename_hint = args [1 ],
133
+ include_paths = options .include_paths ,
134
+ precision = options .precision
135
+ )
179
136
else :
180
- if len (args ) < 2 :
181
- print (css , file = stdout )
182
- else :
183
- with io .open (args [1 ], 'w' , encoding = 'utf-8' , newline = '' ) as f :
184
- f .write (css )
185
- if options .watch :
186
- print (filename , 'is just compiled to' , args [1 ],
187
- file = stdout )
188
- if source_map_filename :
189
- with io .open (
190
- source_map_filename , 'w' , encoding = 'utf-8' , newline = '' ,
191
- ) as f :
192
- f .write (source_map )
193
- if options .watch : # pragma: no cover
194
- # FIXME: we should utilize inotify on Linux, and FSEvents on Mac
195
- while True :
196
- try :
197
- st = os .stat (filename )
198
- if st .st_mtime > mtime :
199
- print (filename , 'changed; recompile...' , file = stdout )
200
- break
201
- time .sleep (0.5 )
202
- except KeyboardInterrupt :
203
- return 0
137
+ source_map_filename = None
138
+ source_map = None
139
+ css = sass .compile (
140
+ filename = filename ,
141
+ output_style = options .style ,
142
+ source_comments = options .source_comments ,
143
+ include_paths = options .include_paths ,
144
+ precision = options .precision
145
+ )
146
+ except (IOError , OSError ) as e :
147
+ error (e )
148
+ return 3
149
+ except sass .CompileError as e :
150
+ error (e )
151
+ return 1
152
+ else :
153
+ if len (args ) < 2 :
154
+ print (css , file = stdout )
204
155
else :
205
- break
156
+ with io .open (args [1 ], 'w' , encoding = 'utf-8' , newline = '' ) as f :
157
+ f .write (css )
158
+ if source_map_filename :
159
+ with io .open (
160
+ source_map_filename , 'w' , encoding = 'utf-8' , newline = '' ,
161
+ ) as f :
162
+ f .write (source_map )
206
163
return 0
207
164
208
165
0 commit comments