Skip to content

Commit

Permalink
Remove deprecated --watch
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jun 2, 2017
1 parent d02e788 commit 70464cc
Showing 1 changed file with 39 additions and 80 deletions.
119 changes: 39 additions & 80 deletions sassc.py
Expand Up @@ -35,18 +35,6 @@
.. versionadded:: 0.4.0
.. option:: -w, --watch
Watch file for changes. Requires the second argument (output CSS
filename).
.. note:: Note that ``--watch`` does not understand imports. Due to this, the
option is scheduled for removal in a future version. It is suggested to
use a third party tool which implements intelligent watching functionality.
.. versionadded:: 0.4.0
.. deprecated:: 0.11.2
.. option:: -p, --precision
Set the precision for numbers. Default is 5.
Expand Down Expand Up @@ -107,9 +95,6 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
dest='include_paths', action='append',
help='Path to find "@import"ed (S)CSS source files. '
'Can be multiply used.')
parser.add_option('-w', '--watch', action='store_true',
help='Watch file for changes. Requires the second '
'argument (output css filename).')
parser.add_option(
'-p', '--precision', action='store', type='int', default=5,
help='Set the precision for numbers. [default: %default]'
Expand All @@ -136,73 +121,47 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
error('-m/-g/--sourcemap requires the second argument, the output '
'css filename.')
return 2
elif options.watch and len(args) < 2:
parser.print_usage(stderr)
error('-w/--watch requires the second argument, the output css '
'filename.')
return 2
else:
pass
while True:
try:
mtime = os.stat(filename).st_mtime
if options.source_map:
source_map_filename = args[1] + '.map' # FIXME
css, source_map = sass.compile(
filename=filename,
output_style=options.style,
source_comments=options.source_comments,
source_map_filename=source_map_filename,
output_filename_hint=args[1],
include_paths=options.include_paths,
precision=options.precision
)
else:
source_map_filename = None
source_map = None
css = sass.compile(
filename=filename,
output_style=options.style,
source_comments=options.source_comments,
include_paths=options.include_paths,
precision=options.precision
)
except (IOError, OSError) as e:
error(e)
return 3
except sass.CompileError as e:
error(e)
if not options.watch:
return 1
except KeyboardInterrupt:
break

try:
mtime = os.stat(filename).st_mtime
if options.source_map:
source_map_filename = args[1] + '.map' # FIXME
css, source_map = sass.compile(
filename=filename,
output_style=options.style,
source_comments=options.source_comments,
source_map_filename=source_map_filename,
output_filename_hint=args[1],
include_paths=options.include_paths,
precision=options.precision
)
else:
if len(args) < 2:
print(css, file=stdout)
else:
with io.open(args[1], 'w', encoding='utf-8', newline='') as f:
f.write(css)
if options.watch:
print(filename, 'is just compiled to', args[1],
file=stdout)
if source_map_filename:
with io.open(
source_map_filename, 'w', encoding='utf-8', newline='',
) as f:
f.write(source_map)
if options.watch: # pragma: no cover
# FIXME: we should utilize inotify on Linux, and FSEvents on Mac
while True:
try:
st = os.stat(filename)
if st.st_mtime > mtime:
print(filename, 'changed; recompile...', file=stdout)
break
time.sleep(0.5)
except KeyboardInterrupt:
return 0
source_map_filename = None
source_map = None
css = sass.compile(
filename=filename,
output_style=options.style,
source_comments=options.source_comments,
include_paths=options.include_paths,
precision=options.precision
)
except (IOError, OSError) as e:
error(e)
return 3
except sass.CompileError as e:
error(e)
return 1
else:
if len(args) < 2:
print(css, file=stdout)
else:
break
with io.open(args[1], 'w', encoding='utf-8', newline='') as f:
f.write(css)
if source_map_filename:
with io.open(
source_map_filename, 'w', encoding='utf-8', newline='',
) as f:
f.write(source_map)
return 0


Expand Down

0 comments on commit 70464cc

Please sign in to comment.