Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 549c811

Browse files
committed
Add sassc executable script
1 parent 740b6de commit 549c811

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

docs/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Version 0.2.4
66

77
To be released.
88

9+
- Added :mod:`sassc` CLI executable script.
910
- Added :const:`sass.OUTPUT_STYLES` constant map.
1011

1112

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ References
5151
.. toctree::
5252
:maxdepth: 2
5353

54+
sassc
5455
sass
5556
sassutils
5657

docs/sassc.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
.. program:: sassc
3+
4+
.. automodule:: sassc
5+
:members:

sassc.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
""":mod:`sassc` --- SassC compliant command line interface
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
This provides SassC_ compliant CLI executable named :program:`sassc`:
5+
6+
.. sourcecode:: console
7+
8+
$ sassc
9+
Usage: sassc [options] SCSS_FILE...
10+
11+
There are options as well:
12+
13+
.. option:: -s <style>, --output-style <style>
14+
15+
Coding style of the compiled result. The same as :func:`sass.compile()`
16+
function's ``output_style`` keyword argument. Default is ``nested``.
17+
18+
.. option:: -I <dir>, --include-path <dir>
19+
20+
Optional directory path to find ``@import``\ ed (S)CSS files.
21+
Can be multiply used.
22+
23+
.. option:: -i <dir>, --image-path <dir>
24+
25+
Path to find images. Default is the current directory (:file:`./`).
26+
27+
.. option:: -v, --version
28+
29+
Prints the program version.
30+
31+
.. option:: -h, --help
32+
33+
Prints the help message.
34+
35+
.. _SassC: https://github.com/hcatlin/sassc
36+
37+
"""
38+
import optparse
39+
import sys
40+
41+
from sass import __version__ as VERSION, OUTPUT_STYLES, CompileError, compile
42+
43+
44+
def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
45+
parser = optparse.OptionParser(usage='%prog [options] SCSS_FILE...',
46+
version='%prog ' + VERSION)
47+
output_styles = list(OUTPUT_STYLES)
48+
output_styles = ', '.join(output_styles[:-1]) + ', or ' + output_styles[-1]
49+
parser.add_option('-s', '--output-style', metavar='STYLE', type='choice',
50+
choices=list(OUTPUT_STYLES), default='nested',
51+
help='Coding style of the compiled result. Choose one '
52+
'of ' + output_styles + '. [default: %default]')
53+
parser.add_option('-I', '--include-path', metavar='DIR',
54+
dest='include_paths', action='append',
55+
help='Path to find "@import"ed (S)CSS source files. '
56+
'Can be multiply used.')
57+
parser.add_option('-i', '--image-path', metavar='DIR', default='./',
58+
help='Path to find images. [default: %default]')
59+
options, args = parser.parse_args(argv[1:])
60+
if not args:
61+
parser.print_usage(stderr)
62+
print >> stderr, parser.get_prog_name() + ': error:', \
63+
'too few arguments'
64+
return 2
65+
elif len(args) > 1:
66+
parser.print_usage(stderr)
67+
print >> stderr, parser.get_prog_name() + ': error:', \
68+
'too many arguments'
69+
return 2
70+
for filename in args:
71+
try:
72+
css = compile(
73+
filename=filename,
74+
output_style=options.output_style,
75+
include_paths=options.include_paths,
76+
image_path=options.image_path
77+
)
78+
except CompileError as e:
79+
print >> stderr, parser.get_prog_name() + ': error:', e
80+
return 1
81+
else:
82+
print css
83+
return 0
84+
85+
86+
if __name__ == '__main__':
87+
sys.exit(main())

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ def run(self):
127127
version=version,
128128
ext_modules=[sass_extension],
129129
packages=['sassutils'],
130-
py_modules=['sasstests'],
130+
py_modules=['sassc', 'sasstests'],
131131
package_data={'': ['README.rst', 'test/*.sass']},
132+
scripts=['sassc.py'],
132133
license='MIT License',
133134
author='Hong Minhee',
134135
author_email='minhee' '@' 'dahlia.kr',
@@ -139,6 +140,9 @@ def run(self):
139140
],
140141
'distutils.setup_keywords': [
141142
'sass_manifests = sassutils.distutils:validate_manifests'
143+
],
144+
'console_scripts': [
145+
['sassc = sassc:main']
142146
]
143147
},
144148
tests_require=['Attest', 'Werkzeug'],

0 commit comments

Comments
 (0)