Passed
Push — develop ( fc562f...b9b638 )
by Dean
02:34
created

PathHelper.remove()   A

Complexity

Conditions 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 4.3145
Metric Value
cc 2
dl 0
loc 14
ccs 1
cts 6
cp 0.1666
crap 4.3145
rs 9.4285
1 1
from plugin.core.libraries.helpers.storage import StorageHelper
0 ignored issues
show
Bug introduced by
The name storage does not seem to exist in module plugin.core.libraries.helpers.
Loading history...
Configuration introduced by
Unable to import 'plugin.core.libraries.helpers.storage' (invalid syntax (<string>, line 25))

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
2
3 1
import logging
4 1
import os
5 1
import sys
6
7 1
log = logging.getLogger(__name__)
8
9
10 1
class PathHelper(object):
11 1
    @classmethod
12
    def insert(cls, base, system, architecture, *args):
13
        """Insert a new path into `sys.path` if it passes basic validation
14
15
        :type base: str
16
        :type system: str
17
        :type architecture: str
18
        """
19
20 1
        path = os.path.join(base, system, architecture, *args)
21
22 1
        if path in sys.path:
23
            return False
24
25 1
        if not os.path.exists(path):
26
            return False
27
28 1
        sys.path.insert(0, path)
29
30 1
        log.debug('Inserted path: %r', StorageHelper.to_relative_path(path))
31 1
        return True
32
33 1
    @classmethod
34
    def remove(cls, path):
35
        """Remove path from `sys.path` if it exists
36
37
        :type path: str
38
        """
39
40
        if path not in sys.path:
41
            return False
42
43
        sys.path.remove(path)
44
45
        log.debug('Removed path: %r', StorageHelper.to_relative_path(path))
46
        return True
47