GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#22)
by
unknown
01:09
created

qtsass.api.compile_and_save()   A

Complexity

Conditions 3

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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__)
0 ignored issues
show
Coding Style Naming introduced by
The name _log does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

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.

Loading history...
27
28
29
def compile(input_file):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in compile.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
30
    _log.debug('Compiling {}...'.format(input_file))
0 ignored issues
show
introduced by
Use formatting in logging functions and pass the parameters as arguments
Loading history...
31
32
    with open(input_file, 'r') as f:
0 ignored issues
show
Coding Style Naming introduced by
The name f does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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.

Loading history...
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:
0 ignored issues
show
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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.

Loading history...
49
        _log.error('Failed to compile {}:\n{}'.format(input_file, e))
0 ignored issues
show
introduced by
Use formatting in logging functions and pass the parameters as arguments
Loading history...
50
    return ""
51
52
53
def compile_and_save(input_file, dest_file):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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))
0 ignored issues
show
introduced by
Use formatting in logging functions and pass the parameters as arguments
Loading history...
59
    else:
60
        print(stylesheet)
61