Skip to content

Commit bd449ef

Browse files
committed
Remove deprecated --watch
1 parent d02e788 commit bd449ef

File tree

1 file changed

+38
-82
lines changed

1 file changed

+38
-82
lines changed

sassc.py

+38-82
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,6 @@
3535
3636
.. versionadded:: 0.4.0
3737
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-
5038
.. option:: -p, --precision
5139
5240
Set the precision for numbers. Default is 5.
@@ -75,9 +63,7 @@
7563
import functools
7664
import io
7765
import optparse
78-
import os
7966
import sys
80-
import time
8167

8268
import sass
8369

@@ -107,9 +93,6 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
10793
dest='include_paths', action='append',
10894
help='Path to find "@import"ed (S)CSS source files. '
10995
'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).')
11396
parser.add_option(
11497
'-p', '--precision', action='store', type='int', default=5,
11598
help='Set the precision for numbers. [default: %default]'
@@ -136,73 +119,46 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
136119
error('-m/-g/--sourcemap requires the second argument, the output '
137120
'css filename.')
138121
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
122+
123+
try:
124+
if options.source_map:
125+
source_map_filename = args[1] + '.map' # FIXME
126+
css, source_map = sass.compile(
127+
filename=filename,
128+
output_style=options.style,
129+
source_comments=options.source_comments,
130+
source_map_filename=source_map_filename,
131+
output_filename_hint=args[1],
132+
include_paths=options.include_paths,
133+
precision=options.precision
134+
)
179135
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
136+
source_map_filename = None
137+
source_map = None
138+
css = sass.compile(
139+
filename=filename,
140+
output_style=options.style,
141+
source_comments=options.source_comments,
142+
include_paths=options.include_paths,
143+
precision=options.precision
144+
)
145+
except (IOError, OSError) as e:
146+
error(e)
147+
return 3
148+
except sass.CompileError as e:
149+
error(e)
150+
return 1
151+
else:
152+
if len(args) < 2:
153+
print(css, file=stdout)
204154
else:
205-
break
155+
with io.open(args[1], 'w', encoding='utf-8', newline='') as f:
156+
f.write(css)
157+
if source_map_filename:
158+
with io.open(
159+
source_map_filename, 'w', encoding='utf-8', newline='',
160+
) as f:
161+
f.write(source_map)
206162
return 0
207163

208164

0 commit comments

Comments
 (0)