Skip to content

Commit 989d516

Browse files
committed
chore(deps): #43 Get rid of click as a dependency
Click was used to raise some specific errors. This was a useless dependency. We created a dedicated error instead.
1 parent b9503d9 commit 989d516

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

pygitguardian/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"""PyGitGuardian API Client"""
2-
from .client import GGClient
2+
from .client import ContentTooLarge, GGClient
33

44

55
__version__ = "1.5.0"
66
GGClient._version = __version__
77

8-
__all__ = [
9-
"GGClient",
10-
]
8+
__all__ = ["GGClient", "ContentTooLarge"]

pygitguardian/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pathlib import Path
77
from typing import Any, Dict, List, Optional, Union, cast
88

9-
import click
109
import requests
1110
from requests import Response, Session, codes
1211

@@ -36,6 +35,14 @@
3635
MAX_TAR_CONTENT_SIZE = 30 * 1024 * 1024
3736

3837

38+
class ContentTooLarge(Exception):
39+
"""
40+
Raised if the total size of files sent by the client exceeds MAX_TAR_CONTENT_SIZE
41+
"""
42+
43+
pass
44+
45+
3946
class Versions:
4047
app_version: Optional[str] = None
4148
secrets_engine_version: Optional[str] = None
@@ -86,7 +93,7 @@ def _create_tar(root_path: Path, filenames: List[str]) -> bytes:
8693
full_path = root_path / filename
8794
current_dir_size += os.path.getsize(full_path)
8895
if current_dir_size > MAX_TAR_CONTENT_SIZE:
89-
raise click.ClickException(
96+
raise ContentTooLarge(
9097
f"The total size of the files processed exceeds {MAX_TAR_CONTENT_SIZE / (1024 * 1024):.0f}MB, "
9198
f"please try again with less files"
9299
)
@@ -393,7 +400,6 @@ def iac_directory_scan(
393400
scan_parameters: IaCScanParameters,
394401
extra_headers: Optional[Dict[str, str]] = None,
395402
) -> Union[Detail, IaCScanResult]:
396-
397403
tar = _create_tar(directory, filenames)
398404
result: Union[Detail, IaCScanResult]
399405
try:

tests/test_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
from io import BytesIO
33
from unittest import mock
44

5-
import click
65
import pytest
76

8-
from pygitguardian.client import _create_tar
7+
from pygitguardian.client import ContentTooLarge, _create_tar
98

109

1110
def test_create_tar(tmp_path):
@@ -44,7 +43,7 @@ def test_create_tar_cannot_exceed_max_tar_content_size(tmp_path):
4443
(tmp_path / file2_name).write_text("")
4544

4645
with pytest.raises(
47-
click.ClickException,
46+
ContentTooLarge,
4847
match=r"The total size of the files processed exceeds \d+MB, please try again with less files",
4948
):
5049
_create_tar(tmp_path, [file1_name, file2_name])

0 commit comments

Comments
 (0)