Completed
Push — develop ( 8e34d8...4d1fdf )
by A
56s
created

long_description()   A

Complexity

Conditions 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
#
4
# Copyright (c) 2014-2016 Scaleway and Contributors. All Rights Reserved.
5
#                         Kevin Deldycke <[email protected]>
6
#
7
# Licensed under the BSD 2-Clause License (the "License"); you may not use this
8
# file except in compliance with the License. You may obtain a copy of the
9
# License at https://opensource.org/licenses/BSD-2-Clause
10
11
12
from __future__ import (
13
    absolute_import,
14
    division,
15
    print_function,
16
    unicode_literals
17
)
18
19
import io
20
import re
21
from os import path
22
23
from setuptools import find_packages, setup
24
25
MODULE_NAME = 'port_range'
26
PACKAGE_NAME = MODULE_NAME.replace('_', '-')
27
28
DEPENDENCIES = []
29
30
EXTRA_DEPENDENCIES = {
31
    # Extra dependencies are made available through the
32
    # `$ pip install .[keyword]` command.
33
    'tests': [
34
        'coverage',
35
        'nose',
36
        'pycodestyle >= 2.1.0',
37
        'pylint'],
38
    'develop': [
39
        'bumpversion',
40
        'isort',
41
        'readme_renderer',
42
        'setuptools >= 24.2.1'
43
        'wheel']}
44
45
46
def read_file(*relative_path_elements):
47
    """ Return content of a file relative to this ``setup.py``. """
48
    file_path = path.join(path.dirname(__file__), *relative_path_elements)
49
    return io.open(file_path, encoding='utf8').read().strip()
50
51
52
# Cache fetched version.
53
_version = None  # noqa
54
55
56
def version():
57
    """ Extracts version from the ``__init__.py`` file at the module's root.
58
    Inspired by: https://packaging.python.org/single_source_version/
59
    """
60
    global _version
61
    if _version:
62
        return _version
63
    init_file = read_file(MODULE_NAME, '__init__.py')
64
    matches = re.search(
65
        r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', init_file, re.M)
66
    if not matches:
67
        raise RuntimeError("Unable to find version string in __init__.py .")
68
    _version = matches.group(1)  # noqa
69
    return _version
70
71
72
def latest_changes():
73
    """ Extract part of changelog pertaining to version. """
74
    lines = []
75
    for line in read_file('CHANGES.rst').splitlines():
76
        if line.startswith('-------'):
77
            if len(lines) > 1:
78
                lines = lines[:-1]
79
                break
80
        if lines:
81
            lines.append(line)
82
        elif line.startswith("`{} (".format(version())):
83
            lines.append(line)
84
    if not lines:
85
        raise RuntimeError(
86
            "Unable to find changelog for the {} release.".format(version()))
87
    # Renormalize and clean lines.
88
    return '\n'.join(lines).strip().split('\n')
89
90
91
def long_description():
92
    """ Collates project README and latest changes. """
93
    changes = latest_changes()
94
    changes[0] = "`Changes for v{}".format(changes[0][1:])
95
    changes[1] = '-' * len(changes[0])
96
    return "\n\n\n".join([
97
        read_file('README.rst'),
98
        '\n'.join(changes),
99
        "`Full changelog <https://github.com/scaleway/{}/blob/develop/"
100
        "CHANGES.rst#changelog>`_.".format(PACKAGE_NAME)])
101
102
103
setup(
104
    name=PACKAGE_NAME,
105
    version=version(),
106
    description="Port range with support of CIDR-like notation.",
107
    long_description=long_description(),
108
    keywords=[
109
        'port', 'network', 'tcp', 'cidr', 'ip', 'protocol', 'udp', 'internet'],
110
111
    author='Scaleway',
112
    author_email='[email protected]',
113
    url='https://github.com/scaleway/port-range',
114
    license='BSD',
115
116
    packages=find_packages(),
117
    # https://www.python.org/dev/peps/pep-0345/#version-specifiers
118
    python_requires='>= 2.7, != 3.0, != 3.1, != 3.2',
119
    install_requires=DEPENDENCIES,
120
    tests_require=DEPENDENCIES + EXTRA_DEPENDENCIES['tests'],
121
    extras_require=EXTRA_DEPENDENCIES,
122
    dependency_links=[],
123
    test_suite='{}.tests'.format(MODULE_NAME),
124
125
    classifiers=[
126
        # See: https://pypi.python.org/pypi?:action=list_classifiers
127
        'Development Status :: 5 - Production/Stable',
128
        'Intended Audience :: Developers',
129
        'Intended Audience :: Information Technology',
130
        'License :: OSI Approved :: BSD License',
131
        'Operating System :: OS Independent',
132
        # List of python versions and their support status:
133
        # https://en.wikipedia.org/wiki/CPython#Version_history
134
        'Programming Language :: Python',
135
        'Programming Language :: Python :: 2',
136
        'Programming Language :: Python :: 2.7',
137
        'Programming Language :: Python :: 3',
138
        'Programming Language :: Python :: 3.3',
139
        'Programming Language :: Python :: 3.4',
140
        'Programming Language :: Python :: 3.5',
141
        'Programming Language :: Python :: Implementation :: CPython',
142
        'Programming Language :: Python :: Implementation :: PyPy',
143
        'Topic :: Software Development :: Libraries :: Python Modules',
144
        'Topic :: System :: Networking',
145
    ],
146
147
    entry_points={
148
        'console_scripts': [],
149
    }
150
)
151