Passed
Push — develop ( 503712...bde8f9 )
by Shalom
02:13
created

setup.VersionCommand.run()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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