Reindent and add docstring

This commit is contained in:
Jason R. Coombs 2017-05-20 04:21:08 -04:00
parent 6d2e11b7d1
commit ce0ff0040f
1 changed files with 23 additions and 18 deletions

View File

@ -999,24 +999,29 @@ class Config(object):
self._warn_about_missing_assertion(mode) self._warn_about_missing_assertion(mode)
def _mark_plugins_for_rewrite(self, hook): def _mark_plugins_for_rewrite(self, hook):
import pkg_resources """
self.pluginmanager.rewrite_hook = hook Given an importhook, mark for rewrite any top-level
for entrypoint in pkg_resources.iter_entry_points('pytest11'): modules or packages in the distribution package for
# 'RECORD' available for plugins installed normally (pip install) all pytest plugins.
# 'SOURCES.txt' available for plugins installed in dev mode (pip install -e) """
# for installed plugins 'SOURCES.txt' returns an empty list, and vice-versa import pkg_resources
# so it shouldn't be an issue self.pluginmanager.rewrite_hook = hook
for metadata in ('RECORD', 'SOURCES.txt'): for entrypoint in pkg_resources.iter_entry_points('pytest11'):
for entry in entrypoint.dist._get_metadata(metadata): # 'RECORD' available for plugins installed normally (pip install)
fn = entry.split(',')[0] # 'SOURCES.txt' available for plugins installed in dev mode (pip install -e)
is_simple_module = os.sep not in fn and fn.endswith('.py') # for installed plugins 'SOURCES.txt' returns an empty list, and vice-versa
is_package = fn.count(os.sep) == 1 and fn.endswith('__init__.py') # so it shouldn't be an issue
if is_simple_module: for metadata in ('RECORD', 'SOURCES.txt'):
module_name, ext = os.path.splitext(fn) for entry in entrypoint.dist._get_metadata(metadata):
hook.mark_rewrite(module_name) fn = entry.split(',')[0]
elif is_package: is_simple_module = os.sep not in fn and fn.endswith('.py')
package_name = os.path.dirname(fn) is_package = fn.count(os.sep) == 1 and fn.endswith('__init__.py')
hook.mark_rewrite(package_name) if is_simple_module:
module_name, ext = os.path.splitext(fn)
hook.mark_rewrite(module_name)
elif is_package:
package_name = os.path.dirname(fn)
hook.mark_rewrite(package_name)
def _warn_about_missing_assertion(self, mode): def _warn_about_missing_assertion(self, mode):
try: try: