Skip to content

Commit 8ceeac8

Browse files
committed
Merge pull request #141 from asottile/add_libsass_version
Add the libsass version to --version
2 parents 0f04ecd + c4e4d9a commit 8ceeac8

File tree

6 files changed

+60
-25
lines changed

6 files changed

+60
-25
lines changed

.gitignore

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
*.egg
2+
*.egg-info
3+
*.pyc
4+
*.pyd
5+
*.so
6+
.*.swp
7+
.DS_Store
8+
._.DS_Store
9+
.coverage
10+
.tox
11+
/.libsass-upstream-version
112
build/
213
dist/
314
docs/_build
415
testpkg/build/
516
testpkg/dist/
617
testpkg/testpkg/static/css/*.scss.css
7-
._.DS_Store
8-
.coverage
9-
.DS_Store
10-
.tox
11-
.*.swp
12-
*.egg
13-
*.egg-info
14-
*.so
15-
*.pyc
16-
*.pyd

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ recursive-include libsass *.cpp
33
recursive-include libsass *.h
44
recursive-include libsass *.hpp
55
include libsass/Makefile
6+
include .libsass-upstream-version
67
include test/*.scss
78
include README.rst

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,29 @@ C_OBJECTS = $(patsubst libsass/src/%.c,build2/libsass/c/%.o,$(C_SOURCES))
1414
CPP_SOURCES := $(wildcard libsass/src/*.cpp)
1515
CPP_OBJECTS = $(patsubst libsass/src/%.cpp,build2/libsass/cpp/%.o,$(CPP_SOURCES))
1616

17+
LIBSASS_VERSION = $(shell git -C libsass describe --abbrev=4 --dirty --always --tags)
18+
19+
BASEFLAGS := -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -I./libsass/include $(PY_HEADERS) -Wno-parentheses -Werror=switch -DLIBSASS_VERSION='"$(LIBSASS_VERSION)"'
20+
CFLAGS := $(BASEFLAGS) -Wstrict-prototypes
21+
CPPFLAGS := $(BASEFLAGS) -std=c++0x
22+
LFLAGS := -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fPIC -lstdc++
23+
1724
all: _sass.so
1825

1926
build2/libsass/c/%.o: libsass/src/%.c
2027
@mkdir -p build2/libsass/c/
21-
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I./libsass/include $(PY_HEADERS) -c $^ -o $@ -c -O2 -fPIC -std=c++0x -Wall -Wno-parentheses -Werror=switch
28+
gcc $(CFLAGS) -c $^ -o $@
2229

2330
build2/libsass/cpp/%.o: libsass/src/%.cpp
2431
@mkdir -p build2/libsass/cpp/
25-
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I./libsass/include $(PY_HEADERS) -c $^ -o $@ -c -O2 -fPIC -std=c++0x -Wall -Wno-parentheses -Werror=switch
32+
gcc $(CPPFLAGS) -c $^ -o $@
2633

2734
build2/pysass.o: pysass.cpp
2835
@mkdir -p build2
29-
gcc -pthread -fno-strict-aliasing -Wno-write-strings -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -I./libsass/include $(PY_HEADERS) -c $^ -o $@ -c -O2 -fPIC -std=c++0x -Wall -Wno-parentheses -Werror=switch
36+
gcc $(CPPFLAGS) -Wno-write-strings -c $^ -o $@
3037

3138
_sass.so: $(C_OBJECTS) $(CPP_OBJECTS) build2/pysass.o
32-
g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro $^ -L./libsass -o $@ -fPIC -lstdc++
39+
g++ $(LFLAGS) $^ -o $@
3340

3441
.PHONY: clean
3542
clean:

pysass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ PyObject* PySass_make_enum_dict() {
634634

635635
void PySass_init_module(PyObject *module) {
636636
PyModule_AddObject(module, "OUTPUT_STYLES", PySass_make_enum_dict());
637+
PyModule_AddObject(module, "libsass_version", PyUnicode_FromString(libsass_version()));
637638
}
638639

639640
#if PY_MAJOR_VERSION >= 3

sassc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,16 @@
7474
import sys
7575
import time
7676

77+
import _sass
7778
from sass import __version__ as VERSION, OUTPUT_STYLES, CompileError, compile
7879

7980

8081
def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
8182
parser = optparse.OptionParser(
8283
usage='%prog [options] SCSS_FILE [OUT_CSS_FILE]',
83-
version='%prog ' + VERSION
84+
version='%prog {0} (sass/libsass {1})'.format(
85+
VERSION, _sass.libsass_version,
86+
),
8487
)
8588
output_styles = list(OUTPUT_STYLES)
8689
output_styles = ', '.join(output_styles[:-1]) + ', or ' + output_styles[-1]

setup.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,51 @@
55
import distutils.cmd
66
import distutils.log
77
import distutils.sysconfig
8-
import os
98
import os.path
109
import platform
1110
import shutil
11+
import subprocess
1212
import sys
1313
import tempfile
1414

1515
from setuptools import Extension, setup
1616

1717
LIBSASS_SOURCE_DIR = os.path.join('libsass', 'src')
1818

19-
if not os.path.isfile(os.path.join('libsass', 'Makefile')) and \
20-
os.path.isdir('.git'):
19+
if (
20+
not os.path.isfile(os.path.join('libsass', 'Makefile')) and
21+
os.path.isdir('.git')
22+
):
2123
print(file=sys.stderr)
22-
print('You seem to miss initializing submodules; '
23-
'try the following command', file=sys.stderr)
24+
print('Missing the libsass sumbodule. Try:', file=sys.stderr)
2425
print(' git submodule update --init', file=sys.stderr)
2526
print(file=sys.stderr)
2627
exit(1)
2728

29+
30+
# Determine the libsass version from the git checkout
31+
if os.path.exists(os.path.join('libsass', '.git')):
32+
proc = subprocess.Popen(
33+
(
34+
'git', '-C', 'libsass', 'describe',
35+
'--abbrev=4', '--dirty', '--always', '--tags',
36+
),
37+
stdout=subprocess.PIPE,
38+
)
39+
out, _ = proc.communicate()
40+
assert not proc.returncode, proc.returncode
41+
with open('.libsass-upstream-version', 'wb') as libsass_version_file:
42+
libsass_version_file.write(out)
43+
44+
# The version file should always exist at this point
45+
with open('.libsass-upstream-version', 'rb') as libsass_version_file:
46+
libsass_version = libsass_version_file.read().decode('UTF-8').strip()
47+
if sys.platform == 'win32':
48+
# This looks wrong, but is required for some reason :(
49+
version_define = r'/DLIBSASS_VERSION="\"{0}\""'.format(libsass_version)
50+
else:
51+
version_define = '-DLIBSASS_VERSION="{0}"'.format(libsass_version)
52+
2853
sources = ['pysass.cpp']
2954
headers = []
3055
for directory in (
@@ -89,9 +114,7 @@ def customize_compiler(compiler):
89114
compiler.linker_so[0] = os.environ['CXX']
90115
return compiler
91116
distutils.sysconfig.customize_compiler = customize_compiler
92-
flags.extend([
93-
'-stdlib=libc++',
94-
])
117+
flags.append('-stdlib=libc++')
95118
if platform.system() == 'Darwin':
96119
flags.append('-mmacosx-version-min=10.7',)
97120
if tuple(map(int, platform.mac_ver()[0].split('.'))) >= (10, 9):
@@ -134,10 +157,9 @@ def restore_cencode():
134157
sass_extension = Extension(
135158
'_sass',
136159
sources,
137-
library_dirs=[os.path.join('.', 'libsass', 'src')],
138160
include_dirs=[os.path.join('.', 'libsass', 'include')],
139161
depends=headers,
140-
extra_compile_args=flags,
162+
extra_compile_args=flags + [version_define],
141163
extra_link_args=link_flags,
142164
)
143165

0 commit comments

Comments
 (0)