Skip to content

Commit 4325416

Browse files
committed
resolve paths
in my case, i've started using symlinks a bit more often, and the current impl causes issues, we need to resolve the symlinked path too.
1 parent 05e5a94 commit 4325416

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

codeflash/code_utils/code_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def get_qualified_name(module_name: str, full_qualified_name: str) -> str:
173173

174174
def module_name_from_file_path(file_path: Path, project_root_path: Path, *, traverse_up: bool = False) -> str:
175175
try:
176-
relative_path = file_path.relative_to(project_root_path)
176+
relative_path = file_path.resolve().relative_to(project_root_path.resolve())
177177
return relative_path.with_suffix("").as_posix().replace("/", ".")
178178
except ValueError:
179179
if traverse_up:

codeflash/context/code_context_extractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def extract_code_markdown_context_from_files(
334334
helpers_of_fto.get(file_path, set()) | helpers_of_helpers.get(file_path, set())
335335
),
336336
)
337-
code_string_context = CodeString(code=code_context, file_path=file_path.relative_to(project_root_path))
337+
code_string_context = CodeString(code=code_context, file_path=file_path.resolve().relative_to(project_root_path.resolve()))
338338
code_context_markdown.code_strings.append(code_string_context)
339339
# Extract code from file paths containing helpers of helpers
340340
for file_path, helper_function_sources in helpers_of_helpers_no_overlap.items():
@@ -365,7 +365,7 @@ def extract_code_markdown_context_from_files(
365365
project_root=project_root_path,
366366
helper_functions=list(helpers_of_helpers_no_overlap.get(file_path, set())),
367367
)
368-
code_string_context = CodeString(code=code_context, file_path=file_path.relative_to(project_root_path))
368+
code_string_context = CodeString(code=code_context, file_path=file_path.resolve().relative_to(project_root_path.resolve()))
369369
code_context_markdown.code_strings.append(code_string_context)
370370
return code_context_markdown
371371

tests/test_code_context_extractor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ def get_system_details():
18271827
hashing_context = code_ctx.hashing_code_context
18281828
# The expected contexts
18291829
expected_read_write_context = f"""
1830-
```python:{main_file_path.relative_to(opt.args.project_root)}
1830+
```python:{main_file_path.resolve().relative_to(opt.args.project_root.resolve())}
18311831
import utility_module
18321832
18331833
class Calculator:
@@ -2096,7 +2096,7 @@ def select_precision(precision, fallback_precision):
20962096
else:
20972097
return DEFAULT_PRECISION
20982098
```
2099-
```python:{main_file_path.relative_to(opt.args.project_root)}
2099+
```python:{main_file_path.resolve().relative_to(opt.args.project_root.resolve())}
21002100
import utility_module
21012101
21022102
class Calculator:

0 commit comments

Comments
 (0)