Completed
Push — develop ( 64818e...cfd4c0 )
by A
01:02
created

read_file()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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