Skip to content

Commit eb0b064

Browse files
Socratic Developerclaude
andcommitted
style: Apply black formatting fixes
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 8647b22 commit eb0b064

8 files changed

Lines changed: 58 additions & 73 deletions

File tree

src/socratic_docs/code_extractor.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def is_markdown_format(content: str) -> bool:
5757
return True
5858

5959
# Check for multiple markdown headers
60-
header_count = sum(1 for line in lines if re.match(CodeExtractor.MARKDOWN_HEADER_PATTERN, line))
60+
header_count = sum(
61+
1 for line in lines if re.match(CodeExtractor.MARKDOWN_HEADER_PATTERN, line)
62+
)
6163
if header_count >= 2:
6264
logger.debug(f"Detected {header_count} markdown headers (##)")
6365
return True
@@ -98,11 +100,7 @@ def extract_from_markdown(content: str) -> str:
98100
logger.info("Extracting Python code from markdown format")
99101

100102
# Find all code fences with python/py language
101-
code_blocks = re.findall(
102-
CodeExtractor.CODE_FENCE_PATTERN,
103-
content,
104-
re.DOTALL
105-
)
103+
code_blocks = re.findall(CodeExtractor.CODE_FENCE_PATTERN, content, re.DOTALL)
106104

107105
if code_blocks:
108106
logger.info(f"Found {len(code_blocks)} code block(s) in markdown")
@@ -238,13 +236,17 @@ def get_code_statistics(content: str) -> dict:
238236
tree = ast.parse(content)
239237
classes = [node for node in ast.walk(tree) if isinstance(node, ast.ClassDef)]
240238
functions = [node for node in ast.walk(tree) if isinstance(node, ast.FunctionDef)]
241-
imports = [node for node in ast.walk(tree) if isinstance(node, (ast.Import, ast.ImportFrom))]
242-
243-
stats.update({
244-
"class_count": len(classes),
245-
"function_count": len(functions),
246-
"import_count": len(imports),
247-
})
239+
imports = [
240+
node for node in ast.walk(tree) if isinstance(node, (ast.Import, ast.ImportFrom))
241+
]
242+
243+
stats.update(
244+
{
245+
"class_count": len(classes),
246+
"function_count": len(functions),
247+
"import_count": len(imports),
248+
}
249+
)
248250
except Exception as e:
249251
logger.warning(f"Could not parse AST for statistics: {e}")
250252

src/socratic_docs/extractors/base.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,14 @@ def extract_from_markdown(self, content: str) -> ExtractionResult:
148148
ExtractionResult with extracted code and metadata
149149
"""
150150
if not content:
151-
return ExtractionResult(extracted_code="", is_valid=False, validation_error="Empty content")
151+
return ExtractionResult(
152+
extracted_code="", is_valid=False, validation_error="Empty content"
153+
)
152154

153155
# Check if this looks like markdown
154156
if not self.is_markdown_format(content):
155157
self.logger.debug("Content doesn't appear to be markdown, returning as-is")
156-
return ExtractionResult(
157-
extracted_code=content,
158-
is_valid=True,
159-
was_markdown=False
160-
)
158+
return ExtractionResult(extracted_code=content, is_valid=True, was_markdown=False)
161159

162160
self.logger.info(f"Extracting {self.language} code from markdown format")
163161

@@ -185,7 +183,7 @@ def extract_from_markdown(self, content: str) -> ExtractionResult:
185183
is_valid=validation.is_valid,
186184
validation_error=validation.error_message,
187185
was_markdown=True,
188-
code_blocks_found=len(code_blocks)
186+
code_blocks_found=len(code_blocks),
189187
)
190188

191189
# If no code fences found but content looks like markdown,
@@ -219,7 +217,7 @@ def extract_from_markdown(self, content: str) -> ExtractionResult:
219217
is_valid=validation.is_valid,
220218
validation_error=validation.error_message,
221219
was_markdown=True,
222-
code_blocks_found=0
220+
code_blocks_found=0,
223221
)
224222

225223
# Fallback: return original if extraction failed
@@ -229,7 +227,7 @@ def extract_from_markdown(self, content: str) -> ExtractionResult:
229227
is_valid=False,
230228
validation_error="Could not extract valid code from markdown",
231229
was_markdown=True,
232-
code_blocks_found=0
230+
code_blocks_found=0,
233231
)
234232

235233
def extract_and_validate(self, content: str) -> ExtractionResult:
@@ -259,7 +257,7 @@ def extract_and_validate(self, content: str) -> ExtractionResult:
259257
is_valid=validation.is_valid,
260258
validation_error=validation.error_message,
261259
was_markdown=extracted.was_markdown,
262-
code_blocks_found=extracted.code_blocks_found
260+
code_blocks_found=extracted.code_blocks_found,
263261
)
264262

265263
def get_code_statistics(self, code: str) -> dict:

src/socratic_docs/extractors/generic_extractor.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,12 @@ def validate_syntax(self, code: str) -> ValidationResult:
5858
ValidationResult indicating code is valid (with warning)
5959
"""
6060
if not code or not code.strip():
61-
return ValidationResult(
62-
is_valid=False,
63-
error_message="Empty code"
64-
)
61+
return ValidationResult(is_valid=False, error_message="Empty code")
6562

6663
# No validation available - assume code is valid but warn user
6764
warnings = [f"No syntax validation available for {self.language}"]
6865

69-
return ValidationResult(
70-
is_valid=True,
71-
warnings=warnings
72-
)
66+
return ValidationResult(is_valid=True, warnings=warnings)
7367

7468
def get_import_statements(self, code: str) -> List[str]:
7569
"""
@@ -87,21 +81,21 @@ def get_import_statements(self, code: str) -> List[str]:
8781
imports = []
8882

8983
# Simple pattern matching for common import styles
90-
for line in code.split('\n'):
84+
for line in code.split("\n"):
9185
line = line.strip()
9286

9387
# Match various import styles
94-
if line.startswith('import '): # import x (Java, Go, etc.)
88+
if line.startswith("import "): # import x (Java, Go, etc.)
9589
imports.append(line)
96-
elif line.startswith('require('): # require('x') (Node.js)
90+
elif line.startswith("require("): # require('x') (Node.js)
9791
imports.append(line)
98-
elif line.startswith('use '): # use x (Perl, Rust)
92+
elif line.startswith("use "): # use x (Perl, Rust)
9993
imports.append(line)
100-
elif line.startswith('use std::'): # use std::x (Rust)
94+
elif line.startswith("use std::"): # use std::x (Rust)
10195
imports.append(line)
102-
elif line.startswith('from '): # from x import y (Python)
96+
elif line.startswith("from "): # from x import y (Python)
10397
imports.append(line)
104-
elif line.startswith('#include '): # #include (C/C++)
98+
elif line.startswith("#include "): # #include (C/C++)
10599
imports.append(line)
106100

107101
return imports

src/socratic_docs/extractors/python_extractor.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ def validate_syntax(self, code: str) -> ValidationResult:
4242
ValidationResult with validation status and error details
4343
"""
4444
if not code or not code.strip():
45-
return ValidationResult(
46-
is_valid=False,
47-
error_message="Empty code"
48-
)
45+
return ValidationResult(is_valid=False, error_message="Empty code")
4946

5047
try:
5148
ast.parse(code)
@@ -57,27 +54,17 @@ def validate_syntax(self, code: str) -> ValidationResult:
5754
if e.text:
5855
error_msg += f"\n {e.text.strip()}"
5956
logger.error(f"Python code validation failed: {error_msg}")
60-
return ValidationResult(
61-
is_valid=False,
62-
error_message=error_msg,
63-
line_number=e.lineno
64-
)
57+
return ValidationResult(is_valid=False, error_message=error_msg, line_number=e.lineno)
6558

6659
except ValueError as e:
6760
error_msg = f"ValueError: {str(e)}"
6861
logger.error(f"Python code validation failed: {error_msg}")
69-
return ValidationResult(
70-
is_valid=False,
71-
error_message=error_msg
72-
)
62+
return ValidationResult(is_valid=False, error_message=error_msg)
7363

7464
except Exception as e:
7565
error_msg = f"{type(e).__name__}: {str(e)}"
7666
logger.error(f"Unexpected error during Python validation: {error_msg}")
77-
return ValidationResult(
78-
is_valid=False,
79-
error_message=error_msg
80-
)
67+
return ValidationResult(is_valid=False, error_message=error_msg)
8168

8269
def get_import_statements(self, code: str) -> List[str]:
8370
"""
@@ -99,13 +86,13 @@ def get_import_statements(self, code: str) -> List[str]:
9986
if isinstance(node, ast.Import):
10087
# import x, y, z
10188
for alias in node.names:
102-
module_name = alias.name.split('.')[0]
89+
module_name = alias.name.split(".")[0]
10390
imports.append(module_name)
10491

10592
elif isinstance(node, ast.ImportFrom):
10693
# from x import y
10794
if node.module:
108-
module_name = node.module.split('.')[0]
95+
module_name = node.module.split(".")[0]
10996
imports.append(module_name)
11097

11198
# Deduplicate and sort
@@ -135,11 +122,13 @@ def get_code_statistics(self, code: str) -> dict:
135122
functions = [node for node in ast.walk(tree) if isinstance(node, ast.FunctionDef)]
136123
imports = self.get_import_statements(code)
137124

138-
stats.update({
139-
"class_count": len(classes),
140-
"function_count": len(functions),
141-
"import_count": len(imports),
142-
})
125+
stats.update(
126+
{
127+
"class_count": len(classes),
128+
"function_count": len(functions),
129+
"import_count": len(imports),
130+
}
131+
)
143132

144133
except Exception as e:
145134
logger.warning(f"Could not parse AST for statistics: {e}")

src/socratic_docs/extractors/registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def auto_register_extractors() -> None:
220220
supports_ast=True,
221221
supports_linting=True,
222222
available=True,
223-
description="Python code extraction and validation using ast module"
223+
description="Python code extraction and validation using ast module",
224224
)
225225
)
226226
logger.info("Registered Python extractor")
@@ -244,7 +244,7 @@ def auto_register_extractors() -> None:
244244
available=True,
245245
description="JavaScript code extraction using esprima parser",
246246
requires_external_tool=False,
247-
dependencies=["esprima"]
247+
dependencies=["esprima"],
248248
)
249249
)
250250
logger.info("Registered JavaScript extractor")
@@ -263,7 +263,7 @@ def auto_register_extractors() -> None:
263263
available=False,
264264
description="JavaScript extraction (requires: pip install esprima)",
265265
requires_external_tool=False,
266-
dependencies=["esprima"]
266+
dependencies=["esprima"],
267267
)
268268
)
269269
logger.debug("JavaScript extractor not available (esprima not installed)")

src/socratic_docs/git_initializer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ def get_repository_status(project_root: Path) -> Dict[str, Any]:
409409
timeout=5,
410410
text=True,
411411
)
412-
remote_lines = [line.split()[0] for line in result.stdout.strip().split("\n") if line]
412+
remote_lines = [
413+
line.split()[0] for line in result.stdout.strip().split("\n") if line
414+
]
413415
status["remotes"] = list(set(remote_lines)) # Remove duplicates
414416
except subprocess.CalledProcessError:
415417
pass

src/socratic_docs/multi_file_splitter.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _split_python(self) -> Dict[str, str]:
7777
"- Review the content in `main.py`\n"
7878
"- Extract the actual Python code from the markdown\n"
7979
"- Re-save as proper Python modules\n"
80-
)
80+
),
8181
}
8282

8383
# Not markdown - regular syntax error
@@ -469,19 +469,15 @@ def create_structure(
469469
complete_structure["README.md"] = f"# {project_name}\n\nProject description.\n"
470470

471471
if "main.py" not in complete_structure and "src/__init__.py" in complete_structure:
472-
complete_structure[
473-
"main.py"
474-
] = '''"""Entry point"""
472+
complete_structure["main.py"] = '''"""Entry point"""
475473
476474
if __name__ == "__main__":
477475
print("Starting application...")
478476
'''
479477

480478
# Add .gitignore if not present
481479
if ".gitignore" not in complete_structure:
482-
complete_structure[
483-
".gitignore"
484-
] = """# Python
480+
complete_structure[".gitignore"] = """# Python
485481
__pycache__/
486482
*.py[cod]
487483
*$py.class

tests/test_module_imports.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
Basic import tests for module verification.
33
"""
44

5+
56
def test_module_import():
67
"""Test that the module can be imported."""
78
import socratic_docs
9+
810
assert socratic_docs is not None
911

12+
1013
def test_main_exports():
1114
"""Test that main exports are available."""
1215
try:
1316
from socratic_docs import DocumentationGenerator
17+
1418
assert DocumentationGenerator is not None
1519
except ImportError:
1620
# Optional - some modules might not export the main class

0 commit comments

Comments
 (0)