Account for removal of `docutils.utils.roman` (#13131)

This commit is contained in:
Adam Turner 2024-11-13 21:41:26 +00:00 committed by GitHub
parent eb337fec0a
commit 2dfb0b907d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 8 deletions

View File

@ -70,6 +70,7 @@ dependencies = [
"alabaster>=0.7.14", "alabaster>=0.7.14",
"imagesize>=1.3", "imagesize>=1.3",
"requests>=2.30.0", "requests>=2.30.0",
"roman-numerals-py>=1.0.0",
"packaging>=23.0", "packaging>=23.0",
"colorama>=0.4.6; sys_platform == 'win32'", "colorama>=0.4.6; sys_platform == 'win32'",
] ]

View File

@ -13,6 +13,7 @@ from pathlib import Path
from typing import TYPE_CHECKING, Any, ClassVar, cast from typing import TYPE_CHECKING, Any, ClassVar, cast
from docutils import nodes, writers from docutils import nodes, writers
from roman_numerals import RomanNumeral
from sphinx import addnodes, highlighting from sphinx import addnodes, highlighting
from sphinx.errors import SphinxError from sphinx.errors import SphinxError
@ -24,12 +25,6 @@ from sphinx.util.nodes import clean_astext, get_prev_node
from sphinx.util.template import LaTeXRenderer from sphinx.util.template import LaTeXRenderer
from sphinx.util.texescape import tex_replace_map from sphinx.util.texescape import tex_replace_map
try:
from docutils.utils.roman import toRoman
except ImportError:
# In Debian/Ubuntu, roman package is provided as roman, not as docutils.utils.roman
from roman import toRoman # type: ignore[no-redef, import-not-found]
if TYPE_CHECKING: if TYPE_CHECKING:
from docutils.nodes import Element, Node, Text from docutils.nodes import Element, Node, Text
@ -1421,8 +1416,9 @@ class LaTeXTranslator(SphinxTranslator):
else: else:
return get_nested_level(node.parent) return get_nested_level(node.parent)
enum = 'enum%s' % toRoman(get_nested_level(node)).lower() nested_level = get_nested_level(node)
enumnext = 'enum%s' % toRoman(get_nested_level(node) + 1).lower() enum = f'enum{RomanNumeral(nested_level).to_lowercase()}'
enumnext = f'enum{RomanNumeral(nested_level + 1).to_lowercase()}'
style = ENUMERATE_LIST_STYLE.get(get_enumtype(node)) style = ENUMERATE_LIST_STYLE.get(get_enumtype(node))
prefix = node.get('prefix', '') prefix = node.get('prefix', '')
suffix = node.get('suffix', '.') suffix = node.get('suffix', '.')