Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add custom setup.py test command
  • Loading branch information
jackwilsdon committed Jun 14, 2016
1 parent c31e1d8 commit 9a850e0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Expand Up @@ -28,10 +28,9 @@ matrix:
# To install dependencies, tell tox to do everything but actually running the
# test.
install:
- travis_retry pip install tox
- travis_retry tox --notest
- travis_retry python setup.py test -a "--notest"

script: tox
script: python setup.py test

# Report coverage to codecov.io.
before_install:
Expand Down
67 changes: 63 additions & 4 deletions setup.py
@@ -1,5 +1,63 @@
from setuptools import setup
from __future__ import division, absolute_import, print_function

import os
from os import path
import sys
from setuptools.dist import Distribution
from setuptools import setup, Command


class CustomDistribution(Distribution):
def __init__(self, *args, **kwargs):
self.sdist_requires = None
Distribution.__init__(self, *args, **kwargs)

def get_finalized_command(self, command, create=1):
cmd_obj = self.get_command_obj(command, create)
cmd_obj.ensure_finalized()
return cmd_obj

def export_live_eggs(self, env=False):
"""Adds all of the eggs in the current environment to PYTHONPATH."""
path_eggs = [p for p in sys.path if p.endswith('.egg')]

command = self.get_finalized_command("egg_info")
egg_base = path.abspath(command.egg_base)

unique_path_eggs = set(path_eggs + [egg_base])

os.environ['PYTHONPATH'] = ':'.join(unique_path_eggs)


class test(Command): # noqa: ignore=N801
"""Command to run tox."""

description = "run tox tests"

user_options = [('tox-args=', 'a', "Arguments to pass to tox")]

def initialize_options(self):
self.tox_args = ''

def finalize_options(self):
pass

def run(self):
# Install test dependencies if needed.
if self.distribution.tests_require:
self.distribution.fetch_build_eggs(self.distribution.tests_require)

# Add eggs to PYTHONPATH. We need to do this to ensure our eggs are
# seen by Tox.
self.distribution.export_live_eggs()

shlex = __import__('shlex')
tox = __import__('tox')

parsed_args = shlex.split(self.tox_args)
result = tox.cmdline(args=parsed_args)

sys.exit(result)


def _read(fn):
Expand All @@ -17,10 +75,10 @@ def _read(fn):
license='MIT',
platforms='ALL',
long_description=_read("README.rst"),
install_requires=[
'pyyaml'
],
install_requires=['pyyaml'],
tests_require=['tox'],
py_modules=['confuse'],
cmdclass={'test': test},
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
Expand All @@ -30,4 +88,5 @@ def _read(fn):
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
distclass=CustomDistribution
)

0 comments on commit 9a850e0

Please sign in to comment.