Completed
Push — master ( e3cf28...819929 )
by John
02:52
created

where_which()   A

Complexity

Conditions 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
dl 0
loc 14
ccs 5
cts 7
cp 0.7143
crap 2.0932
rs 9.4285
1
#!/usr/bin/env python3
2 4
"""This module is used for backwards compatibility for older Python 3."""
3
4 4
__author__ = "Thurask"
5 4
__license__ = "WTFPL v2"
6 4
__copyright__ = "Copyright 2015-2016 Thurask"
7
8
9 4
def enum_cpus():
10
    """
11
    Backwards compatibility wrapper for CPU count.
12
    """
13 4
    try:
14 4
        from os import cpu_count
15 1
    except ImportError:
16 1
        from multiprocessing import cpu_count
17
    finally:
18 4
        cpus = cpu_count()
19 4
    return cpus
20
21
22 4
def where_which(path):
23
    """
24
    Backwards compatibility wrapper for approximating which/where.
25
26
    :param path: Path to a file.
27
    :type path: str
28
    """
29 4
    try:
30 4
        from shutil import which
31
    except ImportError:
32
        from shutilwhich import which
33
    finally:
34 4
        thepath = which(path)
35
    return thepath
36