setup.load_version()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
import os
2
3
from setuptools import setup
4
5
6
def load_version(version_file_path):
7
    import re
8
    file_contents = open(version_file_path, "rt").read()
9
    version_regex = r"^__version__ = ['\"]([^'\"]*)['\"]"
10
    match = re.search(version_regex, file_contents, re.M)
11
    if match:
12
        return match.group(1)
13
    else:
14
        raise RuntimeError(f"Unable to find version string in {version_file_path}")
15
16
17
if os.getenv('LAGOM_SKIP_COMPILE') and os.getenv('LAGOM_COMPILE'):
18
    raise Exception("Both LAGOM_SKIP_COMPILE and LAGOM_COMPILE ")
19
elif os.getenv('LAGOM_COMPILE'):
20
    LAGOM_COMPILE = bool(int(os.environ['LAGOM_COMPILE']))
21
elif os.getenv('LAGOM_SKIP_COMPILE'):
22
    LAGOM_COMPILE = not bool(int(bool(int(os.environ['LAGOM_SKIP_COMPILE']))))
23
else:
24
    LAGOM_COMPILE = False
25
26
if LAGOM_COMPILE:
27
    from mypyc.build import mypycify
28
    setup(
29
        version=load_version("lagom/version.py"),
30
        ext_modules=mypycify([
31
            'lagom/container.py',
32
            'lagom/context_based.py',
33
            'lagom/definitions.py',
34
            'lagom/experimental/definitions.py',
35
            'lagom/updaters.py',
36
        ])
37
    )
38
else:
39
    setup(
40
        version=load_version("lagom/version.py")
41
    )
42
43