latest_changes()   B
last analyzed

Complexity

Conditions 7

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
c 1
b 0
f 0
dl 0
loc 17
rs 7.3333
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
#
4
# Copyright (c) 2013-2017 Scaleway and Contributors. All Rights Reserved.
5
#                         Kevin Deldycke <[email protected]>
6
#                         Bastien Chatelard <[email protected]>
7
#
8
# Licensed under the BSD 2-Clause License (the "License"); you may not use this
9
# file except in compliance with the License. You may obtain a copy of the
10
# License at http://opensource.org/licenses/BSD-2-Clause
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 = 'postal_address'
26
PACKAGE_NAME = MODULE_NAME.replace('_', '-')
27
28
DEPENDENCIES = [
29
    'boltons',
30
    'Faker >= 0.8.4',
31
    # TODO: subdivision definitions are broken for Czech Republic starting with
32
    # PyCountry 16.11.27. See:
33
    # https://bitbucket.org/flyingcircus/pycountry/issues/13389
34
    'pycountry >= 16.11.08, < 16.11.27',
35
]
36
37
EXTRA_DEPENDENCIES = {
38
    # Extra dependencies are made available through the
39
    # `$ pip install .[keyword]` command.
40
    'docs': [
41
        'sphinx >= 1.4',
42
        'sphinx_rtd_theme'],
43
    'tests': [
44
        'coverage',
45
        'nose',
46
        'pycodestyle >= 2.1.0',
47
        'pylint'],
48
    'develop': [
49
        'bumpversion',
50
        'isort',
51
        'readme_renderer',
52
        'setuptools >= 24.2.1'
53
        'wheel'],
54
}
55
56
57
def read_file(*relative_path_elements):
58
    """ Return content of a file relative to this ``setup.py``. """
59
    file_path = path.join(path.dirname(__file__), *relative_path_elements)
60
    return io.open(file_path, encoding='utf8').read().strip()
61
62
63
# Cache fetched version.
64
_version = None  # noqa
65
66
67
def version():
68
    """ Extracts version from the ``__init__.py`` file at the module's root.
69
70
    Inspired by: https://packaging.python.org/single_source_version/
71
    """
72
    global _version
73
    if _version:
74
        return _version
75
    init_file = read_file(MODULE_NAME, '__init__.py')
76
    matches = re.search(
77
        r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', init_file, re.M)
78
    if not matches:
79
        raise RuntimeError("Unable to find version string in __init__.py .")
80
    _version = matches.group(1)  # noqa
81
    return _version
82
83
84
def latest_changes():
85
    """ Extract part of changelog pertaining to version. """
86
    lines = []
87
    for line in read_file('CHANGES.rst').splitlines():
88
        if line.startswith('-------'):
89
            if len(lines) > 1:
90
                lines = lines[:-1]
91
                break
92
        if lines:
93
            lines.append(line)
94
        elif line.startswith("`{} (".format(version())):
95
            lines.append(line)
96
    if not lines:
97
        raise RuntimeError(
98
            "Unable to find changelog for the {} release.".format(version()))
99
    # Renormalize and clean lines.
100
    return '\n'.join(lines).strip().split('\n')
101
102
103
def long_description():
104
    """ Collates project README and latest changes. """
105
    changes = latest_changes()
106
    changes[0] = "`Changes for v{}".format(changes[0][1:])
107
    changes[1] = '-' * len(changes[0])
108
    return "\n\n\n".join([
109
        read_file('README.rst'),
110
        '\n'.join(changes),
111
        "`Full changelog <https://{}.readthedocs.io/en/develop/changelog.html"
112
        "#changelog>`_.".format(PACKAGE_NAME),
113
    ])
114
115
116
setup(
117
    name=PACKAGE_NAME,
118
    version=version(),
119
    description="Parse, normalize and render postal addresses.",
120
    long_description=long_description(),
121
    keywords=['address', 'l10n', 'i18n'],
122
123
    author='Scaleway',
124
    author_email='[email protected]',
125
    url='https://github.com/scaleway/postal-address',
126
    license='BSD',
127
128
    packages=find_packages(),
129
    # https://www.python.org/dev/peps/pep-0345/#version-specifiers
130
    python_requires='>= 2.7, != 3.0.*, != 3.1.*, != 3.2.*',
131
    install_requires=DEPENDENCIES,
132
    tests_require=DEPENDENCIES + EXTRA_DEPENDENCIES['tests'],
133
    extras_require=EXTRA_DEPENDENCIES,
134
    dependency_links=[
135
    ],
136
    test_suite='{}.tests'.format(MODULE_NAME),
137
138
    classifiers=[
139
        # See: https://pypi.python.org/pypi?:action=list_classifiers
140
        'Development Status :: 5 - Production/Stable',
141
        'Intended Audience :: Developers',
142
        'Intended Audience :: Information Technology',
143
        'License :: OSI Approved :: BSD License',
144
        'Operating System :: OS Independent',
145
        # List of python versions and their support status:
146
        # https://en.wikipedia.org/wiki/CPython#Version_history
147
        'Programming Language :: Python',
148
        'Programming Language :: Python :: 2',
149
        'Programming Language :: Python :: 2.7',
150
        'Programming Language :: Python :: 3',
151
        'Programming Language :: Python :: 3.3',
152
        'Programming Language :: Python :: 3.4',
153
        'Programming Language :: Python :: 3.5',
154
        'Programming Language :: Python :: Implementation :: CPython',
155
        'Programming Language :: Python :: Implementation :: PyPy',
156
        'Topic :: Office/Business',
157
        'Topic :: Software Development :: Internationalization',
158
        'Topic :: Software Development :: Libraries :: Python Modules',
159
        'Topic :: Software Development :: Localization',
160
        'Topic :: Text Processing',
161
        'Topic :: Utilities',
162
    ],
163
164
    entry_points={
165
        'console_scripts': [],
166
    }
167
)
168