|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# ----------------------------------------------------------------------------- |
|
3
|
|
|
# Copyright (c) 2015 Yann Lanthony |
|
4
|
|
|
# Copyright (c) 2017-2018 Spyder Project Contributors |
|
5
|
|
|
# |
|
6
|
|
|
# Licensed under the terms of the MIT License |
|
7
|
|
|
# (See LICENSE.txt for details) |
|
8
|
|
|
# ----------------------------------------------------------------------------- |
|
9
|
|
|
"""qtsass - Compile SCSS files to valid Qt stylesheets.""" |
|
10
|
|
|
|
|
11
|
|
|
# Standard library imports |
|
12
|
|
|
from __future__ import absolute_import, print_function |
|
13
|
|
|
import logging |
|
14
|
|
|
import os |
|
15
|
|
|
|
|
16
|
|
|
# Third party imports |
|
17
|
|
|
import sass |
|
18
|
|
|
|
|
19
|
|
|
# Local imports |
|
20
|
|
|
from qtsass.conformers import scss_conform, qt_conform |
|
21
|
|
|
from qtsass.functions import qlineargradient, rgba |
|
22
|
|
|
from qtsass.importers import qss_importer |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
logging.basicConfig(level=logging.DEBUG) |
|
26
|
|
|
_log = logging.getLogger(__name__) |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
def compile(input_file): |
|
|
|
|
|
|
30
|
|
|
_log.debug('Compiling {}...'.format(input_file)) |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
with open(input_file, 'r') as f: |
|
|
|
|
|
|
33
|
|
|
input_str = f.read() |
|
34
|
|
|
|
|
35
|
|
|
try: |
|
36
|
|
|
importer_root = os.path.dirname(os.path.abspath(input_file)) |
|
37
|
|
|
return qt_conform( |
|
38
|
|
|
sass.compile( |
|
39
|
|
|
string=scss_conform(input_str), |
|
40
|
|
|
source_comments=False, |
|
41
|
|
|
custom_functions={ |
|
42
|
|
|
'qlineargradient': qlineargradient, |
|
43
|
|
|
'rgba': rgba |
|
44
|
|
|
}, |
|
45
|
|
|
importers=[(0, qss_importer(importer_root))] |
|
46
|
|
|
) |
|
47
|
|
|
) |
|
48
|
|
|
except sass.CompileError as e: |
|
|
|
|
|
|
49
|
|
|
_log.error('Failed to compile {}:\n{}'.format(input_file, e)) |
|
|
|
|
|
|
50
|
|
|
return "" |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
def compile_and_save(input_file, dest_file): |
|
|
|
|
|
|
54
|
|
|
stylesheet = compile(input_file) |
|
55
|
|
|
if dest_file: |
|
56
|
|
|
with open(dest_file, 'w') as css_file: |
|
57
|
|
|
css_file.write(stylesheet) |
|
58
|
|
|
_log.info('Created CSS file {}'.format(dest_file)) |
|
|
|
|
|
|
59
|
|
|
else: |
|
60
|
|
|
print(stylesheet) |
|
61
|
|
|
|
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.