cpython: b732b02bd0ba (original) (raw)
Mercurial > cpython
changeset 70874:b732b02bd0ba
packaging: Add the project directory to sys.path to support local setup hooks. Original patch by Vinay Sajip on #11637. [#11637]
Éric Araujo merwok@netwok.org | |
---|---|
date | Sun, 19 Jun 2011 21:23:43 +0200 |
parents | 8de5fe3b1696 |
children | 7d3fbce32e07 |
files | Lib/packaging/config.py Lib/packaging/tests/test_config.py Misc/NEWS |
diffstat | 3 files changed, 39 insertions(+), 11 deletions(-)[+] [-] Lib/packaging/config.py 23 Lib/packaging/tests/test_config.py 22 Misc/NEWS 5 |
line wrap: on
line diff
--- a/Lib/packaging/config.py +++ b/Lib/packaging/config.py @@ -134,15 +134,20 @@ class Config: if 'setup_hooks' in content['global']: setup_hooks = split_multiline(content['global']['setup_hooks'])
for line in setup_hooks:[](#l1.7)
try:[](#l1.8)
hook = resolve_name(line)[](#l1.9)
except ImportError as e:[](#l1.10)
logger.warning('cannot find setup hook: %s', e.args[0])[](#l1.11)
else:[](#l1.12)
self.setup_hooks.append(hook)[](#l1.13)
self.run_hooks(content)[](#l1.15)
# add project directory to sys.path, to allow hooks to be[](#l1.16)
# distributed with the project[](#l1.17)
sys.path.insert(0, cfg_directory)[](#l1.18)
try:[](#l1.19)
for line in setup_hooks:[](#l1.20)
try:[](#l1.21)
hook = resolve_name(line)[](#l1.22)
except ImportError as e:[](#l1.23)
logger.warning('cannot find setup hook: %s', e.args[0])[](#l1.24)
else:[](#l1.25)
self.setup_hooks.append(hook)[](#l1.26)
self.run_hooks(content)[](#l1.27)
finally:[](#l1.28)
sys.path.pop(0)[](#l1.29)
--- a/Lib/packaging/tests/test_config.py +++ b/Lib/packaging/tests/test_config.py @@ -126,6 +126,15 @@ language = cxx """ +HOOKS_MODULE = """ +import logging + +logger = logging.getLogger('packaging') + +def logging_hook(config):
+""" + class DCompiler: name = 'd' @@ -326,10 +335,21 @@ class ConfigTestCase(support.TempdirMana self.assertEqual(ext.extra_compile_args, cargs) self.assertEqual(ext.language, 'cxx')
- def test_project_setup_hook_works(self):
# Bug #11637: ensure the project directory is on sys.path to allow[](#l2.24)
# project-specific hooks[](#l2.25)
self.write_setup({'setup-hooks': 'hooks.logging_hook'})[](#l2.26)
self.write_file('README', 'yeah')[](#l2.27)
self.write_file('hooks.py', HOOKS_MODULE)[](#l2.28)
self.get_dist()[](#l2.29)
logs = self.get_logs(logging.WARNING)[](#l2.30)
self.assertEqual(['logging_hook called'], logs)[](#l2.31)
self.assertIn('hooks', sys.modules)[](#l2.32)
+ def test_missing_setup_hook_warns(self): self.write_setup({'setup-hooks': 'this.does._not.exist'}) self.write_file('README', 'yeah')
dist = self.get_dist()[](#l2.37)
self.get_dist()[](#l2.38) logs = self.get_logs(logging.WARNING)[](#l2.39) self.assertEqual(1, len(logs))[](#l2.40) self.assertIn('cannot find setup hook', logs[0])[](#l2.41)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -193,7 +193,10 @@ Core and Builtins Library ------- -- Issue #6771: moved the curses.wrapper function from the single-function +- Issue #11637: Fix support for importing packaging setup hooks from the