Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a720ad2

Browse files
refactor(config,lint): centralize env utils, switch to ruff.isort, drop unused constants
- remove `isort` in favour of `ruff.lint.isort` - remove unused constants `BASE_DIR` and `TEMPLATE_DIR` in `tests/test_flow_integration.py` - rename constant `templates` to `JINJA_TEMPLATES` in `src/server/server_config.py` - move function definition of `_get_int_env_var` from `src/server/server_config.py` to `src/gitingest/utils/config_utils.py` - remove duplicated function definition of `_get_int_env_var` in `src/gitingest/config.py` - rename function `_get_env_var` to `_get_str_env_var` for clarity - move `Colors` from `src/server/server_utils.py` to `src/gitingest/utils/colors.py` to break circular import chain
1 parent 8b63695 commit a720ad2

File tree

15 files changed

+77
-90
lines changed

15 files changed

+77
-90
lines changed

‎.pre-commit-config.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ repos:
5858
- id: python-use-type-annotations
5959
description: 'Enforce that python3.6+ type annotations are used instead of type comments.'
6060

61-
- repo: https://github.com/PyCQA/isort
62-
rev: 6.0.1
63-
hooks:
64-
- id: isort
65-
description: 'Sort imports alphabetically, and automatically separated into sections and by type.'
66-
6761
- repo: https://github.com/pre-commit/mirrors-eslint
6862
rev: v9.30.1
6963
hooks:

‎pyproject.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,13 @@ per-file-ignores = { "tests/**/*.py" = ["S101"] } # Skip the "assert used" warni
100100
[tool.ruff.lint.pylint]
101101
max-returns = 10
102102

103-
#[tool.ruff.lint.isort]
104-
#order-by-type = true
105-
#case-sensitive = true
103+
[tool.ruff.lint.isort]
104+
order-by-type = true
105+
case-sensitive = true
106106

107107
[tool.pycln]
108108
all = true
109109

110-
# TODO: Remove this once we figure out how to use ruff-isort
111-
[tool.isort]
112-
profile = "black"
113-
line_length = 119
114-
remove_redundant_aliases = true
115-
float_to_top = true # https://github.com/astral-sh/ruff/issues/6514
116-
order_by_type = true
117-
filter_files = true
118-
119110
# Test configuration
120111
[tool.pytest.ini_options]
121112
pythonpath = ["src"]

‎src/gitingest/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import click
1010
from typing_extensions import Unpack
1111

12-
from gitingest.config import MAX_DIRECTORY_DEPTH, MAX_FILE_SIZE, MAX_FILES, MAX_TOTAL_SIZE_BYTES, OUTPUT_FILE_NAME
12+
from gitingest.config import MAX_DIRECTORY_DEPTH, MAX_FILES, MAX_FILE_SIZE, MAX_TOTAL_SIZE_BYTES, OUTPUT_FILE_NAME
1313
from gitingest.entrypoint import ingest_async
1414

1515

‎src/gitingest/config.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33
import tempfile
44
from pathlib import Path
55

6-
from gitingest.utils.config_utils import _get_env_var
7-
8-
def _get_int_env_var(key: str, default: int) -> int:
9-
"""Get environment variable as integer with fallback to default."""
10-
try:
11-
return int(_get_env_var(key, str(default)))
12-
except ValueError:
13-
print(f"Warning: Invalid value for GITINGEST_{key}. Using default: {default}")
14-
return default
6+
from gitingest.utils.config_utils import _get_int_env_var, _get_str_env_var
157

168
MAX_FILE_SIZE = _get_int_env_var("MAX_FILE_SIZE", 10 * 1024 * 1024) # Max file size to process in bytes (10 MB)
179
MAX_FILES = _get_int_env_var("MAX_FILES", 10_000) # Max number of files to process
@@ -20,5 +12,5 @@ def _get_int_env_var(key: str, default: int) -> int:
2012

2113
DEFAULT_TIMEOUT = _get_int_env_var("DEFAULT_TIMEOUT", 60) # Default timeout for git operations in seconds
2214

23-
OUTPUT_FILE_NAME = _get_env_var("OUTPUT_FILE_NAME", "digest.txt")
24-
TMP_BASE_PATH = Path(_get_env_var("TMP_BASE_PATH", tempfile.gettempdir())) / "gitingest"
15+
OUTPUT_FILE_NAME = _get_str_env_var("OUTPUT_FILE_NAME", "digest.txt")
16+
TMP_BASE_PATH = Path(_get_str_env_var("TMP_BASE_PATH", tempfile.gettempdir())) / "gitingest"

‎src/gitingest/schemas/ingestion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pydantic import BaseModel, Field
99

10-
from gitingest.config import MAX_DIRECTORY_DEPTH, MAX_FILE_SIZE, MAX_FILES, MAX_TOTAL_SIZE_BYTES
10+
from gitingest.config import MAX_DIRECTORY_DEPTH, MAX_FILES, MAX_FILE_SIZE, MAX_TOTAL_SIZE_BYTES
1111

1212

1313
@dataclass

‎src/gitingest/utils/colors.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Color printing utility."""
2+
3+
4+
class Colors:
5+
"""ANSI color codes."""
6+
7+
BLACK = "033円[0;30m"
8+
RED = "033円[0;31m"
9+
GREEN = "033円[0;32m"
10+
BROWN = "033円[0;33m"
11+
BLUE = "033円[0;34m"
12+
PURPLE = "033円[0;35m"
13+
CYAN = "033円[0;36m"
14+
LIGHT_GRAY = "033円[0;37m"
15+
DARK_GRAY = "033円[1;30m"
16+
LIGHT_RED = "033円[1;31m"
17+
LIGHT_GREEN = "033円[1;32m"
18+
YELLOW = "033円[1;33m"
19+
LIGHT_BLUE = "033円[1;34m"
20+
LIGHT_PURPLE = "033円[1;35m"
21+
LIGHT_CYAN = "033円[1;36m"
22+
WHITE = "033円[1;37m"
23+
BOLD = "033円[1m"
24+
FAINT = "033円[2m"
25+
ITALIC = "033円[3m"
26+
UNDERLINE = "033円[4m"
27+
BLINK = "033円[5m"
28+
NEGATIVE = "033円[7m"
29+
CROSSED = "033円[9m"
30+
END = "033円[0m"

‎src/gitingest/utils/config_utils.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from __future__ import annotations
44

55
import os
6+
import warnings
67

78

8-
def _get_env_var(key: str, default: str) -> str:
9-
"""Get environment variable with ``GITINGEST_`` prefix.
9+
def _get_str_env_var(key: str, default: str) -> str:
10+
"""Get string environment variable with ``GITINGEST_`` prefix and fallback to default.
1011
1112
Parameters
1213
----------
@@ -18,13 +19,35 @@ def _get_env_var(key: str, default: str) -> str:
1819
Returns
1920
-------
2021
str
21-
The value of the environment variable as a string.
22+
The value of the environment variable.
2223
2324
"""
24-
env_key = f"GITINGEST_{key}"
25-
value = os.environ.get(env_key)
25+
value = os.environ.get(f"GITINGEST_{key}")
2626

2727
if value is None:
2828
return default
2929

3030
return value
31+
32+
33+
def _get_int_env_var(key: str, default: int) -> int:
34+
"""Get integer environment variable with ``GITINGEST_`` prefix and fallback to default.
35+
36+
Parameters
37+
----------
38+
key : str
39+
The name of the environment variable.
40+
default : int
41+
The default value to return if the environment variable is not set.
42+
43+
Returns
44+
-------
45+
int
46+
The value of the environment variable as an integer.
47+
48+
"""
49+
try:
50+
return int(_get_str_env_var(key, default=str(default)))
51+
except ValueError:
52+
warnings.warn(f"Invalid value for GITINGEST_{key}. Using default: {default}", stacklevel=2)
53+
return default

‎src/gitingest/utils/git_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import httpx
1313
from starlette.status import HTTP_200_OK, HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN, HTTP_404_NOT_FOUND
1414

15+
from gitingest.utils.colors import Colors
1516
from gitingest.utils.compat_func import removesuffix
1617
from gitingest.utils.exceptions import InvalidGitHubTokenError
17-
from server.server_utils import Colors
1818

1919
# GitHub Personal-Access tokens (classic + fine-grained).
2020
# - ghp_ / gho_ / ghu_ / ghs_ / ghr_ → 36 alphanumerics

‎src/server/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from server.metrics_server import start_metrics_server
1818
from server.routers import dynamic, index, ingest
19-
from server.server_config import templates
19+
from server.server_config import JINJA_TEMPLATES
2020
from server.server_utils import lifespan, limiter, rate_limit_exception_handler
2121

2222
# Load environment variables from .env file
@@ -163,7 +163,7 @@ async def custom_swagger_ui(request: Request) -> HTMLResponse:
163163
- **HTMLResponse**: Custom Swagger UI documentation page
164164
165165
"""
166-
return templates.TemplateResponse("swagger_ui.jinja", {"request": request})
166+
return JINJA_TEMPLATES.TemplateResponse("swagger_ui.jinja", {"request": request})
167167

168168

169169
@app.get("/api", include_in_schema=True)

‎src/server/query_processor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
from gitingest.clone import clone_repo
99
from gitingest.ingestion import ingest_query
1010
from gitingest.query_parser import IngestionQuery, parse_query
11+
from gitingest.utils.colors import Colors
1112
from gitingest.utils.git_utils import validate_github_token
1213
from server.models import IngestErrorResponse, IngestResponse, IngestSuccessResponse
1314
from server.server_config import MAX_DISPLAY_SIZE
14-
from server.server_utils import Colors, log_slider_to_size
15+
from server.server_utils import log_slider_to_size
1516

1617

1718
async def process_query(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /