From e7811f02923a98eafe7dd3afcaefe3ab856cc4e2 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 16 Sep 2018 16:40:30 +0900 Subject: [PATCH] Fix #5437: autodoc: crashed on modules importing eggs --- CHANGES | 1 + sphinx/util/__init__.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index f2ec8b162..faaf4ad67 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,7 @@ Bugs fixed * #5421: autodoc emits deprecation warning for :confval:`autodoc_default_flags` * #5422: lambda object causes PicklingError on storing environment * #5417: Sphinx fails to build with syntax error in Python 2.7.5 +* #5437: autodoc: crashed on modules importing eggs Testing -------- diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 0c0c22c9c..2da685a97 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -314,8 +314,9 @@ def get_module_source(modname): filename += 'w' elif not (lfilename.endswith('.py') or lfilename.endswith('.pyw')): raise PycodeError('source is not a .py file: %r' % filename) - elif '.egg' in filename: - eggpath, _ = re.split('(?<=\\.egg)/', filename) + elif ('.egg' + os.path.sep) in filename: + pat = '(?<=\\.egg)' + re.escape(os.path.sep) + eggpath, _ = re.split(pat, filename, 1) if path.isfile(eggpath): return 'file', filename