Skip to content

Commit

Permalink
MAINT: improve robustness of translator (#104)
Browse files Browse the repository at this point in the history
* improve robustness of translator

* pin sphinx to v3

* fix environment from sample project

* fix to python=3.7
  • Loading branch information
mmcky committed May 26, 2021
1 parent b0ad3da commit 22f973c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
auto-update-conda: true
auto-activate-base: true
miniconda-version: 'latest'
python-version: 3.8
python-version: 3.7
environment-file: lecture-python-programming/environment.yml
activate-environment: qe-lectures
- name: Install sphinx-tomyst
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -49,7 +49,7 @@
platforms="any",
packages=find_packages(),
include_package_data=True,
install_requires=["docutils", "sphinx"],
install_requires=["docutils", "sphinx>=3.0,<4.0"],
extras_require={
"code_style": ["flake8<3.8.0,>=3.7.0", "black", "pre-commit==1.17.0"],
"testing": [
Expand Down
17 changes: 14 additions & 3 deletions sphinx_tomyst/writers/translator.py
Expand Up @@ -9,6 +9,8 @@

from __future__ import unicode_literals
import re
from pathlib import Path
import os
from docutils import nodes

from sphinx.util import logging
Expand Down Expand Up @@ -1332,7 +1334,9 @@ def visit_pending_xref(self, node):
targetname = node["reftarget"]
if linktext == targetname:
# Update linktext to be the title of the target document
linktext = self.builder.env.longtitles[targetname].astext()
directory = os.path.dirname(Path(node["refdoc"]))
target = os.path.join(directory, targetname)
linktext = self.builder.env.longtitles[target].astext()
content = "{} <{}>".format(linktext, target)
else:
# ref
Expand Down Expand Up @@ -1442,9 +1446,16 @@ def depart_reference(self, node):
refid = refid.replace(")", "%29")
# markdown target
refuri = "#{}".format(refid)
# error
# warning
else:
self.error("Invalid reference")
docname = self.builder.current_docname
line = node.line
msg = """
[{}:{}] contains a reference role that is not converted.
""".format(
docname, line
).strip()
logger.warning(msg)
refuri = ""

# TODO: review if both %28 replacements necessary in this function?
Expand Down

0 comments on commit 22f973c

Please sign in to comment.