|
9 | 9 | # file except in compliance with the License. You may obtain a copy of the |
10 | 10 | # License at https://opensource.org/licenses/BSD-2-Clause |
11 | 11 |
|
12 | | -import os |
| 12 | +from __future__ import ( |
| 13 | + absolute_import, |
| 14 | + division, |
| 15 | + print_function, |
| 16 | + unicode_literals |
| 17 | +) |
| 18 | + |
| 19 | +import io |
13 | 20 | import re |
14 | 21 | import sys |
15 | | -from contextlib import closing |
| 22 | +from os import path |
16 | 23 |
|
17 | 24 | from setuptools import find_packages, setup |
18 | 25 |
|
19 | 26 | MODULE_NAME = 'scaleway' |
| 27 | +PACKAGE_NAME = 'scaleway-sdk' |
20 | 28 |
|
21 | | - |
22 | | -def get_version(): |
23 | | - |
24 | | - with open(os.path.join( |
25 | | - os.path.dirname(__file__), MODULE_NAME, '__init__.py') |
26 | | - ) as init: |
27 | | - |
28 | | - for line in init.readlines(): |
29 | | - res = re.match(r'__version__ *= *[\'"]([0-9\.]*)[\'"]$', line) |
30 | | - if res: |
31 | | - return res.group(1) |
32 | | - |
33 | | - |
34 | | -def get_long_description(): |
35 | | - readme = os.path.join(os.path.dirname(__file__), 'README.rst') |
36 | | - changes = os.path.join(os.path.dirname(__file__), 'CHANGES.rst') |
37 | | - with closing(open(readme)) as hreadme, closing(open(changes)) as hchanges: |
38 | | - return hreadme.read() + '\n' + hchanges.read() |
39 | | - |
40 | | - |
41 | | -REQUIREMENTS = [ |
| 29 | +DEPENDENCIES = [ |
42 | 30 | 'slumber >= 0.6.2', |
43 | 31 | 'six'] |
44 | 32 |
|
45 | 33 | # Packages required to handle SNI, only for Python2. |
46 | 34 | if sys.version_info.major == 2: |
47 | | - REQUIREMENTS += [ |
| 35 | + DEPENDENCIES += [ |
48 | 36 | 'pyOpenSSL', |
49 | 37 | 'ndg-httpsclient', |
50 | | - 'pyasn1' |
51 | | - ] |
| 38 | + 'pyasn1'] |
| 39 | + |
| 40 | +EXTRA_DEPENDENCIES = { |
| 41 | + # Extra dependencies are made available through the |
| 42 | + # `$ pip install .[keyword]` command. |
| 43 | + 'tests': [ |
| 44 | + 'coverage', |
| 45 | + 'httpretty >= 0.8.0', |
| 46 | + 'mock', |
| 47 | + 'nose', |
| 48 | + 'pycodestyle >= 2.1.0', |
| 49 | + 'pylint'], |
| 50 | + 'develop': [ |
| 51 | + 'bumpversion', |
| 52 | + 'isort', |
| 53 | + 'readme_renderer', |
| 54 | + 'setuptools >= 24.2.1' |
| 55 | + 'wheel']} |
| 56 | + |
| 57 | + |
| 58 | +def read_file(*relative_path_elements): |
| 59 | + """ Return content of a file relative to this ``setup.py``. """ |
| 60 | + file_path = path.join(path.dirname(__file__), *relative_path_elements) |
| 61 | + return io.open(file_path, encoding='utf8').read().strip() |
| 62 | + |
| 63 | + |
| 64 | +# Cache fetched version. |
| 65 | +_version = None # noqa |
| 66 | + |
| 67 | + |
| 68 | +def version(): |
| 69 | + """ Extract version from the ``__init__.py`` file at the module's root. |
| 70 | +
|
| 71 | + Inspired by: https://packaging.python.org/single_source_version/ |
| 72 | + """ |
| 73 | + global _version |
| 74 | + if _version: |
| 75 | + return _version |
| 76 | + init_file = read_file(MODULE_NAME, '__init__.py') |
| 77 | + matches = re.search( |
| 78 | + r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', init_file, re.M) |
| 79 | + if not matches: |
| 80 | + raise RuntimeError("Unable to find version string in __init__.py .") |
| 81 | + _version = matches.group(1) # noqa |
| 82 | + return _version |
| 83 | + |
| 84 | + |
| 85 | +def latest_changes(): |
| 86 | + """ Extract part of changelog pertaining to version. """ |
| 87 | + lines = [] |
| 88 | + for line in read_file('CHANGES.rst').splitlines(): |
| 89 | + if line.startswith('-------'): |
| 90 | + if len(lines) > 1: |
| 91 | + lines = lines[:-1] |
| 92 | + break |
| 93 | + if lines: |
| 94 | + lines.append(line) |
| 95 | + elif line.startswith("`{} (".format(version())): |
| 96 | + lines.append(line) |
| 97 | + if not lines: |
| 98 | + raise RuntimeError( |
| 99 | + "Unable to find changelog for the {} release.".format(version())) |
| 100 | + # Renormalize and clean lines. |
| 101 | + return '\n'.join(lines).strip().split('\n') |
| 102 | + |
| 103 | + |
| 104 | +def long_description(): |
| 105 | + """ Collates project README and latest changes. """ |
| 106 | + changes = latest_changes() |
| 107 | + changes[0] = "`Changes for v{}".format(changes[0][1:]) |
| 108 | + changes[1] = '-' * len(changes[0]) |
| 109 | + return "\n\n\n".join([ |
| 110 | + read_file('README.rst'), |
| 111 | + '\n'.join(changes), |
| 112 | + "`Full changelog <https://github.com/scaleway/python-scaleway/blob/" |
| 113 | + "develop/CHANGES.rst#changelog>`_."]) |
52 | 114 |
|
53 | 115 | setup( |
54 | | - name='scaleway-sdk', |
55 | | - version=get_version(), |
56 | | - description="Tools to query the REST APIs of Scaleway", |
57 | | - long_description=get_long_description(), |
| 116 | + name=PACKAGE_NAME, |
| 117 | + version=version(), |
| 118 | + description="Python SDK to query Scaleway APIs.", |
| 119 | + long_description=long_description(), |
| 120 | + keywords=['network', 'compute', 'storage', 'api', 'sdk', 'cloud', 'iaas'], |
58 | 121 |
|
59 | 122 | author='Scaleway', |
60 | 123 | author_email='opensource@scaleway.com', |
61 | 124 | url='https://github.com/scaleway/python-scaleway', |
62 | 125 | license='BSD', |
63 | 126 |
|
64 | | - install_requires=REQUIREMENTS, |
65 | | - |
66 | 127 | packages=find_packages(), |
67 | | - |
68 | | - tests_require=[ |
69 | | - 'httpretty >= 0.8.0', |
70 | | - 'mock', |
71 | | - ], |
72 | | - test_suite=MODULE_NAME + '.tests', |
| 128 | + # https://www.python.org/dev/peps/pep-0345/#version-specifiers |
| 129 | + python_requires='>= 2.7, != 3.0.*, != 3.1.*, != 3.2.*', |
| 130 | + install_requires=DEPENDENCIES, |
| 131 | + tests_require=DEPENDENCIES + EXTRA_DEPENDENCIES['tests'], |
| 132 | + extras_require=EXTRA_DEPENDENCIES, |
| 133 | + dependency_links=[], |
| 134 | + test_suite='{}.tests'.format(MODULE_NAME), |
73 | 135 |
|
74 | 136 | classifiers=[ |
75 | 137 | # See: https://pypi.python.org/pypi?:action=list_classifiers |
|
0 commit comments