summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/config.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-06-19 19:23:43 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-06-19 19:23:43 (GMT)
commit3e425ac64b1f9ed858b098411012909cfe7b854e (patch)
tree72b37a6e204a19ee31d297d1509f415f7c4d58ad /Lib/packaging/config.py
parente043b6bac7c2d2845e0b1d10d140364c73de8456 (diff)
downloadcpython-3e425ac64b1f9ed858b098411012909cfe7b854e.zip
cpython-3e425ac64b1f9ed858b098411012909cfe7b854e.tar.gz
cpython-3e425ac64b1f9ed858b098411012909cfe7b854e.tar.bz2
packaging: Add the project directory to sys.path to support local setup hooks.
Original patch by Vinay Sajip on #11637.
Diffstat (limited to 'Lib/packaging/config.py')
-rw-r--r--Lib/packaging/config.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/Lib/packaging/config.py b/Lib/packaging/config.py
index 21bbcf8..43263f7 100644
--- 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:
- try:
- hook = resolve_name(line)
- except ImportError as e:
- logger.warning('cannot find setup hook: %s', e.args[0])
- else:
- self.setup_hooks.append(hook)
-
- self.run_hooks(content)
+ # add project directory to sys.path, to allow hooks to be
+ # distributed with the project
+ sys.path.insert(0, cfg_directory)
+ try:
+ for line in setup_hooks:
+ try:
+ hook = resolve_name(line)
+ except ImportError as e:
+ logger.warning('cannot find setup hook: %s', e.args[0])
+ else:
+ self.setup_hooks.append(hook)
+ self.run_hooks(content)
+ finally:
+ sys.path.pop(0)
metadata = self.dist.metadata