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 (#44)
by
unknown
01:11
created

qtsass.watchers.api   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 49
dl 0
loc 118
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A Watcher.stop() 0 3 1
A Watcher.__init__() 0 9 1
A Watcher.setup() 0 7 1
A Watcher.compile_and_dispatch() 0 11 2
A Watcher.compile() 0 9 1
A Watcher.on_change() 0 11 1
A Watcher.disconnect() 0 4 1
A Watcher.join() 0 3 1
A Watcher.dispatch() 0 5 2
A Watcher.connect() 0 8 1
A Watcher.start() 0 3 1
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
"""The filesystem watcher api."""
10
11
# yapf: disable
12
13
from __future__ import absolute_import
14
import logging
15
16
17
# yapf: enable
18
19
_log = logging.getLogger(__name__)
20
21
22
class Watcher(object):
23
    """Watcher base class.
24
25
    Watchers monitor a file or directory and call the on_change method when a
26
    change occurs. The on_change method should trigger the compiler function
27
    passed in during construction and dispatch the result to all connected
28
    callbacks.
29
30
    Watcher implementations must inherit from this base class. Subclasses
31
    should perform any setup required in the setup method, rather than
32
    overriding __init__.
33
    """
34
35
    def __init__(self, watch_dir, compiler, args=None, kwargs=None):
36
        """Store initialization values and call Watcher.setup."""
37
        self._watch_dir = watch_dir
38
        self._compiler = compiler
39
        self._args = args or ()
40
        self._kwargs = kwargs or {}
41
        self._callbacks = set()
42
        self._log = _log
43
        self.setup()
44
45
    def setup(self):
46
        """Perform any setup required here.
47
48
        Rather than implement __init__, subclasses can perform any setup in
49
        this method.
50
        """
51
        return NotImplemented
52
53
    def start(self):
54
        """Start this Watcher."""
55
        return NotImplemented
56
57
    def stop(self):
58
        """Stop this Watcher."""
59
        return NotImplemented
60
61
    def join(self):
62
        """Wait for this Watcher to finish."""
63
        return NotImplemented
64
65
    def compile(self):
66
        """Call the Watcher's compiler."""
67
        self._log.debug(
68
            'Compiling sass...%s(*%s, **%s)',
69
            self._compiler,
70
            self._args,
71
            self._kwargs,
72
        )
73
        return self._compiler(*self._args, **self._kwargs)
74
75
    def compile_and_dispatch(self):
76
        """Compile and dispatch the resulting css to connected callbacks."""
77
        self._log.debug('Compiling and dispatching....')
78
79
        try:
80
            css = self.compile()
81
        except Exception:
82
            self._log.exception('Failed to compile...')
83
            return
84
85
        self.dispatch(css)
86
87
    def dispatch(self, css):
88
        """Dispatch css to connected callbacks."""
89
        self._log.debug('Dispatching callbacks...')
90
        for callback in self._callbacks:
91
            callback(css)
92
93
    def on_change(self):
94
        """Call when a change is detected.
95
96
        Subclasses must call this method when they detect a change. Subclasses
97
        may also override this method in order to manually compile and dispatch
98
        callbacks. For example, a Qt implementation may use signals and slots
99
        to ensure that compiling and executing callbacks happens in the main
100
        GUI thread.
101
        """
102
        self._log.debug('Change detected...')
103
        self.compile_and_dispatch()
104
105
    def connect(self, fn):
106
        """Connect a callback to this Watcher.
107
108
        All callbacks are called when a change is detected. Callbacks are
109
        passed the compiled css.
110
        """
111
        self._log.debug('Connecting callback: %s', fn)
112
        self._callbacks.add(fn)
113
114
    def disconnect(self, fn):
115
        """Disconnect a callback from this Watcher."""
116
        self._log.debug('Disconnecting callback: %s', fn)
117
        self._callbacks.discard(fn)
118