mirror of
https://github.com/apache/airflow.git
synced 2026-11-04 07:12:48 +00:00
Remove unused Sphinx snippet renderer (#75886)
This commit is contained in:
1 parent
5f337adeb1
commit
7e1a4504fc
1 file changed
-45
@@ -17,7 +17,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from contextlib import suppress
|
||||
from pathlib import Path
|
||||
|
||||
from sphinx_exts.provider_yaml_utils import load_package_data
|
||||
@@ -35,50 +34,6 @@ PROCESS_TIMEOUT = 15 * 60 * 2
|
||||
CONSOLE_WIDTH = 250
|
||||
|
||||
|
||||
def prepare_code_snippet(file_path: str, line_no: int, context_lines_count: int = 5) -> str:
|
||||
"""
|
||||
Prepares code snippet.
|
||||
|
||||
:param file_path: file path
|
||||
:param line_no: line number
|
||||
:param context_lines_count: number of lines of context.
|
||||
"""
|
||||
|
||||
def guess_lexer_for_filename(filename):
|
||||
from pygments.lexers import get_lexer_for_filename
|
||||
from pygments.util import ClassNotFound
|
||||
|
||||
try:
|
||||
lexer = get_lexer_for_filename(filename)
|
||||
except ClassNotFound:
|
||||
from pygments.lexers.special import TextLexer
|
||||
|
||||
lexer = TextLexer()
|
||||
return lexer
|
||||
|
||||
with open(file_path) as text_file:
|
||||
# Highlight code
|
||||
code = text_file.read()
|
||||
with suppress(ImportError):
|
||||
import pygments
|
||||
from pygments.formatters.terminal import TerminalFormatter
|
||||
|
||||
code = pygments.highlight(
|
||||
code=code, formatter=TerminalFormatter(), lexer=guess_lexer_for_filename(file_path)
|
||||
)
|
||||
|
||||
code_lines = code.splitlines()
|
||||
# Prepend line number
|
||||
code_lines = [f"{line_no:4} | {line}" for line_no, line in enumerate(code_lines, 1)]
|
||||
# # Cut out the snippet
|
||||
start_line_no = max(0, line_no - context_lines_count)
|
||||
end_line_no = line_no + context_lines_count
|
||||
code_lines = code_lines[start_line_no:end_line_no]
|
||||
# Join lines
|
||||
code = "\n".join(code_lines)
|
||||
return code
|
||||
|
||||
|
||||
def pretty_format_path(path: str, start: str) -> str:
|
||||
"""Formats path nicely."""
|
||||
relpath = os.path.relpath(path, start)
|
||||
|
||||
Reference in new issue
Block a user