Passed
Push — master ( 363580...b7b87f )
by John
02:43
created

bbarchivist.compat   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 49
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Functions

Rating   Name   Duplication   Size   Complexity  
A enum_cpus() 0 11 2
A where_which() 0 14 2
A perf_clock() 0 11 2
1
#!/usr/bin/env python3
2 5
"""This module is used for backwards compatibility for older Python 3."""
3
4 5
__author__ = "Thurask"
5 5
__license__ = "WTFPL v2"
6 5
__copyright__ = "2015-2018 Thurask"
7
8
9 5
def perf_clock():
10
    """
11
    Backwards compatibility wrapper for system clock.
12
    """
13 5
    try:
14 5
        from time import perf_counter as clock
15 1
    except ImportError:  # 3.2
16 1
        from time import clock
17
    finally:
18 5
        wclock = clock()
19 5
    return wclock
20
21
22 5
def enum_cpus():
23
    """
24
    Backwards compatibility wrapper for CPU count.
25
    """
26 5
    try:
27 5
        from os import cpu_count
28 2
    except ImportError:  # 3.2, 3.3
29 2
        from multiprocessing import cpu_count
30
    finally:
31 5
        cpus = cpu_count()
32 5
    return cpus
33
34
35 5
def where_which(path):
36
    """
37
    Backwards compatibility wrapper for approximating which/where.
38
39
    :param path: Path to a file.
40
    :type path: str
41
    """
42 5
    try:
43 5
        from shutil import which
44 1
    except ImportError:  # 3.2
45 1
        from shutilwhich import which
46
    finally:
47 5
        thepath = which(path)
48
    return thepath
49