Skip to content
Browse files

setup environment to be more modern; tweak Makefile; convert to CircleCI

  • Loading branch information...
1 parent d349d76 commit 91e652c04b8e645c3cf197dd17e1e177f2a7dc1c @bear committed Mar 15, 2016
Showing with 118 additions and 38 deletions.
  1. +5 −0 .gitignore
  2. +1 −0 MANIFEST.in
  3. +13 −14 Makefile
  4. +11 −0 circle.yml
  5. +10 −0 requirements-test.txt
  6. +4 −0 setup.cfg
  7. +57 −14 setup.py
  8. +9 −2 twitter/__init__.py
  9. +8 −8 twitter/api.py
View
5 .gitignore
@@ -18,13 +18,16 @@ var
sdist
develop-eggs
.installed.cfg
+.eggs
+.cache
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
+htmlcov
# PyCharm data
.idea
@@ -37,3 +40,5 @@ pip-log.txt
#Environment
env
+
+violations.flake8.txt
View
1 MANIFEST.in
@@ -3,4 +3,5 @@ include COPYING
include LICENSE
include NOTICE
include *.rst
+include requirements.txt
prune .DS_Store
View
27 Makefile
@@ -1,21 +1,17 @@
help:
- @echo " env create a development environment using virtualenv"
- @echo " deps install dependencies"
+ @echo " env install all production dependencies"
+ @echo " dev install all dev and production dependencies (virtualenv is assumed)"
@echo " clean remove unwanted stuff"
@echo " lint check style with flake8"
- @echo " coverage run tests with code coverage"
@echo " test run tests"
+ @echo " coverage run tests with code coverage"
env:
- sudo easy_install pip && \
- pip install virtualenv && \
- virtualenv env && \
- . env/bin/activate && \
- make deps
+ pip install -r requirements.txt
-deps:
- pip install -r requirements.txt --use-mirrors
+dev: env
+ pip install -r requirements-test.txt
clean:
rm -fr build
@@ -27,13 +23,16 @@ clean:
lint:
flake8 twitter > violations.flake8.txt
-coverage:
- nosetests --with-coverage --cover-package=twitter
+test: lint
+ python setup.py test
-test:
- nosetests
+coverage: clean test
+ coverage run --source=twitter setup.py test --addopts "--ignore=venv"
+ coverage html
+ coverage report
build: clean
+ python setup.py check
python setup.py sdist
python setup.py bdist_wheel
View
11 circle.yml
@@ -0,0 +1,11 @@
+machine:
+ python:
+ version: 2.7.10 pre:
+
+dependencies:
+ override:
+ - make deps-test
+
+test:
+ override:
+ - make coverage
View
10 requirements-test.txt
@@ -0,0 +1,10 @@
+pytest>=2.8.7
+pytest-cov>=2.2.0
+pytest-runner>=2.6.2
+mccabe>=0.3.1
+flake8>=2.5.2
+mock>=1.3.0
+coverage>=4.0.3
+coveralls>=1.1
+codecov>=1.6.3
+check-manifest>=0.30
View
4 setup.cfg
@@ -1,6 +1,10 @@
+[aliases]
+test = pytest
+
[check-manifest]
ignore =
.travis.yml
+ circle.yml
violations.flake8.txt
[flake8]
View
71 setup.py
@@ -1,4 +1,7 @@
#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from __future__ import absolute_import, print_function
+
#
# Copyright 2007-2016 The Python-Twitter Developers
#
@@ -14,33 +17,73 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-'''The setup and build script for the python-twitter library.'''
-
import os
+import sys
+import re
+import codecs
from setuptools import setup, find_packages
+from setuptools.command.test import test as TestCommand
+
+cwd = os.path.abspath(os.path.dirname(__file__))
+
+class PyTest(TestCommand):
+ """You can pass a single string of arguments using the
+ --pytest-args or -a command-line option:
+ python setup.py test -a "--durations=5"
+ is equivalent to running:
+ py.test --durations=5
+ """
+ user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')]
+
+ def initialize_options(self):
+ TestCommand.initialize_options(self)
+ self.pytest_args = ['--strict', '--verbose', '--tb=long', 'tests']
+ def finalize_options(self):
+ TestCommand.finalize_options(self)
-def read(*paths):
- """Build a file path from *paths* and return the contents."""
- with open(os.path.join(*paths), 'r') as f:
- return f.read()
+ def run_tests(self):
+ # import here, cause outside the eggs aren't loaded
+ import pytest
+ errno = pytest.main(self.pytest_args)
+ sys.exit(errno)
+def read(filename):
+ with codecs.open(os.path.join(cwd, filename), 'rb', 'utf-8') as h:
+ return h.read()
+
+metadata = read(os.path.join(cwd, 'twitter', '__init__.py'))
+
+def extract_metaitem(meta):
+ # swiped from https://hynek.me 's attr package
+ meta_match = re.search(r"""^__{meta}__\s+=\s+['\"]([^'\"]*)['\"]""".format(meta=meta),
+ metadata, re.MULTILINE)
+ if meta_match:
+ return meta_match.group(1)
+ raise RuntimeError('Unable to find __{meta}__ string.'.format(meta=meta))
+
setup(
name='python-twitter',
- version='3.0rc1',
- author='The Python-Twitter Developers',
- author_email='[email protected]',
- license='Apache License 2.0',
- url='https://github.com/bear/python-twitter',
- keywords='twitter api',
- description='A Python wrapper around the Twitter API',
+ version=extract_metaitem('version'),
+ license=extract_metaitem('license'),
+ description=extract_metaitem('description'),
long_description=(read('README.rst') + '\n\n' +
read('AUTHORS.rst') + '\n\n' +
read('CHANGES')),
- packages=find_packages(exclude=['tests*']),
+ author=extract_metaitem('author'),
+ author_email=extract_metaitem('email'),
+ maintainer=extract_metaitem('author'),
+ maintainer_email=extract_metaitem('email'),
+ url=extract_metaitem('url'),
+ download_url=extract_metaitem('download_url'),
+ packages=find_packages(exclude=('tests', 'docs')),
+ platforms=['Any'],
install_requires=['future', 'requests', 'requests-oauthlib'],
+ setup_requires=['pytest-runner'],
+ tests_require=['pytest'],
+ keywords='twitter api',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
View
11 twitter/__init__.py
@@ -19,8 +19,15 @@
"""A library that provides a Python interface to the Twitter API"""
from __future__ import absolute_import
-__author__ = '[email protected]'
-__version__ = '3.0rc1'
+__author__ = 'The Python-Twitter Developers'
+__email__ = '[email protected]'
+__copyright__ = 'Copyright (c) 2007-2016 The Python-Twitter Developers'
+__license__ = 'Apache License 2.0'
+__version__ = '3.0rc1'
+__url__ = 'https://github.com/bear/python-twitter'
+__download_url__ = 'https://pypi.python.org/pypi/python-twitter'
+__description__ = 'A Python wrapper around the Twitter API'
+
import json # noqa
View
16 twitter/api.py
@@ -36,15 +36,15 @@
from past.utils import old_div
try:
- # python 3
- from urllib.parse import urlparse, urlunparse, urlencode
- from urllib.request import urlopen
- from urllib.request import __version__ as urllib_version
+ # python 3
+ from urllib.parse import urlparse, urlunparse, urlencode
+ from urllib.request import urlopen
+ from urllib.request import __version__ as urllib_version
except ImportError:
- from urlparse import urlparse, urlunparse
- from urllib2 import urlopen
- from urllib import urlencode
- from urllib import __version__ as urllib_version
+ from urlparse import urlparse, urlunparse
+ from urllib2 import urlopen
+ from urllib import urlencode
+ from urllib import __version__ as urllib_version
from twitter import (__version__, _FileCache, json, DirectMessage, List,
Status, Trend, TwitterError, User, UserStatus)

0 comments on commit 91e652c

Please sign in to comment.
Something went wrong with that request. Please try again.