Skip to content

Commit 8f878c3

Browse files
author
Waylan Limberg
committed
Added a temp workwround for deprecated short ext names.
As we chnaged the order in import trys for short names extensions (no dot syntax), an extra test was added to the import code for the occassion when a naming conflict exists. For example, if PyTables is installed (module name is tables) and the user tries to use the short name 'tables' instead of 'markdown.extensions.tables'. Fixes #341. Of course, this code will get ripped out when the old behavior is fully deprecated.
1 parent 39c8c1c commit 8f878c3

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

markdown/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ def build_extension(self, ext_name, configs):
221221
# Assume string uses dot syntax (`path.to.some.module`)
222222
module = importlib.import_module(ext_name)
223223
logger.debug('Successfuly imported extension module "%s".' % ext_name)
224+
# For backward compat (until deprecation) check that this is an extension
225+
if '.' not in ext_name and not (hasattr(module, 'extendMarkdown') or (class_name and hasattr(module, class_name))):
226+
# We have a name conflict (eg: extensions=['tables'] and PyTables is installed)
227+
raise ImportError
224228
except ImportError:
225229
# Preppend `markdown.extensions.` to name
226230
module_name = '.'.join(['markdown.extensions', ext_name])

tests/test_apis.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,25 +289,22 @@ def testLoadExtensionFailure(self):
289289

290290
def testLoadBadExtension(self):
291291
""" Test loading of an Extension with no makeExtension function. """
292-
_create_fake_extension(name='fake_a', has_factory_func=False)
293-
self.assertRaises(AttributeError, markdown.Markdown, extensions=['fake_a'])
292+
self.assertRaises(AttributeError, markdown.Markdown, extensions=['markdown.util'])
294293

295294
def testNonExtension(self):
296295
""" Test loading a non Extension object as an extension. """
297-
_create_fake_extension(name='fake_b', is_wrong_type=True)
298-
self.assertRaises(TypeError, markdown.Markdown, extensions=['fake_b'])
296+
self.assertRaises(TypeError, markdown.Markdown, extensions=[object])
299297

300298
def testBaseExtention(self):
301299
""" Test that the base Extension class will raise NotImplemented. """
302-
_create_fake_extension(name='fake_c')
303300
self.assertRaises(NotImplementedError,
304-
markdown.Markdown, extensions=['fake_c'])
301+
markdown.Markdown, extensions=[markdown.extensions.Extension()])
305302

306303
def testMdxExtention(self):
307304
""" Test that appending mdx_ raises a PendingDeprecationWarning. """
308-
_create_fake_extension(name='fake_d', use_old_style=True)
305+
_create_fake_extension(name='fake', use_old_style=True)
309306
self.assertRaises(PendingDeprecationWarning,
310-
markdown.Markdown, extensions=['fake_d'])
307+
markdown.Markdown, extensions=['fake'])
311308

312309
def testShortNameExtention(self):
313310
""" Test that using a short name raises a PendingDeprecationWarning. """
@@ -645,4 +642,4 @@ def testExtensonConfigOptionBadFormat(self):
645642
PLACE_MARKER= ~~~footnotes~~~
646643
"""
647644
self.create_config_file(config)
648-
self.assertRaises(yaml.YAMLError, parse_options, ['-c', self.tempfile])
645+
self.assertRaises(yaml.YAMLError, parse_options, ['-c', self.tempfile])

0 commit comments

Comments
 (0)