Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround to include relative readme into docs directory #6

Merged
merged 4 commits into from
Jan 6, 2021

Conversation

abravalheri
Copy link
Contributor

The workaround is described in readthedocs/recommonmark#191

It is not perfect, but it does the job, and now readthedocs have something to show...

The workaround is described in
readthedocs/recommonmark#191

It is not perfect, but it does the job
Copy link
Member

@FlorianWilhelm FlorianWilhelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice workaround. Makes me think. On could also have a demo project for this extension. One could even have an RTD site for each demo project to showcase the default docs.

docs/conf.py Outdated
app.add_config_value('m2r_anonymous_references', False, 'env')
app.add_config_value('m2r_disable_inline_math', False, 'env')
app.add_directive('mdinclude', MdInclude)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these changes also need to be added to the template itself? Meaning AUTO_STRUCTIFY_CONF in extension.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add them to the template... it is a workaround and have some drawbacks... but they do allow usind mdinclude... which means that even files such as AUTHORS.md and CHANGELOG.md could be viable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a recent PR that if accepted would lift the need for a workaround...

The approach used by recommonmark's own documentation is to include a
symbolic link file inside the `docs` directory, instead of trying to do
a `include`.

References:
readthedocs/recommonmark#191
sphinx-doc/sphinx#701
sphinx-doc/sphinx#7739
Obs.: Unfortunately it is not possible to convert docs/license.rst into
markdown because the toctree directive needs a title and the original
file is a TXT without one. So both steps are needed: (a) define a title
and (b) use a special sphinx/reST directive (not available in
recommonmark) to directly include the contents of another file.
@abravalheri
Copy link
Contributor Author

Hi @FlorianWilhelm I changed the implementation of the workaround...
The approach used by recommonmark's own documentation is to include a symbolic link file inside the docs directory, instead of trying to do a include.

References:

I will try to also do this with the templates and generated project in another PR.

@FlorianWilhelm
Copy link
Member

Okay, this even looks much cleaner. The only thing I find a bit dangerous is the symlinks. Do they even work on Windows? In sphinx-doc/sphinx#701 they say it might be problematic. Once this is merged I need to check if the dsproject extension still works since it directly depends on this.

@abravalheri
Copy link
Contributor Author

They "work" on Windows, if the user have setup the environment correctly.
Git-for-windows have some help about that in: https://github.com/git-for-windows/git/wiki/Symbolic-Links#creating-symbolic-links

I was thinking about catching the exception and then re-raising something like this:

class SymlinkError(OSError):
    """\
    Impossible to create a symbolic link {{{link_path} => {original_file}}}.
    If you are using a non-POSIX operating system, please make sure that
    your user have the correct rights and that your system is corrctly
    configured.

    Please check the following references:
    http://github.com/git-for-windows/git/wiki/Symbolic-Links
    https://blogs.windows.com/windowsdeveloper/2016/12/02/ symlinks-windows-10/
    https://docs.microsoft.com/en-us/windows/win32/fileio/ creating-symbolic-links
    """
    def __init__(self, link_path, original_file, *args, **kwargs):
        msg = (self.__class__.__doc__ or "").format(original_file, link_path)
        super().__init__(msg, *args, **kwargs)

@FlorianWilhelm
Copy link
Member

I think this would help Windows users a lot. A lot of Windows users struggle to set Git up, let alone something more complicated. We already had several issues on Windows where PyScaffold couldn't even find Git although it was supposed to be installed. Windows is just a pain...
Nevertheless, I like your solution since it will work for the majority of users (which are Linux & MacOs anyway) without any trouble and it can work for Windows if everything is set up correctly.

@abravalheri
Copy link
Contributor Author

I suppose we could go for it. If the Windows users still have problems even trying the documentation from git-for-windows and Microsoft, they still have 2 options: WSL and sticking with plain old rst... It is not like not using markdown would compromise a python project in terms of functionality...

@abravalheri abravalheri merged commit 00ec7a0 into master Jan 6, 2021
@abravalheri abravalheri deleted the workaround branch January 6, 2021 15:57
abravalheri added a commit that referenced this pull request Jan 6, 2021
This follows the discussion in #6
@abravalheri abravalheri mentioned this pull request Jan 6, 2021
abravalheri added a commit that referenced this pull request Jan 6, 2021
This follows the discussion in #6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants