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.
Completed
Push — master ( 2edce9...7e9855 )
by Gonzalo
12s
created

qtsass.events   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A SourceModificationEventHandler.on_created() 0 3 2
A SourceModificationEventHandler._recompile() 0 10 4
A SourceModificationEventHandler.__init__() 0 7 1
A SourceModificationEventHandler.on_modified() 0 11 2
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
"""Source files event handler."""
10
11
# Standard library imports
12
import os
13
import time
14
15
# Third party imports
16
from watchdog.events import FileSystemEventHandler
17
18
19
# py2 has no FileNotFoundError
20
try:
21
    FileNotFoundError
22
except NameError:
23
    FileNotFoundError = IOError
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in FileNotFoundError.

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

Loading history...
24
25
26
class SourceModificationEventHandler(FileSystemEventHandler):
0 ignored issues
show
Coding Style introduced by
This class 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...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
27
28
    def __init__(self, input_file, dest_file, watched_dir, compiler):
29
        super(SourceModificationEventHandler, self).__init__()
30
        self._input_file = input_file
31
        self._dest_file = dest_file
32
        self._compiler = compiler
33
        self._watched_dir = watched_dir
34
        self._watched_extension = os.path.splitext(self._input_file)[1]
35
36
    def _recompile(self):
37
        i = 0
38
        success = False
39
        while i < 10 and not success:
40
            try:
41
                time.sleep(0.2)
42
                self._compiler(self._input_file, self._dest_file)
43
                success = True
44
            except FileNotFoundError:
45
                i += 1
46
47
    def on_modified(self, event):
48
        # On Mac, event will always be a directory.
49
        # On Windows, only recompile if event's file
50
        # has the same extension as the input file
51
        we_should_recompile = (
0 ignored issues
show
Unused Code introduced by
Consider using ternary (os.path.samefile(event.src_path, self._watched_dir) if event.is_directory else os.path.splitext(event.src_path)[1] == self._watched_extension)
Loading history...
52
            event.is_directory and
53
            os.path.samefile(event.src_path, self._watched_dir) or
54
            os.path.splitext(event.src_path)[1] == self._watched_extension
55
        )
56
        if we_should_recompile:
57
            self._recompile()
58
59
    def on_created(self, event):
60
        if os.path.splitext(event.src_path)[1] == self._watched_extension:
61
            self._recompile()
62