Skip to content

Commit e769fcb

Browse files
Carreaumeeseeksmachine
authored andcommitted
Backport PR #12367: PR: Add handling for malformed pathext env var (Windows)
1 parent 046f1f6 commit e769fcb

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

IPython/core/magics/osm.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from IPython.utils.process import abbrev_cwd
2626
from IPython.utils.terminal import set_term_title
2727
from traitlets import Bool
28+
from warnings import warn
2829

2930

3031
@magics_class
@@ -48,8 +49,15 @@ def __init__(self, shell=None, **kwargs):
4849
winext = os.environ['pathext'].replace(';','|').replace('.','')
4950
except KeyError:
5051
winext = 'exe|com|bat|py'
51-
52-
self.execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
52+
try:
53+
self.execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
54+
except re.error:
55+
warn("Seems like your pathext environmental "
56+
"variable is malformed. Please check it to "
57+
"enable a proper handle of file extensions "
58+
"managed for your system")
59+
winext = 'exe|com|bat|py'
60+
self.execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
5361

5462
# call up the chain
5563
super().__init__(shell=shell, **kwargs)

0 commit comments

Comments
 (0)