|
1 | 1 | #!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +from __future__ import absolute_import, print_function |
| 4 | + |
2 | 5 | # |
3 | 6 | # Copyright 2007-2016 The Python-Twitter Developers |
4 | 7 | # |
|
14 | 17 | # See the License for the specific language governing permissions and |
15 | 18 | # limitations under the License. |
16 | 19 |
|
17 | | -'''The setup and build script for the python-twitter library.''' |
18 | | - |
19 | 20 | import os |
| 21 | +import sys |
| 22 | +import re |
| 23 | +import codecs |
20 | 24 |
|
21 | 25 | from setuptools import setup, find_packages |
| 26 | +from setuptools.command.test import test as TestCommand |
| 27 | + |
| 28 | +cwd = os.path.abspath(os.path.dirname(__file__)) |
| 29 | + |
| 30 | +class PyTest(TestCommand): |
| 31 | + """You can pass a single string of arguments using the |
| 32 | + --pytest-args or -a command-line option: |
| 33 | + python setup.py test -a "--durations=5" |
| 34 | + is equivalent to running: |
| 35 | + py.test --durations=5 |
| 36 | + """ |
| 37 | + user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')] |
| 38 | + |
| 39 | + def initialize_options(self): |
| 40 | + TestCommand.initialize_options(self) |
| 41 | + self.pytest_args = ['--strict', '--verbose', '--tb=long', 'tests'] |
22 | 42 |
|
| 43 | + def finalize_options(self): |
| 44 | + TestCommand.finalize_options(self) |
23 | 45 |
|
24 | | -def read(*paths): |
25 | | - """Build a file path from *paths* and return the contents.""" |
26 | | - with open(os.path.join(*paths), 'r') as f: |
27 | | - return f.read() |
| 46 | + def run_tests(self): |
| 47 | + # import here, cause outside the eggs aren't loaded |
| 48 | + import pytest |
| 49 | + errno = pytest.main(self.pytest_args) |
| 50 | + sys.exit(errno) |
28 | 51 |
|
29 | 52 |
|
| 53 | +def read(filename): |
| 54 | + with codecs.open(os.path.join(cwd, filename), 'rb', 'utf-8') as h: |
| 55 | + return h.read() |
| 56 | + |
| 57 | +metadata = read(os.path.join(cwd, 'twitter', '__init__.py')) |
| 58 | + |
| 59 | +def extract_metaitem(meta): |
| 60 | + # swiped from https://hynek.me 's attr package |
| 61 | + meta_match = re.search(r"""^__{meta}__\s+=\s+['\"]([^'\"]*)['\"]""".format(meta=meta), |
| 62 | + metadata, re.MULTILINE) |
| 63 | + if meta_match: |
| 64 | + return meta_match.group(1) |
| 65 | + raise RuntimeError('Unable to find __{meta}__ string.'.format(meta=meta)) |
| 66 | + |
30 | 67 | setup( |
31 | 68 | name='python-twitter', |
32 | | - version='3.0rc1', |
33 | | - author='The Python-Twitter Developers', |
34 | | - author_email='python-twitter@googlegroups.com', |
35 | | - license='Apache License 2.0', |
36 | | - url='https://github.com/bear/python-twitter', |
37 | | - keywords='twitter api', |
38 | | - description='A Python wrapper around the Twitter API', |
| 69 | + version=extract_metaitem('version'), |
| 70 | + license=extract_metaitem('license'), |
| 71 | + description=extract_metaitem('description'), |
39 | 72 | long_description=(read('README.rst') + '\n\n' + |
40 | 73 | read('AUTHORS.rst') + '\n\n' + |
41 | 74 | read('CHANGES')), |
42 | | - packages=find_packages(exclude=['tests*']), |
| 75 | + author=extract_metaitem('author'), |
| 76 | + author_email=extract_metaitem('email'), |
| 77 | + maintainer=extract_metaitem('author'), |
| 78 | + maintainer_email=extract_metaitem('email'), |
| 79 | + url=extract_metaitem('url'), |
| 80 | + download_url=extract_metaitem('download_url'), |
| 81 | + packages=find_packages(exclude=('tests', 'docs')), |
| 82 | + platforms=['Any'], |
43 | 83 | install_requires=['future', 'requests', 'requests-oauthlib'], |
| 84 | + setup_requires=['pytest-runner'], |
| 85 | + tests_require=['pytest'], |
| 86 | + keywords='twitter api', |
44 | 87 | classifiers=[ |
45 | 88 | 'Development Status :: 5 - Production/Stable', |
46 | 89 | 'Intended Audience :: Developers', |
|
0 commit comments