Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors because of mix indentation #13274

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -652,25 +652,27 @@ def _parse_nodes(
def _get_indentation(text: str) -> Tuple[str, int, int]:
indent_char = None
minimum_chain = None
first_indent_char = None

# Check that text is at least 1 line long
text_split = text.splitlines()
if len(text_split) == 0:
raise ValueError("Text should be at least one line long.")

for line in text_split:
for line_id, line in enumerate(text_split):
stripped_line = line.lstrip()

if stripped_line:
# Get whether it's tabs or spaces
spaces_count = line.count(" ", 0, len(line) - len(stripped_line))
tabs_count = line.count("\t", 0, len(line) - len(stripped_line))

if not indent_char:
if spaces_count:
indent_char = " "
if tabs_count:
indent_char = "\t"
if spaces_count:
indent_char = " "
if tabs_count:
indent_char = "\t"

if line_id == 0:
first_indent_char = indent_char

# Detect mixed indentation.
if spaces_count > 0 and tabs_count > 0:
Expand All @@ -685,6 +687,7 @@ def _get_indentation(text: str) -> Tuple[str, int, int]:
char_count = line.count(
indent_char, 0, len(line) - len(stripped_line)
)
char_count = char_count * 4 if indent_char == "\t" else char_count
if minimum_chain is not None:
if char_count > 0:
minimum_chain = min(char_count, minimum_chain)
Expand All @@ -693,17 +696,16 @@ def _get_indentation(text: str) -> Tuple[str, int, int]:
minimum_chain = char_count

# Handle edge case
if indent_char is None:
indent_char = " "
indent_char = " "
if minimum_chain is None:
minimum_chain = 4

# Get the first indent count
first_line = text_split[0]
first_indent_count = 0
for char in first_line:
if char == indent_char:
first_indent_count += 1
if char == first_indent_char:
first_indent_count += 1 if first_indent_char == " " else 4
else:
break

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ license = "MIT"
maintainers = ["ryanpeach"]
name = "llama-index-packs-code-hierarchy"
readme = "README.md"
version = "0.1.5"
version = "0.1.6"

[tool.poetry.dependencies]
python = ">=3.8.1,<3.12"
Expand Down