Skip to content

Commit 7a5c4ba

Browse files
Add Python 3.7 support by reverting inline generics and removing walrus usage
1 parent fe81de1 commit 7a5c4ba

18 files changed

+160
-159
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ubuntu-latest, macos-latest, windows-latest]
16-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
16+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1717

1818
steps:
1919
- uses: actions/checkout@v4

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ You can also replace `hub` with `ingest` in any GitHub URL to access the corespo
2828

2929
## 📚 Requirements
3030

31-
- Python 3.9+
31+
- Python 3.7+
3232

3333
## 📦 Installation
3434

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "gitingest"
33
version = "0.1.3"
44
description="CLI tool to analyze and create text dumps of codebases for LLMs"
55
readme = {file = "README.md", content-type = "text/markdown" }
6-
requires-python = ">= 3.9"
6+
requires-python = ">= 3.7"
77
dependencies = [
88
"click>=8.0.0",
99
"tiktoken",
@@ -16,6 +16,7 @@ classifiers=[
1616
"Development Status :: 3 - Alpha",
1717
"Intended Audience :: Developers",
1818
"License :: OSI Approved :: MIT License",
19+
"Programming Language :: Python :: 3.8",
1920
"Programming Language :: Python :: 3.9",
2021
"Programming Language :: Python :: 3.10",
2122
"Programming Language :: Python :: 3.11",

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"gitingest=gitingest.cli:main",
2222
],
2323
},
24-
python_requires=">=3.9",
24+
python_requires=">=3.7",
2525
author="Romain Courtois",
2626
author_email="[email protected]",
2727
description="CLI tool to analyze and create text dumps of codebases for LLMs",

src/gitingest/cli.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# pylint: disable=no-value-for-parameter
44

55
import asyncio
6-
from typing import Optional
6+
from typing import Optional, Tuple
77

88
import click
99

@@ -22,8 +22,8 @@ def main(
2222
source: str,
2323
output: Optional[str],
2424
max_size: int,
25-
exclude_pattern: tuple[str, ...],
26-
include_pattern: tuple[str, ...],
25+
exclude_pattern: Tuple[str, ...],
26+
include_pattern: Tuple[str, ...],
2727
branch: Optional[str],
2828
):
2929
"""
@@ -35,16 +35,16 @@ def main(
3535
----------
3636
source : str
3737
The source directory or repository to analyze.
38-
output : Optional[str]
38+
output : str, optional
3939
The path where the output file will be written. If not specified, the output will be written
4040
to a file named `<repo_name>.txt` in the current directory.
4141
max_size : int
4242
The maximum file size to process, in bytes. Files larger than this size will be ignored.
43-
exclude_pattern : tuple[str, ...]
44-
A tuple of patterns to exclude during the analysis. Files matching these patterns will be ignored.
45-
include_pattern : tuple[str, ...]
43+
exclude_pattern : Tuple[str, ...]
44+
A tuple of patterns to exclude during the analysis. Files matching these patterns will be ignored.
45+
include_pattern : Tuple[str, ...]
4646
A tuple of patterns to include during the analysis. Only files matching these patterns will be processed.
47-
branch : Optional[str]
47+
branch : str, optional
4848
The branch to clone (optional).
4949
"""
5050
# Main entry point for the CLI. This function is called when the CLI is run as a script.
@@ -55,8 +55,8 @@ async def _async_main(
5555
source: str,
5656
output: Optional[str],
5757
max_size: int,
58-
exclude_pattern: tuple[str, ...],
59-
include_pattern: tuple[str, ...],
58+
exclude_pattern: Tuple[str, ...],
59+
include_pattern: Tuple[str, ...],
6060
branch: Optional[str],
6161
) -> None:
6262
"""
@@ -69,16 +69,16 @@ async def _async_main(
6969
----------
7070
source : str
7171
The source directory or repository to analyze.
72-
output : Optional[str]
72+
output : str, optional
7373
The path where the output file will be written. If not specified, the output will be written
7474
to a file named `<repo_name>.txt` in the current directory.
7575
max_size : int
7676
The maximum file size to process, in bytes. Files larger than this size will be ignored.
77-
exclude_pattern : tuple[str, ...]
77+
exclude_pattern : Tuple[str, ...]
7878
A tuple of patterns to exclude during the analysis. Files matching these patterns will be ignored.
79-
include_pattern : tuple[str, ...]
79+
include_pattern : Tuple[str, ...]
8080
A tuple of patterns to include during the analysis. Only files matching these patterns will be processed.
81-
branch : Optional[str]
81+
branch : str, optional
8282
The branch to clone (optional).
8383
8484
Raises

src/gitingest/ignore_patterns.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
""" Default ignore patterns for Gitingest. """
22

3-
DEFAULT_IGNORE_PATTERNS: set[str] = {
3+
from typing import Set
4+
5+
DEFAULT_IGNORE_PATTERNS: Set[str] = {
46
# Python
57
"*.pyc",
68
"*.pyo",

src/gitingest/notebook_utils.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import warnings
55
from itertools import chain
66
from pathlib import Path
7-
from typing import Any, Optional
7+
from typing import Any, Dict, List, Optional
88

99
from gitingest.exceptions import InvalidNotebookError
1010

@@ -32,12 +32,13 @@ def process_notebook(file: Path, include_output: bool = True) -> str:
3232
"""
3333
try:
3434
with file.open(encoding="utf-8") as f:
35-
notebook: dict[str, Any] = json.load(f)
35+
notebook: Dict[str, Any] = json.load(f)
3636
except json.JSONDecodeError as e:
3737
raise InvalidNotebookError(f"Invalid JSON in notebook: {file}") from e
3838

3939
# Check if the notebook contains worksheets
40-
if worksheets := notebook.get("worksheets"):
40+
worksheets = notebook.get("worksheets")
41+
if worksheets:
4142
warnings.warn(
4243
"Worksheets are deprecated as of IPEP-17. Consider updating the notebook. "
4344
"(See: https://github.com/jupyter/nbformat and "
@@ -57,26 +58,27 @@ def process_notebook(file: Path, include_output: bool = True) -> str:
5758
result = ["# Jupyter notebook converted to Python script."]
5859

5960
for cell in cells:
60-
if cell_str := _process_cell(cell, include_output=include_output):
61+
cell_str = _process_cell(cell, include_output=include_output)
62+
if cell_str:
6163
result.append(cell_str)
6264

6365
return "\n\n".join(result) + "\n"
6466

6567

66-
def _process_cell(cell: dict[str, Any], include_output: bool) -> Optional[str]:
68+
def _process_cell(cell: Dict[str, Any], include_output: bool) -> Optional[str]:
6769
"""
6870
Process a Jupyter notebook cell and return the cell content as a string.
6971
7072
Parameters
7173
----------
72-
cell : dict[str, Any]
74+
cell : Dict[str, Any]
7375
The cell dictionary from a Jupyter notebook.
7476
include_output : bool
7577
Whether to include cell outputs in the generated script
7678
7779
Returns
7880
-------
79-
Optional[str]
81+
str, optional
8082
The cell content as a string, or None if the cell is empty.
8183
8284
Raises
@@ -101,7 +103,8 @@ def _process_cell(cell: dict[str, Any], include_output: bool) -> Optional[str]:
101103
return f'"""\n{cell_str}\n"""'
102104

103105
# Add cell output as comments
104-
if include_output and (outputs := cell.get("outputs")):
106+
outputs = cell.get("outputs")
107+
if include_output and outputs:
105108

106109
# Include cell outputs as comments
107110
output_lines = []
@@ -118,18 +121,18 @@ def _process_cell(cell: dict[str, Any], include_output: bool) -> Optional[str]:
118121
return cell_str
119122

120123

121-
def _extract_output(output: dict[str, Any]) -> list[str]:
124+
def _extract_output(output: Dict[str, Any]) -> List[str]:
122125
"""
123126
Extract the output from a Jupyter notebook cell.
124127
125128
Parameters
126129
----------
127-
output : dict[str, Any]
130+
output : Dict[str, Any]
128131
The output dictionary from a Jupyter notebook cell.
129132
130133
Returns
131134
-------
132-
list[str]
135+
List[str]
133136
The output as a list of strings.
134137
135138
Raises

0 commit comments

Comments
 (0)