setup.VersionCommand.finalize_options()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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