Skip to content

Commit

Permalink
Get the theme location via entry_points
Browse files Browse the repository at this point in the history
  • Loading branch information
d0ugal committed May 18, 2015
1 parent 9d95d7d commit b3693b2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mkdocs/config/config_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def post_validation(self, config, key_name):

package_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..'))
theme_dir = [os.path.join(package_dir, 'themes', config['theme']), ]
theme_dir = [utils.get_themes()[config['theme']], ]
config['mkdocs_templates'] = os.path.join(package_dir, 'templates')

if config['theme_dir'] is not None:
Expand Down
4 changes: 2 additions & 2 deletions mkdocs/tests/config/config_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_theme(self):
dict(), # default theme
{"theme": "readthedocs"}, # builtin theme
{"theme_dir": mytheme}, # custom only
{"theme": "cosmo", "theme_dir": custom}, # builtin and custom
{"theme": "readthedocs", "theme_dir": custom}, # builtin and custom
]

abs_path = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -113,7 +113,7 @@ def test_theme(self):
[os.path.join(theme_dir, 'mkdocs'), search_asset_dir],
[os.path.join(theme_dir, 'readthedocs'), search_asset_dir],
[mytheme, search_asset_dir],
[custom, os.path.join(theme_dir, 'cosmo'), search_asset_dir],
[custom, os.path.join(theme_dir, 'readthedocs'), search_asset_dir],
)

for config_contents, result in six.moves.zip(configs, results):
Expand Down
4 changes: 1 addition & 3 deletions mkdocs/tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ def test_get_themes(self):

self.assertEqual(
sorted(utils.get_theme_names()),
sorted(['flatly', 'cerulean', 'slate', 'bootstrap', 'yeti',
'spacelab', 'united', 'readable', 'simplex', 'mkdocs',
'cosmo', 'journal', 'cyborg', 'readthedocs', 'amelia']))
sorted(['mkdocs', 'readthedocs']))

def test_nest_paths(self):

Expand Down
3 changes: 2 additions & 1 deletion mkdocs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,10 @@ def get_themes():
themes = {}

for theme in iter_entry_points(group='mkdocs.themes', name=None):
name = theme.name
theme = theme.load()
location = os.path.dirname(theme.__file__)
themes[theme.name] = location
themes[name] = location

return themes

Expand Down

0 comments on commit b3693b2

Please sign in to comment.