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:10
created

qtsass.watchers.api   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Importance

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