Skip to content

Commit f88ba3c

Browse files
authored
Merge pull request #307 from sass/abi3
Build abi3 wheels on macos / linux
2 parents bdbc8fc + 6cb1484 commit f88ba3c

File tree

4 files changed

+66
-87
lines changed

4 files changed

+66
-87
lines changed

Makefile

Lines changed: 0 additions & 43 deletions
This file was deleted.

pysass.cpp renamed to _sass.c

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
#define COLLECTIONS_ABC_MOD "collections"
1212
#endif
1313

14-
#ifdef __cplusplus
15-
extern "C" {
16-
#endif
17-
1814
static PyObject* _to_py_value(const union Sass_Value* value);
1915
static union Sass_Value* _to_sass_value(PyObject* value);
2016

@@ -156,7 +152,7 @@ static union Sass_Value* _list_to_sass_value(PyObject* value) {
156152
PyObject* items = PyObject_GetAttrString(value, "items");
157153
PyObject* separator = PyObject_GetAttrString(value, "separator");
158154
PyObject* bracketed = PyObject_GetAttrString(value, "bracketed");
159-
Sass_Separator sep = SASS_COMMA;
155+
enum Sass_Separator sep = SASS_COMMA;
160156
if (separator == sass_comma) {
161157
sep = SASS_COMMA;
162158
} else if (separator == sass_space) {
@@ -168,7 +164,7 @@ static union Sass_Value* _list_to_sass_value(PyObject* value) {
168164
retv = sass_make_list(PyTuple_Size(items), sep, is_bracketed);
169165
for (i = 0; i < PyTuple_Size(items); i += 1) {
170166
sass_list_set_value(
171-
retv, i, _to_sass_value(PyTuple_GET_ITEM(items, i))
167+
retv, i, _to_sass_value(PyTuple_GetItem(items, i))
172168
);
173169
}
174170
Py_DECREF(types_mod);
@@ -204,7 +200,7 @@ static union Sass_Value* _number_to_sass_value(PyObject* value) {
204200
PyObject* unit = PyObject_GetAttrString(value, "unit");
205201
PyObject* bytes = PyUnicode_AsEncodedString(unit, "UTF-8", "strict");
206202
retv = sass_make_number(
207-
PyFloat_AsDouble(d_value), PyBytes_AS_STRING(bytes)
203+
PyFloat_AsDouble(d_value), PyBytes_AsString(bytes)
208204
);
209205
Py_DECREF(d_value);
210206
Py_DECREF(unit);
@@ -215,7 +211,7 @@ static union Sass_Value* _number_to_sass_value(PyObject* value) {
215211
static union Sass_Value* _unicode_to_sass_value(PyObject* value) {
216212
union Sass_Value* retv = NULL;
217213
PyObject* bytes = PyUnicode_AsEncodedString(value, "UTF-8", "strict");
218-
retv = sass_make_string(PyBytes_AS_STRING(bytes));
214+
retv = sass_make_string(PyBytes_AsString(bytes));
219215
Py_DECREF(bytes);
220216
return retv;
221217
}
@@ -224,7 +220,7 @@ static union Sass_Value* _warning_to_sass_value(PyObject* value) {
224220
union Sass_Value* retv = NULL;
225221
PyObject* msg = PyObject_GetAttrString(value, "msg");
226222
PyObject* bytes = PyUnicode_AsEncodedString(msg, "UTF-8", "strict");
227-
retv = sass_make_warning(PyBytes_AS_STRING(bytes));
223+
retv = sass_make_warning(PyBytes_AsString(bytes));
228224
Py_DECREF(msg);
229225
Py_DECREF(bytes);
230226
return retv;
@@ -234,7 +230,7 @@ static union Sass_Value* _error_to_sass_value(PyObject* value) {
234230
union Sass_Value* retv = NULL;
235231
PyObject* msg = PyObject_GetAttrString(value, "msg");
236232
PyObject* bytes = PyUnicode_AsEncodedString(msg, "UTF-8", "strict");
237-
retv = sass_make_error(PyBytes_AS_STRING(bytes));
233+
retv = sass_make_error(PyBytes_AsString(bytes));
238234
Py_DECREF(msg);
239235
Py_DECREF(bytes);
240236
return retv;
@@ -263,7 +259,7 @@ static union Sass_Value* _unknown_type_to_sass_error(PyObject* value) {
263259
format_meth, type_name, NULL
264260
);
265261
PyObject* bytes = PyUnicode_AsEncodedString(result, "UTF-8", "strict");
266-
retv = sass_make_error(PyBytes_AS_STRING(bytes));
262+
retv = sass_make_error(PyBytes_AsString(bytes));
267263
Py_DECREF(type);
268264
Py_DECREF(type_name);
269265
Py_DECREF(fmt);
@@ -302,7 +298,7 @@ static PyObject* _exception_to_bytes() {
302298

303299
static union Sass_Value* _exception_to_sass_error() {
304300
PyObject* bytes = _exception_to_bytes();
305-
union Sass_Value* retv = sass_make_error(PyBytes_AS_STRING(bytes));
301+
union Sass_Value* retv = sass_make_error(PyBytes_AsString(bytes));
306302
Py_DECREF(bytes);
307303
return retv;
308304
}
@@ -311,7 +307,7 @@ static Sass_Import_List _exception_to_sass_import_error(const char* path) {
311307
PyObject* bytes = _exception_to_bytes();
312308
Sass_Import_List import_list = sass_make_import_list(1);
313309
import_list[0] = sass_make_import_entry(path, 0, 0);
314-
sass_import_set_error(import_list[0], PyBytes_AS_STRING(bytes), 0, 0);
310+
sass_import_set_error(import_list[0], PyBytes_AsString(bytes), 0, 0);
315311
Py_DECREF(bytes);
316312
return import_list;
317313
}
@@ -334,7 +330,7 @@ static union Sass_Value* _to_sass_value(PyObject* value) {
334330
} else if (PyUnicode_Check(value)) {
335331
retv = _unicode_to_sass_value(value);
336332
} else if (PyBytes_Check(value)) {
337-
retv = sass_make_string(PyBytes_AS_STRING(value));
333+
retv = sass_make_string(PyBytes_AsString(value));
338334
/* XXX: PyMapping_Check returns true for lists and tuples in python3 :( */
339335
/* XXX: pypy derps on dicts: https://bitbucket.org/pypy/pypy/issue/1970 */
340336
} else if (PyDict_Check(value) || PyObject_IsInstance(value, mapping_t)) {
@@ -404,11 +400,11 @@ static void _add_custom_functions(
404400
Sass_Function_List fn_list = sass_make_function_list(
405401
PyList_Size(custom_functions)
406402
);
407-
for (i = 0; i < PyList_GET_SIZE(custom_functions); i += 1) {
408-
PyObject* sass_function = PyList_GET_ITEM(custom_functions, i);
403+
for (i = 0; i < PyList_Size(custom_functions); i += 1) {
404+
PyObject* sass_function = PyList_GetItem(custom_functions, i);
409405
PyObject* signature = PySass_Object_Bytes(sass_function);
410406
Sass_Function_Entry fn = sass_make_function(
411-
PyBytes_AS_STRING(signature),
407+
PyBytes_AsString(signature),
412408
_call_py_f,
413409
sass_function
414410
);
@@ -443,13 +439,13 @@ static Sass_Import_List _call_py_importer_f(
443439

444440
/* Otherwise, we know our importer is well formed (because we wrap it)
445441
* The return value will be a tuple of 1, 2, or 3 tuples */
446-
sass_imports = sass_make_import_list(PyTuple_GET_SIZE(py_result));
447-
for (i = 0; i < PyTuple_GET_SIZE(py_result); i += 1) {
442+
sass_imports = sass_make_import_list(PyTuple_Size(py_result));
443+
for (i = 0; i < PyTuple_Size(py_result); i += 1) {
448444
char* path_str = NULL; /* XXX: Memory leak? */
449445
char* source_str = NULL;
450446
char* sourcemap_str = NULL;
451-
PyObject* tup = PyTuple_GET_ITEM(py_result, i);
452-
Py_ssize_t size = PyTuple_GET_SIZE(tup);
447+
PyObject* tup = PyTuple_GetItem(py_result, i);
448+
Py_ssize_t size = PyTuple_Size(tup);
453449

454450
if (size == 1) {
455451
PyArg_ParseTuple(tup, PySass_IF_PY3("y", "s"), &path_str);
@@ -495,10 +491,10 @@ static void _add_custom_importers(
495491
return;
496492
}
497493

498-
importer_list = sass_make_importer_list(PyTuple_GET_SIZE(custom_importers));
494+
importer_list = sass_make_importer_list(PyTuple_Size(custom_importers));
499495

500-
for (i = 0; i < PyTuple_GET_SIZE(custom_importers); i += 1) {
501-
PyObject* item = PyTuple_GET_ITEM(custom_importers, i);
496+
for (i = 0; i < PyTuple_Size(custom_importers); i += 1) {
497+
PyObject* item = PyTuple_GetItem(custom_importers, i);
502498
int priority = 0;
503499
PyObject* import_function = NULL;
504500

@@ -517,11 +513,11 @@ PySass_compile_string(PyObject *self, PyObject *args) {
517513
struct Sass_Context *ctx;
518514
struct Sass_Data_Context *context;
519515
struct Sass_Options *options;
520-
char *string, *include_paths, *source_map_file;
516+
char *string, *include_paths;
521517
const char *error_message, *output_string;
522-
Sass_Output_Style output_style;
518+
enum Sass_Output_Style output_style;
523519
int source_comments, error_status, precision, indented,
524-
source_map_embed, source_map_contents, source_map_file_urls,
520+
source_map_embed, source_map_contents,
525521
omit_source_map_url;
526522
PyObject *custom_functions;
527523
PyObject *custom_importers;
@@ -549,9 +545,9 @@ PySass_compile_string(PyObject *self, PyObject *args) {
549545
sass_option_set_source_map_embed(options, source_map_embed);
550546
sass_option_set_omit_source_map_url(options, omit_source_map_url);
551547

552-
if (PyBytes_Check(source_map_root) && PyBytes_GET_SIZE(source_map_root)) {
548+
if (PyBytes_Check(source_map_root) && PyBytes_Size(source_map_root)) {
553549
sass_option_set_source_map_root(
554-
options, PyBytes_AS_STRING(source_map_root)
550+
options, PyBytes_AsString(source_map_root)
555551
);
556552
}
557553

@@ -579,9 +575,9 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
579575
struct Sass_Options *options;
580576
char *filename, *include_paths;
581577
const char *error_message, *output_string, *source_map_string;
582-
Sass_Output_Style output_style;
578+
enum Sass_Output_Style output_style;
583579
int source_comments, error_status, precision, source_map_embed,
584-
source_map_contents, source_map_file_urls, omit_source_map_url;
580+
source_map_contents, omit_source_map_url;
585581
PyObject *source_map_filename, *custom_functions, *custom_importers,
586582
*result, *output_filename_hint, *source_map_root;
587583

@@ -600,23 +596,23 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
600596
options = sass_file_context_get_options(context);
601597

602598
if (PyBytes_Check(source_map_filename)) {
603-
if (PyBytes_GET_SIZE(source_map_filename)) {
599+
if (PyBytes_Size(source_map_filename)) {
604600
sass_option_set_source_map_file(
605-
options, PyBytes_AS_STRING(source_map_filename)
601+
options, PyBytes_AsString(source_map_filename)
606602
);
607603
}
608604
}
609605
if (PyBytes_Check(output_filename_hint)) {
610-
if (PyBytes_GET_SIZE(output_filename_hint)) {
606+
if (PyBytes_Size(output_filename_hint)) {
611607
sass_option_set_output_path(
612-
options, PyBytes_AS_STRING(output_filename_hint)
608+
options, PyBytes_AsString(output_filename_hint)
613609
);
614610
}
615611
}
616612

617-
if (PyBytes_Check(source_map_root) && PyBytes_GET_SIZE(source_map_root)) {
613+
if (PyBytes_Check(source_map_root) && PyBytes_Size(source_map_root)) {
618614
sass_option_set_source_map_root(
619-
options, PyBytes_AS_STRING(source_map_root)
615+
options, PyBytes_AsString(source_map_root)
620616
);
621617
}
622618

@@ -703,7 +699,3 @@ init_sass()
703699
}
704700

705701
#endif
706-
707-
#ifdef __cplusplus
708-
}
709-
#endif

requirements-dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
-e .
21
coverage
32
coverage-enable-subprocess
43
pre-commit

setup.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
LFLAGS_POSIX = ['-fPIC', '-lstdc++']
2323
LFLAGS_CLANG = ['-fPIC', '-stdlib=libc++']
2424

25-
sources = ['pysass.cpp']
25+
sources = ['_sass.c']
2626
headers = []
2727

2828
if sys.platform == 'win32':
@@ -148,6 +148,15 @@ def restore_cencode():
148148
include_dirs = [os.path.join('.', 'libsass', 'include')]
149149
extra_compile_args.append(define)
150150

151+
# Py_LIMITED_API does not work for pypy
152+
# https://foss.heptapod.net/pypy/pypy/issues/3173
153+
if not hasattr(sys, 'pypy_version_info'):
154+
py_limited_api = True
155+
define_macros = [('Py_LIMITED_API', None)]
156+
else:
157+
py_limited_api = False
158+
define_macros = []
159+
151160
sass_extension = Extension(
152161
'_sass',
153162
sorted(sources),
@@ -156,6 +165,8 @@ def restore_cencode():
156165
extra_compile_args=extra_compile_args,
157166
extra_link_args=extra_link_args,
158167
libraries=libraries,
168+
py_limited_api=py_limited_api,
169+
define_macros=define_macros,
159170
)
160171

161172

@@ -210,6 +221,26 @@ def run(self):
210221
shutil.rmtree(path)
211222

212223

224+
cmdclass = {'upload_doc': upload_doc}
225+
226+
if (
227+
sys.platform != 'win32' and
228+
sys.version_info >= (3,) and
229+
platform.python_implementation() == 'CPython'
230+
):
231+
try:
232+
import wheel.bdist_wheel
233+
except ImportError:
234+
pass
235+
else:
236+
class bdist_wheel(wheel.bdist_wheel.bdist_wheel):
237+
def finalize_options(self):
238+
self.py_limited_api = 'cp3{}'.format(sys.version_info[1])
239+
super().finalize_options()
240+
241+
cmdclass['bdist_wheel'] = bdist_wheel
242+
243+
213244
setup(
214245
name='libsass',
215246
description='Sass for Python: '
@@ -265,5 +296,5 @@ def run(self):
265296
'Topic :: Software Development :: Code Generators',
266297
'Topic :: Software Development :: Compilers',
267298
],
268-
cmdclass={'upload_doc': upload_doc},
299+
cmdclass=cmdclass,
269300
)

0 commit comments

Comments
 (0)