diff options
| author | Paul Ganssle <paul@ganssle.io> | 2019-01-28 09:22:49 -0500 |
|---|---|---|
| committer | Paul Ganssle <paul@ganssle.io> | 2019-02-03 12:25:06 -0500 |
| commit | 49d17725a0ad02552babbdc79c737cfb27430f4f (patch) | |
| tree | 002736157226b67f45e1605dd3ddce997406101f /setuptools | |
| parent | 90a8701ae4088db2092a574c39c9ee56efc7eb6b (diff) | |
| download | external_python_setuptools-49d17725a0ad02552babbdc79c737cfb27430f4f.tar.gz external_python_setuptools-49d17725a0ad02552babbdc79c737cfb27430f4f.tar.bz2 external_python_setuptools-49d17725a0ad02552babbdc79c737cfb27430f4f.zip | |
Set sys.path in try/finally block with comment
Per Nick Coghlan's suggestion on PR #1652, a try/finally block ensures
that the path is restored even in the event of an error.
Diffstat (limited to 'setuptools')
| -rw-r--r-- | setuptools/build_meta_legacy.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/setuptools/build_meta_legacy.py b/setuptools/build_meta_legacy.py index 7eed41f1..03492da9 100644 --- a/setuptools/build_meta_legacy.py +++ b/setuptools/build_meta_legacy.py @@ -6,6 +6,7 @@ bridge between the old packaging mechanism and the new packaging mechanism, and will eventually be removed. """ +import os import sys from setuptools.build_meta import _BuildMetaBackend @@ -25,14 +26,21 @@ class _BuildMetaLegacyBackend(_BuildMetaBackend): # In order to maintain compatibility with scripts assuming that # the setup.py script is in a directory on the PYTHONPATH, inject # '' into sys.path. (pypa/setuptools#1642) - sys_path = list(sys.path) # Save the old path - if '' not in sys.path: - sys.path.insert(0, '') - - super(_BuildMetaLegacyBackend, - self).run_setup(setup_script=setup_script) - - sys.path = sys_path # Restore the old path + sys_path = list(sys.path) # Save the original path + + try: + if '' not in sys.path: + sys.path.insert(0, '') + + super(_BuildMetaLegacyBackend, + self).run_setup(setup_script=setup_script) + finally: + # While PEP 517 frontends should be calling each hook in a fresh + # subprocess according to the standard (and thus it should not be + # strictly necessary to restore the old sys.path), we'll restore + # the original path so that the path manipulation does not persist + # within the hook after run_setup is called. + sys.path[:] = sys_path _BACKEND = _BuildMetaLegacyBackend() |
