summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-01-26 22:32:46 -0500
committerJason R. Coombs <jaraco@jaraco.com>2016-01-26 22:32:46 -0500
commit116021cba89aa955869fec102a4d50d728501f22 (patch)
tree0273eeafe43adec61ead6e941b0d767560ee1bed
parent7555f8aecfd4ea1f391ef03dd1859a217f1ccc22 (diff)
downloadpytest-runner-rwt.tar.gz
Experimental re-write using rwtrwt
-rw-r--r--ptr.py103
1 files changed, 39 insertions, 64 deletions
diff --git a/ptr.py b/ptr.py
index 5c5287e..b0bfe85 100644
--- a/ptr.py
+++ b/ptr.py
@@ -2,13 +2,13 @@
Implementation
"""
-import os as _os
import shlex as _shlex
import contextlib as _contextlib
import sys as _sys
+import itertools as _itertools
+import distutils.cmd as _cmd
-import pkg_resources
-import setuptools.command.test as orig
+import rwt.deps
@_contextlib.contextmanager
@@ -22,7 +22,26 @@ def _save_argv(repl=None):
_sys.argv[:] = saved
-class PyTest(orig.test):
+class Extra(list):
+ def __init__(self, item):
+ spec, reqs = item
+ self.name, sep, self.marker = spec.partition(':')
+ super(Extra, self).__init__(reqs)
+
+ def __bool__(self):
+ return bool(self.name)
+
+ def __iter__(self):
+ """
+ Move markers onto each of the requirements.
+ """
+ for req in super(Extra, self).__iter__():
+ if self.marker:
+ req += ';' + self.marker
+ yield req
+
+
+class PyTest(_cmd.Command):
user_options = [
('extras', None, "Install (all) setuptools extras when running tests"),
('index-url=', None, "Specify an index url from which to retrieve "
@@ -43,79 +62,35 @@ class PyTest(orig.test):
if self.addopts:
self.addopts = _shlex.split(self.addopts)
- @staticmethod
- def marker_passes(marker):
- """
- Given an environment marker, return True if the marker is valid
- and matches this environment.
- """
- return (
- marker
- and not pkg_resources.invalid_marker(marker)
- and pkg_resources.evaluate_marker(marker)
- )
+ def iter_extras(self):
+ return map(Extra, self.distribution.extras_require.items())
def run(self):
"""
Override run to ensure requirements are available in this session (but
don't install them anywhere).
"""
- self._build_egg_fetcher()
- if self.distribution.install_requires:
- self.distribution.fetch_build_eggs(self.distribution.install_requires)
- if self.distribution.tests_require:
- self.distribution.fetch_build_eggs(self.distribution.tests_require)
- extras_require = self.distribution.extras_require or {}
- for spec, reqs in extras_require.items():
- name, sep, marker = spec.partition(':')
- if marker and not self.marker_passes(marker):
- continue
- # always include unnamed extras
- if not name or self.extras:
- self.distribution.fetch_build_eggs(reqs)
+ named_extras = (x for x in self.iter_extras() if x.name)
+ unnamed_extras = (x for x in self.iter_extras() if not x.name)
+ flatten = _itertools.chain.from_iterable
+ reqs = set(_itertools.chain(
+ self.distribution.install_requires,
+ self.distribution.tests_require,
+ flatten(unnamed_extras),
+ flatten(named_extras) if self.extras else (),
+ ))
if self.dry_run:
self.announce('skipping tests (dry run)')
+ list(reqs)
return
- self.with_project_on_sys_path(self.run_tests)
+
+ with rwt.deps.on_sys_path(*reqs):
+ self.run_tests()
+
if self.result_code:
raise SystemExit(self.result_code)
return self.result_code
- def _build_egg_fetcher(self):
- """Build an egg fetcher that respects index_url and allow_hosts"""
- # modified from setuptools.dist:Distribution.fetch_build_egg
- from setuptools.command.easy_install import easy_install
- main_dist = self.distribution
- # construct a fake distribution to store the args for easy_install
- dist = main_dist.__class__({'script_args': ['easy_install']})
- dist.parse_config_files()
- opts = dist.get_option_dict('easy_install')
- keep = (
- 'find_links', 'site_dirs', 'index_url', 'optimize',
- 'site_dirs', 'allow_hosts'
- )
- for key in opts.keys():
- if key not in keep:
- del opts[key] # don't use any other settings
- if main_dist.dependency_links:
- links = main_dist.dependency_links[:]
- if 'find_links' in opts:
- links = opts['find_links'][1].split() + links
- opts['find_links'] = ('setup', links)
- if self.allow_hosts:
- opts['allow_hosts'] = ('test', self.allow_hosts)
- if self.index_url:
- opts['index_url'] = ('test', self.index_url)
- install_dir_func = getattr(dist, 'get_egg_cache_dir', _os.getcwd)
- install_dir = install_dir_func()
- cmd = easy_install(
- dist, args=["x"], install_dir=install_dir, exclude_scripts=True,
- always_copy=False, build_directory=None, editable=False,
- upgrade=False, multi_version=True, no_report = True
- )
- cmd.ensure_finalized()
- main_dist._egg_fetcher = cmd
-
def run_tests(self):
"""
Invoke pytest, replacing argv.