Skip to content

Add the libsass version to --version #141

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
Mar 23, 2016
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
21 changes: 11 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
*.egg
*.egg-info
*.pyc
*.pyd
*.so
.*.swp
.DS_Store
._.DS_Store
.coverage
.tox
/.libsass-upstream-version
build/
dist/
docs/_build
testpkg/build/
testpkg/dist/
testpkg/testpkg/static/css/*.scss.css
._.DS_Store
.coverage
.DS_Store
.tox
.*.swp
*.egg
*.egg-info
*.so
*.pyc
*.pyd
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ recursive-include libsass *.cpp
recursive-include libsass *.h
recursive-include libsass *.hpp
include libsass/Makefile
include .libsass-upstream-version
include test/*.scss
include README.rst
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,29 @@ C_OBJECTS = $(patsubst libsass/src/%.c,build2/libsass/c/%.o,$(C_SOURCES))
CPP_SOURCES := $(wildcard libsass/src/*.cpp)
CPP_OBJECTS = $(patsubst libsass/src/%.cpp,build2/libsass/cpp/%.o,$(CPP_SOURCES))

LIBSASS_VERSION = $(shell git -C libsass describe --abbrev=4 --dirty --always --tags)

BASEFLAGS := -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -I./libsass/include $(PY_HEADERS) -Wno-parentheses -Werror=switch -DLIBSASS_VERSION='"$(LIBSASS_VERSION)"'
CFLAGS := $(BASEFLAGS) -Wstrict-prototypes
CPPFLAGS := $(BASEFLAGS) -std=c++0x
LFLAGS := -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fPIC -lstdc++

all: _sass.so

build2/libsass/c/%.o: libsass/src/%.c
@mkdir -p build2/libsass/c/
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
gcc $(CFLAGS) -c $^ -o $@

build2/libsass/cpp/%.o: libsass/src/%.cpp
@mkdir -p build2/libsass/cpp/
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
gcc $(CPPFLAGS) -c $^ -o $@

build2/pysass.o: pysass.cpp
@mkdir -p build2
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
gcc $(CPPFLAGS) -Wno-write-strings -c $^ -o $@

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

.PHONY: clean
clean:
Expand Down
1 change: 1 addition & 0 deletions pysass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ PyObject* PySass_make_enum_dict() {

void PySass_init_module(PyObject *module) {
PyModule_AddObject(module, "OUTPUT_STYLES", PySass_make_enum_dict());
PyModule_AddObject(module, "libsass_version", PyUnicode_FromString(libsass_version()));
}

#if PY_MAJOR_VERSION >= 3
Expand Down
5 changes: 4 additions & 1 deletion sassc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@
import sys
import time

import _sass
from sass import __version__ as VERSION, OUTPUT_STYLES, CompileError, compile


def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
parser = optparse.OptionParser(
usage='%prog [options] SCSS_FILE [OUT_CSS_FILE]',
version='%prog ' + VERSION
version='%prog {0} (sass/libsass {1})'.format(
VERSION, _sass.libsass_version,
),
)
output_styles = list(OUTPUT_STYLES)
output_styles = ', '.join(output_styles[:-1]) + ', or ' + output_styles[-1]
Expand Down
42 changes: 32 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,51 @@
import distutils.cmd
import distutils.log
import distutils.sysconfig
import os
import os.path
import platform
import shutil
import subprocess
import sys
import tempfile

from setuptools import Extension, setup

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

if not os.path.isfile(os.path.join('libsass', 'Makefile')) and \
os.path.isdir('.git'):
if (
not os.path.isfile(os.path.join('libsass', 'Makefile')) and
os.path.isdir('.git')
):
print(file=sys.stderr)
print('You seem to miss initializing submodules; '
'try the following command', file=sys.stderr)
print('Missing the libsass sumbodule. Try:', file=sys.stderr)
print(' git submodule update --init', file=sys.stderr)
print(file=sys.stderr)
exit(1)


# Determine the libsass version from the git checkout
if os.path.exists(os.path.join('libsass', '.git')):
proc = subprocess.Popen(
(
'git', '-C', 'libsass', 'describe',
'--abbrev=4', '--dirty', '--always', '--tags',
),
stdout=subprocess.PIPE,
)
out, _ = proc.communicate()
assert not proc.returncode, proc.returncode
with open('.libsass-upstream-version', 'wb') as libsass_version_file:
libsass_version_file.write(out)

# The version file should always exist at this point
with open('.libsass-upstream-version', 'rb') as libsass_version_file:
libsass_version = libsass_version_file.read().decode('UTF-8').strip()
if sys.platform == 'win32':
# This looks wrong, but is required for some reason :(
version_define = r'/DLIBSASS_VERSION="\"{0}\""'.format(libsass_version)
else:
version_define = '-DLIBSASS_VERSION="{0}"'.format(libsass_version)

sources = ['pysass.cpp']
headers = []
for directory in (
Expand Down Expand Up @@ -89,9 +114,7 @@ def customize_compiler(compiler):
compiler.linker_so[0] = os.environ['CXX']
return compiler
distutils.sysconfig.customize_compiler = customize_compiler
flags.extend([
'-stdlib=libc++',
])
flags.append('-stdlib=libc++')
if platform.system() == 'Darwin':
flags.append('-mmacosx-version-min=10.7',)
if tuple(map(int, platform.mac_ver()[0].split('.'))) >= (10, 9):
Expand Down Expand Up @@ -134,10 +157,9 @@ def restore_cencode():
sass_extension = Extension(
'_sass',
sources,
library_dirs=[os.path.join('.', 'libsass', 'src')],
include_dirs=[os.path.join('.', 'libsass', 'include')],
depends=headers,
extra_compile_args=flags,
extra_compile_args=flags + [version_define],
extra_link_args=link_flags,
)

Expand Down