Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Deprecate sassc for pysassc #262

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

Merged
merged 1 commit into from
Sep 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ References
.. toctree::
:maxdepth: 2

sassc
pysassc
sass
sassutils

Expand Down
4 changes: 2 additions & 2 deletions docs/sassc.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

.. program:: sassc
.. program:: pysassc

.. automodule:: sassc
.. automodule:: pysassc
:members:
182 changes: 182 additions & 0 deletions pysassc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#!/usr/bin/env python
r""":mod:`pysassc` --- SassC compliant command line interface
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This provides SassC_ compliant CLI executable named :program:`pysassc`:

.. sourcecode:: console

$ pysassc
Usage: pysassc [options] SCSS_FILE [CSS_FILE]

There are options as well:

.. option:: -t <style>, --style <style>

Coding style of the compiled result. The same as :func:`sass.compile()`
function's ``output_style`` keyword argument. Default is ``nested``.

.. option:: -s <style>, --output-style <style>

Alias for -t / --style.

.. deprecated:: 0.11.0

.. option:: -I <dir>, --include-path <dir>

Optional directory path to find ``@import``\ ed (S)CSS files.
Can be multiply used.

.. option:: -m, -g, --sourcemap

Emit source map. Requires the second argument (output CSS filename).
The filename of source map will be the output CSS filename followed by
:file:`.map`.

.. versionadded:: 0.4.0

.. option:: -p, --precision

Set the precision for numbers. Default is 5.

.. versionadded:: 0.7.0

.. option:: --source-comments

Include debug info in output.

.. versionadded:: 0.11.0

.. option:: -v, --version

Prints the program version.

.. option:: -h, --help

Prints the help message.

.. _SassC: https://github.com/sass/sassc

"""
from __future__ import print_function

import functools
import io
import optparse
import sys

import sass


def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
parser = optparse.OptionParser(
usage='%prog [options] SCSS_FILE [OUT_CSS_FILE]',
version='%prog {} (sass/libsass {})'.format(
sass.__version__, sass.libsass_version,
),
)
output_styles = list(sass.OUTPUT_STYLES)
output_styles = ', '.join(output_styles[:-1]) + ', or ' + output_styles[-1]
parser.add_option(
'-t', '--style', '-s', '--output-style', metavar='STYLE',
type='choice', choices=list(sass.OUTPUT_STYLES), default='nested',
help=(
'Coding style of the compiled result. Choose one of ' +
output_styles + '. [default: %default]'
),
)
parser.add_option(
'-m', '-g', '--sourcemap', dest='source_map',
action='store_true', default=False,
help='Emit source map. Requires the second argument '
'(output css filename).',
)
parser.add_option(
'-I', '--include-path', metavar='DIR',
dest='include_paths', action='append',
help='Path to find "@import"ed (S)CSS source files. '
'Can be multiply used.',
)
parser.add_option(
'-p', '--precision', action='store', type='int', default=5,
help='Set the precision for numbers. [default: %default]',
)
parser.add_option(
'--source-comments', action='store_true', default=False,
help='Include debug info in output',
)
parser.add_option(
'--import-extensions',
dest='custom_import_extensions', action='append',
help='Extra extensions allowed for sass imports. '
'Can be multiply used.',
)
options, args = parser.parse_args(argv[1:])
error = functools.partial(
print,
parser.get_prog_name() + ': error:',
file=stderr,
)
if not args:
parser.print_usage(stderr)
error('too few arguments')
return 2
elif len(args) > 2:
parser.print_usage(stderr)
error('too many arguments')
return 2
filename = args[0]
if options.source_map and len(args) < 2:
parser.print_usage(stderr)
error(
'-m/-g/--sourcemap requires the second argument, the output '
'css filename.',
)
return 2

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,
custom_import_extensions=options.custom_import_extensions,
)
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,
custom_import_extensions=options.custom_import_extensions,
)
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:
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


if __name__ == '__main__':
sys.exit(main())
2 changes: 1 addition & 1 deletion sass.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def my_importer(path):
"values like 'none', 'line_numbers', and 'map' for "
'the source_comments parameter are deprecated; ' +
deprecation_message,
DeprecationWarning,
FutureWarning,
)
if not isinstance(source_comments, bool):
raise TypeError('source_comments must be bool, not ' +
Expand Down
Loading