readthedocs / sphinx-notfound-page

Create a custom 404 page with absolute URLs hardcoded
https://sphinx-notfound-page.readthedocs.io/
MIT License
49 stars 32 forks source link

Toctree links always use default language and version #25

Closed acozine closed 5 years ago

acozine commented 5 years ago

The notfound_default_language and notfound_default_version settings are not getting picked up everywhere when the 404 page gets built. When I build a custom 404 page with:

notfound_default_language = "foo"
notfound_default_version = "1.0"
notfound_no_urls_prefix = False

the stylesheets load correctly for pages at any level of the filetree (hooray!). However, the links in the left navigation still use /en/latest. For example:

<a class="reference internal" href="/en/latest/installation_guide/index.html">Installation Guide</a>

So if you click on any link from the TOC on the custom 404 page, you get another 404.

I think this is related to #14 and possibly also to #9. I'll see if I can figure out more details.

humitos commented 5 years ago

@acozine what version are you using? I think that 0.3 does not have this problem. Can you confirm please?

acozine commented 5 years ago

@humitos:

[alicia@tooticky]~/git_repos/ansible$ pip show sphinx-notfound-page
Name: sphinx-notfound-page
Version: 0.3
Summary: Sphinx extension to build a 404 page with absolute URLs
Home-page: https://github.com/rtfd/sphinx-notfound-page
humitos commented 5 years ago

I can't reproduce your issue.

I will need you to share a project where this is failing and the steps you are following to reproduce it on my own.

acozine commented 5 years ago

Hm. Maybe it's to do with our config, or the version of Sphinx we're using? Here are the steps to reproduce:

  1. Clone https://github.com/acozine/ansible
  2. Checkout the custom-404 branch
  3. Run MODULES=none make webdocs
  4. Look at the source for docs/docsite/_build/html/404.html.
acozine commented 5 years ago

You can also look at the 404 content on our test site - see http://docs.testing.ansible.com/ansible/2.9/dev_guide/index2.html.

humitos commented 5 years ago

This is definitely a bug.

The problem is at this chunk

https://github.com/rtfd/sphinx-notfound-page/blob/4ec09ad5609fd435730cf457c84c6018c9a6b955/notfound/extension.py#L110-L114

Instead of using app.config.language and READTHEDOCS_VERSION environment variable it should use the configs from this extension.

Thanks for your report. I will try to fix it soon and make a new release.

acozine commented 5 years ago

Thanks @humitos for the confirmation and for the PR to fix the issue!

acozine commented 5 years ago

@humitos thanks for merging those PRs! Unfortunately I'm still seeing this issue after reinstalling sphinx-notfound-page just now, using the command pip install --user git+git://github.com/rtfd/sphinx-notfound-page@master. When I do pip show sphinx-notfound-page I get Version: 0.3.dev0. Is this running the tip of the master branch? Do I need to wait until you release 0.4?

humitos commented 5 years ago

@acozine try running,

pip install --force-reinstall --user git+git://github.com/rtfd/sphinx-notfound-page@master

and let me know.

If that does not work, uninstall it first, with pip uninstall sphinx-notfound-page.

humitos commented 5 years ago

With the --force-reinstall and following the steps you mentioned from https://github.com/rtfd/sphinx-notfound-page/issues/25#issuecomment-497095195 I can see the proper links generated. Example

<li class="toctree-l1"><a class="reference internal" href="/ansible/2.9/reference_appendices/faq.html">Frequently Asked Questions</a></li>

Let me know if anything.

acozine commented 5 years ago

I believe you, but I can't make it work on my laptop. What am I doing wrong? Here's what I tried:

Fresh install of the module:

[alicia@tooticky]~/git_repos/ansible$ pip uninstall sphinx-notfound-page
Uninstalling sphinx-notfound-page-0.3.dev0:
  Would remove:
    /Users/alicia/Library/Python/3.7/lib/python/site-packages/common/*
    /Users/alicia/Library/Python/3.7/lib/python/site-packages/notfound/*
    /Users/alicia/Library/Python/3.7/lib/python/site-packages/sphinx_notfound_page-0.3.dev0.dist-info/*
Proceed (y/n)? y
  Successfully uninstalled sphinx-notfound-page-0.3.dev0
[alicia@tooticky]~/git_repos/ansible$ pip install --user git+git://github.com/rtfd/sphinx-notfound-page@master
Collecting git+git://github.com/rtfd/sphinx-notfound-page@master
  Cloning git://github.com/rtfd/sphinx-notfound-page (to revision master) to /private/var/folders/0m/p_lcv0p56rbdx01gjg2yst_h0000gn/T/pip-req-build-5tfwzuy6
Requirement already satisfied: sphinx in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx-notfound-page==0.3.dev0) (2.1.0)
Requirement already satisfied: docutils>=0.12 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (0.14)
Requirement already satisfied: sphinxcontrib-applehelp in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (1.0.1)
Requirement already satisfied: Pygments>=2.0 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (2.4.2)
Requirement already satisfied: snowballstemmer>=1.1 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (1.2.1)
Requirement already satisfied: requests>=2.5.0 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (2.22.0)
Requirement already satisfied: setuptools in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (41.0.1)
Requirement already satisfied: imagesize in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (1.1.0)
Requirement already satisfied: sphinxcontrib-qthelp in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (1.0.2)
Requirement already satisfied: packaging in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (19.0)
Requirement already satisfied: sphinxcontrib-devhelp in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (1.0.1)
Requirement already satisfied: sphinxcontrib-htmlhelp in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (1.0.2)
Requirement already satisfied: Jinja2>=2.3 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (2.10.1)
Requirement already satisfied: sphinxcontrib-jsmath in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (1.0.1)
Requirement already satisfied: alabaster<0.8,>=0.7 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (0.7.12)
Requirement already satisfied: sphinxcontrib-serializinghtml in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (1.1.3)
Requirement already satisfied: babel!=2.0,>=1.3 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from sphinx->sphinx-notfound-page==0.3.dev0) (2.7.0)
Requirement already satisfied: idna<2.9,>=2.5 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from requests>=2.5.0->sphinx->sphinx-notfound-page==0.3.dev0) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from requests>=2.5.0->sphinx->sphinx-notfound-page==0.3.dev0) (2019.3.9)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from requests>=2.5.0->sphinx->sphinx-notfound-page==0.3.dev0) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from requests>=2.5.0->sphinx->sphinx-notfound-page==0.3.dev0) (1.25.3)
Requirement already satisfied: six in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from packaging->sphinx->sphinx-notfound-page==0.3.dev0) (1.12.0)
Requirement already satisfied: pyparsing>=2.0.2 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from packaging->sphinx->sphinx-notfound-page==0.3.dev0) (2.4.0)
Requirement already satisfied: MarkupSafe>=0.23 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from Jinja2>=2.3->sphinx->sphinx-notfound-page==0.3.dev0) (1.1.1)
Requirement already satisfied: pytz>=2015.7 in /Users/alicia/Library/Python/3.7/lib/python/site-packages (from babel!=2.0,>=1.3->sphinx->sphinx-notfound-page==0.3.dev0) (2019.1)
Building wheels for collected packages: sphinx-notfound-page
  Building wheel for sphinx-notfound-page (setup.py) ... done
  Stored in directory: /private/var/folders/0m/p_lcv0p56rbdx01gjg2yst_h0000gn/T/pip-ephem-wheel-cache-efrablc8/wheels/52/4c/96/b7a0f834425258967366a4223c3891b617e4add3a571bec2f5
Successfully built sphinx-notfound-page
Installing collected packages: sphinx-notfound-page
Successfully installed sphinx-notfound-page-0.3.dev0

Confirmed the _build directory is empty:

[alicia@tooticky]~/git_repos/ansible$ ls -la docs/docsite/_build/
ls: docs/docsite/_build/: No such file or directory

Fresh build:

[alicia@tooticky]~/git_repos/ansible$ MODULES=none make webdocs
(cd docs/docsite/; CPUS=12 /Library/Developer/CommandLineTools/usr/bin/make docs)
PYTHONPATH=../../lib ../bin/dump_config.py --template-file=../templates/config.rst.j2 --output-dir=rst/reference_appendices/ -d ../../lib/ansible/config/base.yml
mkdir -p rst/cli
PYTHONPATH=../../lib ../bin/generate_man.py --template-file=../templates/cli_rst.j2 --output-dir=rst/cli/ --output-format rst ../../lib/ansible/cli/*.py
PYTHONPATH=../../lib ../bin/dump_keywords.py --template-dir=../templates --output-dir=rst/reference_appendices/ -d ./keyword_desc.yml
PYTHONPATH=../../lib ../bin/plugin_formatter.py -t rst --template-dir=../templates --module-dir=../../lib/ansible/modules -o rst/modules/ -l none
Evaluating module files...
rendering: None
. . . 
. . . many lines omitted
. . . 
The HTML pages are in _build/html.

And yet I still see links with en/latest in them in docs/docsite/_build/html/404.html: <li class="toctree-l1"><a class="reference internal" href="/en/latest/reference_appendices/faq.html">Frequently Asked Questions</a></li>

Are you and I running different versions of Python? or Sphinx? Here are mine:

[alicia@tooticky]~/git_repos/ansible$ python --version
Python 3.7.3
[alicia@tooticky]~/git_repos/ansible$ pip show Sphinx
Name: Sphinx
Version: 2.1.0
Summary: Python documentation generator
Home-page: http://sphinx-doc.org/

I will keep trying - if you have ideas, please pass them along!

acozine commented 5 years ago

Update: Downgrading to Sphinx 1.x solved this problem. Thanks @humitos for all your help!

humitos commented 5 years ago

Thanks for reporting back!

Update: Downgrading to Sphinx 1.x solved this problem. Thanks @humitos for all your help!

This is weird. I'm running tests in Sphinx 2.x and they passed. I suppose it should be something else from your environment.

(I suspects that you mixed pip environment using --user and not using it and the packages ended installed in the system vs. per user or something like that).

I'm glad it worked for you, though! Feel free to open another issue if you have any other trouble.