Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated --watch #203

Merged
merged 1 commit into from
Jun 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
120 changes: 38 additions & 82 deletions sassc.py
Original file line number Diff line number Diff line change
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 @@ -75,9 +63,7 @@
import functools
import io
import optparse
import os
import sys
import time

import sass

Expand Down Expand Up @@ -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]'
Expand All @@ -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


Expand Down