Skip to content

Commit cb95812

Browse files
committed
Version string
1 parent 35d1794 commit cb95812

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

sass.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static PyMethodDef sass_methods[] = {
339339
PyMODINIT_FUNC
340340
initsass()
341341
{
342-
PyObject *module;
342+
PyObject *module, *version;
343343

344344
if (PyType_Ready(&sass_OptionsType) < 0) {
345345
return;
@@ -353,6 +353,12 @@ initsass()
353353
if (module == NULL) {
354354
return;
355355
}
356+
#ifdef LIBSASS_PYTHON_VERSION
357+
version = PyString_FromString(LIBSASS_PYTHON_VERSION);
358+
#else
359+
version = PyString_FromString("unknown");
360+
#endif
361+
PyModule_AddObject(module, "__version__", version);
356362
Py_INCREF(&sass_OptionsType);
357363
PyModule_AddObject(module, "Options", (PyObject *) &sass_OptionsType);
358364
Py_INCREF(&sass_BaseContextType);

sasstests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
from __future__ import with_statement
22
from attest import assert_hook
33

4+
import re
5+
46
from attest import Tests, raises
57

6-
from sass import BaseContext, Options
8+
from sass import __version__, BaseContext, Options
79

810

911
suite = Tests()
1012

1113

14+
@suite.test
15+
def version():
16+
assert re.match(r'^\d+\.\d+\.\d+$', __version__)
17+
18+
1219
@suite.test
1320
def options_output_style():
1421
for style in 'nested', 'expanded', 'compact', 'compressed':

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from distutils.core import Extension, setup
55

66

7+
version = '0.1.0'
8+
79
libsass_sources = [
810
'context.cpp', 'functions.cpp', 'document.cpp',
911
'document_parser.cpp', 'eval_apply.cpp', 'node.cpp',
@@ -21,14 +23,15 @@
2123
sass_extension = Extension(
2224
'sass',
2325
['sass.c'] + libsass_sources,
26+
define_macros=[('LIBSASS_PYTHON_VERSION', '"' + version + '"')],
2427
depends=libsass_headers,
2528
extra_compile_args=['-c', '-Wall', '-O2', '-fPIC'],
2629
extra_link_args=['-fPIC'],
2730
)
2831

2932
setup(
3033
name='libsass',
31-
version='0.1.0',
34+
version=version,
3235
ext_modules=[sass_extension],
3336
py_modules=['sasstests'],
3437
license='MIT License',

0 commit comments

Comments
 (0)