mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-25885 Remove registered sphinxcontrib modules in docstring_formatter.py
Otherwise their presense doesn't let us import sphinxcontrib.napoleon that we need to render docstrings in Numpy/Google Style formats. It's not enough to remove site-packages/dist-packages from sys.path to isolate the script from such "malicious" packages, since they are registered and installed in sys.modules on interpreter startup before any path modifications happen. Launching interpreter with -S option prevents it from running these hooks and also excludes site-packages from sys.path but makes inherited stdlib modules not available in virtualenv. What's more, sphinxcontrib.napoleon itself depends on setuptools as it tries to register itself in a similar fashion in its __init__.py. We could patch it but that would make future updates of the library more tedious and error-prone.
This commit is contained in:
@@ -369,6 +369,11 @@ def format_epytext(docstring):
|
||||
|
||||
|
||||
def main():
|
||||
# Remove existing Sphinx extensions registered via
|
||||
# sphinxcontrib setuptools namespace package, as they
|
||||
# conflict with sphinxcontrib.napoleon that we bundle.
|
||||
sys.modules.pop('sphinxcontrib', None)
|
||||
|
||||
args = sys.argv[1:]
|
||||
|
||||
docstring_format = args[0] if args else 'rest'
|
||||
@@ -393,4 +398,8 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
try:
|
||||
main()
|
||||
except ImportError:
|
||||
print_safe('sys.path = %s\n\n' % sys.path, error=True)
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user