From bd449ef67469433147c86cdd92d784237ad81c24 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 2 Jun 2017 11:32:16 -0700 Subject: [PATCH] Remove deprecated --watch --- sassc.py | 120 ++++++++++++++++++------------------------------------- 1 file changed, 38 insertions(+), 82 deletions(-) diff --git a/sassc.py b/sassc.py index 15461a8a..893f1ac4 100755 --- a/sassc.py +++ b/sassc.py @@ -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. @@ -75,9 +63,7 @@ import functools import io import optparse -import os import sys -import time import sass @@ -107,9 +93,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]' @@ -136,73 +119,46 @@ 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: + 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