Passed
Push — master ( fb555e...c66640 )
by Ramon
01:23 queued 11s
created

build.get_version()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nop 0
1
import os
2
import re
3
import sys
4
5
6
def get_version():
7
    with open('setup.py', 'r') as f:
8
        setup_content = ' '.join(f.readlines())
9
        res = re.search("version='(.*?)'", setup_content)
10
        return res.group(1)
11
12
13
def get_exclusions():
14
    with open('.gitignore', 'r') as f:
15
        static_exclusions = [
16
            '.codecov.yml',
17
            '.coveragerc',
18
            '.travis.yml',
19
            '.git',
20
            '.gitignore',
21
            'build.py',
22
            'tox.ini',
23
            'jsons.egg-info',
24
            '_config.yml',
25
        ]
26
        lines = [f'--exclude="./{l.strip()}"'
27
                 for l in f.readlines() + static_exclusions
28
                 if l.strip()
29
                 and '*' not in l
30
                 and '#' not in l
31
                 and not l.startswith('/')]
32
        return ' '.join(lines)
33
34
35
filename = f'jsons-{get_version()}.tar.gz'
36
37
cmd_tar = (f'tar {get_exclusions()} '
38
           f'--exclude="{filename}" '
39
           f'-czf {filename} *')
40
41
cmd_wheel = 'python setup.py bdist_wheel'
42
cmd_mkdir_tar = 'mkdir tar'
43
cmd_move_tar = f'move {filename} tar'
44
cmd_deploy = 'twine upload dist/*'
45
46
arg_build = 'build'
47
arg_deploy = 'deploy'
48
args = [arg_build, arg_deploy]
49
50
if __name__ == '__main__':
51
    if os.name == 'nt':
52
        if len(sys.argv) < 2:
53
            print(f'Expecting one of the following commands: {", ".join(args)}')
54
        elif sys.argv[1] == arg_build:
55
            os.system(cmd_wheel)
56
            os.system(cmd_tar)
57
            os.system(cmd_mkdir_tar)
58
            os.system(cmd_move_tar)
59
        elif sys.argv[1] == arg_deploy:
60
            os.system(cmd_deploy)
61
        else:
62
            print(f'Unsupported command "{sys.argv[1]}"')
63
    else:
64
        print('This script is intended for use on Windows only')
65