Skip to content

Commit 016a9d8

Browse files
committed
Modernize packaging.
1 parent ccd878a commit 016a9d8

File tree

3 files changed

+123
-42
lines changed

3 files changed

+123
-42
lines changed

.travis.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,25 @@ python:
2525
# /index-of-release-notes.html#cpython-3-3-compatible-versions
2626
- pypy3.3-5.2-alpha1
2727

28-
install:
29-
- pip install -e .
28+
before_install:
29+
# Check default Python version installed.
30+
- python --version
31+
32+
before_script:
3033
- pip install codecov
3134

3235
script:
33-
- coverage run setup.py test
36+
# Launch unittests.
37+
- pip install -e .[tests]
38+
- coverage run ./setup.py test
3439
- coverage report -m
40+
# Check coding style.
41+
- pycodestyle
42+
# Test that building packages works.
43+
- pip install -e .[develop]
44+
- ./setup.py sdist bdist_egg bdist_wheel
45+
# Validates package metadata.
46+
- ./setup.py check -m -r -s
3547

3648
after_script:
3749
- codecov

CHANGES.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ ChangeLog
99
* Remove popularity badge: PyPI download counters are broken and no longer
1010
displayed.
1111
* Move ``coverage`` config to ``setup.cfg``.
12-
* Make wheels generated under Python 2 environnment available for Python 3 too.
12+
* Add ``test`` and ``develop`` dependencies.
13+
* Only show latest changes in the long description of the package instead of
14+
the full changelog.
1315
* Add default PyLint config.
1416
* Add default ``pycodestyle`` config.
17+
* Enforce ``pycodestyle`` checks in Travis CI jobs.
18+
* Test production of packages in Travis CI jobs.
19+
* Always check for package metadata in Travis CI jobs.
20+
* Make wheels generated under Python 2 environnment available for Python 3 too.
21+
* Add link to full changelog in package's long description.
1522

1623

1724
`1.4.1 (2016-10-31) <https://github.com/scaleway/python-scaleway/compare/v1.4.0...v1.4.1>`_

setup.py

Lines changed: 100 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,67 +9,129 @@
99
# file except in compliance with the License. You may obtain a copy of the
1010
# License at https://opensource.org/licenses/BSD-2-Clause
1111

12-
import os
12+
from __future__ import (
13+
absolute_import,
14+
division,
15+
print_function,
16+
unicode_literals
17+
)
18+
19+
import io
1320
import re
1421
import sys
15-
from contextlib import closing
22+
from os import path
1623

1724
from setuptools import find_packages, setup
1825

1926
MODULE_NAME = 'scaleway'
27+
PACKAGE_NAME = 'scaleway-sdk'
2028

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 = [
4230
'slumber >= 0.6.2',
4331
'six']
4432

4533
# Packages required to handle SNI, only for Python2.
4634
if sys.version_info.major == 2:
47-
REQUIREMENTS += [
35+
DEPENDENCIES += [
4836
'pyOpenSSL',
4937
'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>`_."])
52114

53115
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'],
58121

59122
author='Scaleway',
60123
author_email='opensource@scaleway.com',
61124
url='https://github.com/scaleway/python-scaleway',
62125
license='BSD',
63126

64-
install_requires=REQUIREMENTS,
65-
66127
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),
73135

74136
classifiers=[
75137
# See: https://pypi.python.org/pypi?:action=list_classifiers

0 commit comments

Comments
 (0)