Skip to content

Add a way for users to reuse external themes #476

Closed

Description

@d0ugal

This is a topic that has come up a number of times. There is really good discussion on #179 and #424.

It would be good to provide users with a way to use external themes more easily. Currently the only approach is to download the theme, set theme_dir to point to it and then build the docs.

In #424 we considered installing zip files from a remote URL. While this worked, it took us down the road of implementing out own packaging system. This isn't something we want to support in MkDocs - it quickly will run into issues if we ever have to take into account versioning or reproducible building - what happens if the theme updates and then somebody builds on a new machine with no copy of the old one? or maybe the theme is removed and then can't be accessed anymore? etc. etc.

So, that leaves me thinking only we really have two options worth considering. Listed here with some thoughts about each.

  • Stay as we are, but perhaps improve documentation for users that are manually installing themes.
    • Very simple to use and understand
    • Cumbersome for the user, they need to install and update manually and manage the theme for us.
  • Use Python packaging and PyPI to install and manage themes.
    • More features than we need - very robust packaging
    • Absolute overkill for just static files
    • Very complicated for theme authors and users (they need to learn Python tooling a bit)

Activity

  1. added this to the 1.0.0 milestone on Apr 24, 2015
  2. facelessuser commented on Apr 24, 2015

    @facelessuser
    Contributor

    What if a user could install a package with a specific entry_point so that mkdocs could view those packages as native. Those packages could use the theme option and mkdocs could resolve that theme name as if it were native. But you could also leave the theme_dir in place for those who wish to have it locally and or override parts of a global theme.

    The main reason I like this idea is mainly because I would like to have a theme global for multiple projects, and if I have project specific tweaks to the theme, I could override just the files I need to via theme_dir (and I would commit those changes to my project as they are project specific). If the whole theme was specific for the project, then I could just use theme_dir and include the theme with the project.

    I think that would satisfy me; I don't know about anyone else. This way, if I wanted to specify a version as a dependency for my project I could. This would work for tox etc. But mkdocs wouldn't have to manage versions. I guess it depends on how much you want mkdocs to manage themes. Or better put, should mkdocs also be a theme manager, or will you just make it easier to access themes and let the user manage his/her stuff with already available tools. This way you don't force anyone to use PyPI, but they could indirectly.

  3. waylan commented on Apr 27, 2015

    @waylan
    Contributor

    @facelessuser what you describe is almost exactly what Sphinx has implemented. An entry_point resolves to a dir and then that dir is the theme_dir. The weird think about this solution is that for an entry_point to work, it has to call Python code. Therefore, each theme has to have an __init__.py at its root which contains something like the following:

    import os
    theme_dir = os.path.dirname(os.path.abspath(__file__))

    The theme author then needs to create a setup.py file which defines the entry_point which points to path.to.theme:theme_dir. The setup script also needs to load all non-python package_data. While this is all easy enough for Python devs, it can feel out-of-place and perhaps be overwhelming to front end devs.

    It is relatively easy to implement. I don't think anyone is questioning that. But is it the right thing to do? I don't know.

  4. facelessuser commented on Apr 27, 2015

    @facelessuser
    Contributor

    The theme author then needs to create a setup.py file which defines the entry_point which points to path.to.theme:theme_dir. The setup script also needs to load all non-python package_data. While this is all easy enough for Python devs, it can feel out-of-place and perhaps be overwhelming to front end devs.

    Keep in mind, that this is meant to augment only the theme option, or access to internal themes. If a user installs a Python package variant, it would be accessible via theme; otherwise, you can download the theme directly somewhere and use theme_dir The idea is to allow things to stay relatively the same, but also get the added ability to use PyPI if desired.

    From what I read, mkdocs wants to split out themes to begin with into a separate repo. This could be available via PyPI just like mkdocs is. custom themes could still be downloaded as they are now and even override parts of the built-in themes just like it does now. But people could also make available themes via PyPI that could be accessed globally just like the built-in themes are if desired.

    Based on the two directions listed above, this kind of bridges the gap. Let people use the tools already in place to manage packages, but also allow the option for people install via the legacy way (just improve documentation). And if some one wants to build a separate theme manager on the side, let them.

    But is it the right thing to do? I don't know.

    I'm not sure what the right way to go is, but this is possibly a third option. Just thought I would add to the brainstorming.

  5. d0ugal commented on Apr 27, 2015

    @d0ugal
    ContributorAuthor

    But people could also make available themes via PyPI that could be accessed globally just like the built-in themes are if desired.

    This is the part that I like about using PyPI the most. It might be a bit painful for theme authors, but it optimises the solution for end users and it will be really simple for them.

  6. d0ugal commented on May 8, 2015

    @d0ugal
    ContributorAuthor

    From the point of view of ReadTheDocs, Python packaging would work very well I'm not sure they would be fans of other approaches to download stuff.

  7. modified the milestones: 0.15.0, 1.0.0 on Jun 27, 2015
  8. d0ugal commented on Jun 27, 2015

    @d0ugal
    ContributorAuthor

    This just landed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions