Skip to content

Commit 0628eb4

Browse files
committed
update CI to test windows and Macos
1 parent 3bb13a1 commit 0628eb4

File tree

3 files changed

+55
-18
lines changed

3 files changed

+55
-18
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: true
1414
matrix:
15-
os: [ubuntu-latest, macos-latest]
15+
os: [ubuntu-latest, macos-latest, windows-latest]
1616
python-version: ["3.10", "3.11", "3.12", "3.13"]
1717

1818
steps:

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from setuptools import find_packages, setup
21
from pathlib import Path
32

3+
from setuptools import find_packages, setup
4+
45
this_directory = Path(__file__).parent
56
long_description = (this_directory / "README.md").read_text(encoding="utf-8")
67

src/gitingest/query_ingestion.py

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
""" Functions to ingest and analyze a codebase directory or single file. """
22

3-
from fnmatch import fnmatch
4-
from pathlib import Path
5-
from typing import Any
63
import locale
74
import os
85
import platform
6+
from fnmatch import fnmatch
7+
from pathlib import Path
8+
from typing import Any
99

1010
import tiktoken
1111

@@ -20,25 +20,61 @@
2020
from gitingest.query_parser import ParsedQuery
2121

2222
try:
23-
locale.setlocale(locale.LC_ALL, '')
23+
locale.setlocale(locale.LC_ALL, "")
2424
except locale.Error:
25-
locale.setlocale(locale.LC_ALL, 'C')
25+
locale.setlocale(locale.LC_ALL, "C")
26+
2627

2728
def _normalize_path(path: Path) -> Path:
28-
"""Normalize path for cross-platform compatibility."""
29+
"""
30+
Normalize path for cross-platform compatibility.
31+
32+
Parameters
33+
----------
34+
path : Path
35+
The Path object to normalize.
36+
37+
Returns
38+
-------
39+
Path
40+
The normalized path with platform-specific separators and resolved components.
41+
"""
2942
return Path(os.path.normpath(str(path)))
3043

44+
3145
def _normalize_path_str(path: str | Path) -> str:
32-
"""Convert path to string with forward slashes for consistent output."""
33-
return str(path).replace(os.sep, '/')
46+
"""
47+
Convert path to string with forward slashes for consistent output.
48+
49+
Parameters
50+
----------
51+
path : str | Path
52+
The path to convert, can be string or Path object.
53+
54+
Returns
55+
-------
56+
str
57+
The normalized path string with forward slashes as separators.
58+
"""
59+
return str(path).replace(os.sep, "/")
60+
3461

3562
def _get_encoding_list() -> list[str]:
36-
"""Get list of encodings to try, prioritized for the current platform."""
37-
encodings = ['utf-8', 'utf-8-sig']
38-
if platform.system() == 'Windows':
39-
encodings.extend(['cp1252', 'iso-8859-1'])
63+
"""
64+
Get list of encodings to try, prioritized for the current platform.
65+
66+
Returns
67+
-------
68+
list[str]
69+
List of encoding names to try in priority order, starting with the
70+
platform's default encoding followed by common fallback encodings.
71+
"""
72+
encodings = ["utf-8", "utf-8-sig"]
73+
if platform.system() == "Windows":
74+
encodings.extend(["cp1252", "iso-8859-1"])
4075
return encodings + [locale.getpreferredencoding()]
4176

77+
4278
def _should_include(path: Path, base_path: Path, include_patterns: set[str]) -> bool:
4379
"""
4480
Determine if the given file or directory path matches any of the include patterns.
@@ -129,13 +165,13 @@ def _is_safe_symlink(symlink_path: Path, base_path: Path) -> bool:
129165
`True` if the symlink points within the base directory, `False` otherwise.
130166
"""
131167
try:
132-
if platform.system() == 'Windows':
168+
if platform.system() == "Windows":
133169
if not os.path.islink(str(symlink_path)):
134170
return False
135-
171+
136172
target_path = _normalize_path(symlink_path.resolve())
137173
base_resolved = _normalize_path(base_path.resolve())
138-
174+
139175
return base_resolved in target_path.parents or target_path == base_resolved
140176
except (OSError, ValueError):
141177
# If there's any error resolving the paths, consider it unsafe
@@ -201,7 +237,7 @@ def _read_file_content(file_path: Path) -> str:
201237
continue
202238
except OSError as e:
203239
return f"Error reading file: {e}"
204-
240+
205241
return "Error: Unable to decode file with available encodings"
206242

207243
except (OSError, InvalidNotebookError) as e:

0 commit comments

Comments
 (0)