Passed
Push — develop ( 63be29...c81ce7 )
by Shalom
01:25
created

setup.version()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 0
1
#!/usr/bin/env python3
2
3
# -*- coding: utf-8 -*-
4
5
import distutils.cmd
6
import os
7
import re
8
import setuptools
9
import subprocess
10
import sys
11
12
# Suppress setup.py's stdout logging for our commands that output data
13
if any( x in ['requirements', 'version'] for x in sys.argv ):
14
    sys.argv.insert(1, '-q')
15
16
requirements_dev = '''
17
jinja2==2.11.*
18
pyyaml==5.3.*
19
markdown==3.2.*
20
'''.strip().split('\n')
21
22
requirements_test = '''
23
ansible>=2.8
24
cffi==1.14.2
25
coverage==5.2.1
26
pytest-tap==3.1
27
pytest-cov==2.10.1
28
pytest==6.0.1
29
'''.strip().split('\n')
30
31
# https://jichu4n.com/posts/how-to-add-custom-build-steps-and-commands-to-setuppy/
32
class RequirementsCommand(distutils.cmd.Command):
33
    """ Emit requirements """
34
    description = 'emit requirements'
35
    user_options = [
36
        ('dev',  None, 'emit dev requirements'),
37
        ('test', None, 'emit test requirements')
38
    ]
39
40
    def initialize_options(self):
41
        self.dev  = None
42
        self.test = None
43
44
    def finalize_options(self): pass
45
46
    def run(self):
47
        if self.test:
48
           requirements = requirements_test
49
        else:
50
           requirements = requirements_dev
51
        print('\n'.join(requirements))
52
        return requirements
53
54
def version():
55
    args = 'git describe --tags --always'.split(' ')
56
    version = subprocess.check_output(args).decode().strip()
57
    version = re.sub('^[vV]|\-\w{8}$', '', version)
58
    version = re.sub('-', '.post', version)
59
    return version
60
61
class VersionCommand(distutils.cmd.Command):
62
    """ Emit version numbers """
63
    description = 'Emit version numbers'
64
    user_options = [
65
        ('version', None, 'current version number'),
66
        ('next', None, 'next version number'),
67
    ]
68
    def initialize_options(self): pass
69
    def finalize_options(self): pass
70
    def run(self):
71
        print(version())
72
        return(version())
73
74
with open('README.md', 'r') as fh:
75
    long_description = fh.read()
76
77
setuptools.setup(
78
    name             = 'inji',
79
    version          = version(),
80
    description      = 'Render parametrized Jinja2 templates at the CLI',
81
    author           = 'Shalom Bhooshi',
82
    author_email     = '[email protected]',
83
    license          = 'Apache License 2.0',
84
    url              = 'https://github.com/shalomb/inji',
85
    download_url     = 'https://github.com/shalomb/inji/tarball/{}'.format(version()),
86
    packages         = setuptools.find_packages(),
87
    scripts          = [ 'bin/inji' ],
88
    install_requires = requirements_dev,
89
    include_package_data = True,
90
    zip_safe         = False,
91
    python_requires  = '>=3.5',
92
    long_description_content_type = 'text/markdown',
93
    long_description = long_description,
94
    keywords         = [ 'jinja', 'jinja2', 'templating' ],
95
    classifiers      = [
96
        'Development Status :: 4 - Beta',
97
        'Environment :: Console',
98
        'Intended Audience :: Developers',
99
        'Intended Audience :: System Administrators',
100
        'License :: OSI Approved :: Apache Software License',
101
        'Operating System :: OS Independent',
102
        'Programming Language :: Python :: 3',
103
        'Topic :: Software Development',
104
        'Topic :: System :: Systems Administration'
105
    ],
106
    cmdclass         = {
107
        'requirements': RequirementsCommand,
108
        'version':      VersionCommand,
109
    }
110
)
111