mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor: Catch ImportError for lib2to3 to support future python
This commit is contained in:
parent
a5036270c8
commit
3fee5a1ad8
@ -55,6 +55,7 @@ filterwarnings =
|
|||||||
all
|
all
|
||||||
ignore::DeprecationWarning:docutils.io
|
ignore::DeprecationWarning:docutils.io
|
||||||
ignore::DeprecationWarning:pyximport.pyximport
|
ignore::DeprecationWarning:pyximport.pyximport
|
||||||
|
ignore::PendingDeprecationWarning:sphinx.util.pycompat
|
||||||
markers =
|
markers =
|
||||||
sphinx
|
sphinx
|
||||||
apidoc
|
apidoc
|
||||||
|
@ -31,8 +31,15 @@ logger = logging.getLogger(__name__)
|
|||||||
# convert_with_2to3():
|
# convert_with_2to3():
|
||||||
# support for running 2to3 over config files
|
# support for running 2to3 over config files
|
||||||
def convert_with_2to3(filepath: str) -> str:
|
def convert_with_2to3(filepath: str) -> str:
|
||||||
|
try:
|
||||||
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
|
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
|
||||||
from lib2to3.pgen2.parse import ParseError
|
from lib2to3.pgen2.parse import ParseError
|
||||||
|
except ImportError:
|
||||||
|
# python 3.9.0a6+ emits PendingDeprecationWarning for lib2to3.
|
||||||
|
# Additionally, removal of the module is still discussed at PEP-594.
|
||||||
|
# To support future python, this catches ImportError for lib2to3.
|
||||||
|
raise SyntaxError
|
||||||
|
|
||||||
fixers = get_fixers_from_package('lib2to3.fixes')
|
fixers = get_fixers_from_package('lib2to3.fixes')
|
||||||
refactoring_tool = RefactoringTool(fixers)
|
refactoring_tool = RefactoringTool(fixers)
|
||||||
source = refactoring_tool._read_python_source(filepath)[0]
|
source = refactoring_tool._read_python_source(filepath)[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user