Completed
Push — master ( 8a9714...a444b5 )
by Jace
9s
created

read_package_variable()   B

Complexity

Conditions 6

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
dl 0
loc 9
rs 8
c 0
b 0
f 0
1
#!/usr/bin/env python
2
3
"""Setup script for the package."""
4
5
import os
6
import sys
7
8
import setuptools
9
10
11
PACKAGE_NAME = 'mine'
12
MINIMUM_PYTHON_VERSION = 3, 3
13
14
15
def check_python_version():
16
    """Exit when the Python version is too low."""
17
    if sys.version_info < MINIMUM_PYTHON_VERSION:
18
        sys.exit("Python {}.{}+ is required.".format(*MINIMUM_PYTHON_VERSION))
19
20
21
def read_package_variable(key):
22
    """Read the value of a variable from the package without importing."""
23
    module_path = os.path.join(PACKAGE_NAME, '__init__.py')
24
    with open(module_path) as module:
25
        for line in module:
26
            parts = line.strip().split(' ')
27
            if parts and parts[0] == key:
28
                return parts[-1].strip("'")
29
    assert 0, "'{0}' not found in '{1}'".format(key, module_path)
30
31
32
def read_descriptions():
33
    """Build a description for the project from documentation files."""
34
    try:
35
        readme = open("README.rst").read()
36
        changelog = open("CHANGELOG.rst").read()
37
    except IOError:
38
        return "<placeholder>"
39
    else:
40
        return readme + '\n' + changelog
41
42
43
check_python_version()
44
setuptools.setup(
45
    name=read_package_variable('__project__'),
46
    version=read_package_variable('__version__'),
47
48
    description=read_package_variable('DESCRIPTION'),
49
    url='https://github.com/jacebrowning/mine',
50
    author='Jace Browning',
51
    author_email='[email protected]',
52
53
    packages=setuptools.find_packages(),
54
55
    entry_points={'console_scripts': [
56
        read_package_variable('CLI') + ' = mine.cli:main',
57
    ]},
58
59
    long_description=read_descriptions(),
60
    license='MIT',
61
    classifiers=[
62
        'Development Status :: 4 - Beta',
63
        'Environment :: Console',
64
        'Intended Audience :: End Users/Desktop',
65
        'License :: OSI Approved :: MIT License',
66
        'Natural Language :: English',
67
        'Operating System :: OS Independent',
68
        'Programming Language :: Python',
69
        'Programming Language :: Python :: 3',
70
        'Programming Language :: Python :: 3.3',
71
        'Programming Language :: Python :: 3.4',
72
        'Programming Language :: Python :: 3.5',
73
        'Topic :: System',
74
        'Topic :: System :: Monitoring',
75
        'Topic :: Utilities',
76
    ],
77
78
    install_requires=open("requirements.txt").readlines(),
79
)
80