Skip to content

Commit aa7838b

Browse files
authored
Merge pull request #59 from tharropoulos/stubs
Add type hints, testing suite and documentation
2 parents 84f5193 + df75f68 commit aa7838b

File tree

101 files changed

+13135
-627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+13135
-627
lines changed

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8

Pipfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
requests = "*"
8+
9+
[dev-packages]
10+
mypy = "*"
11+
wemake-python-styleguide = "*"
12+
flake8 = "*"
13+
black = "*"
14+
pytest = "*"
15+
coverage = "*"
16+
pytest-mock = "*"
17+
requests-mock = "*"
18+
python-dotenv = "*"
19+
types-requests = "*"
20+
typing-extensions = {version = "*", markers = "python_version < '3.11'"}
21+
faker = "*"
22+
23+
[requires]
24+
python_version = "3.8"

Pipfile.lock

Lines changed: 905 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ version = {attr = "typesense.__version__"}
3232

3333
[tool.setuptools.packages.find]
3434
where = ["src"]
35+
36+
[tool.coverage.run]
37+
source = ["."]
38+
omit = ["examples/*.py","./venv/*","tests/*/*.py","*__init__.py","*/*test.py", "./src/typesense/types/*.py"]
39+
40+
[tool.coverage.report]
41+
omit = ["examples/*.py","./venv/*","tests/*.py","*__init__.py","*/*test.py"]

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[pytest]
22
pythonpath = src
3+
markers =
4+
open_ai

requirements.txt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,2 @@
1-
certifi==2024.7.4
2-
chardet==3.0.4
3-
charset-normalizer==3.3.2
4-
idna==2.8
5-
iniconfig==2.0.0
6-
mypy==1.11.0
7-
mypy-extensions==1.0.0
8-
packaging==24.1
9-
pluggy==1.5.0
10-
pytest==8.3.2
11-
requests==2.32.3
12-
typing_extensions==4.12.2
13-
urllib3==2.2.2
1+
-i https://pypi.org/simple
2+
-r requirements/common.txt

requirements/common.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-i https://pypi.org/simple
2+
certifi==2024.8.30; python_version >= '3.6'
3+
charset-normalizer==3.3.2; python_full_version >= '3.7.0'
4+
idna==3.8; python_version >= '3.6'
5+
requests==2.32.3; python_version >= '3.8'
6+
urllib3==2.2.2; python_version >= '3.8'

requirements/dev.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-i https://pypi.org/simple
2+
-r common.txt
3+
astor==0.8.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
4+
attrs==24.2.0; python_version >= '3.7'
5+
bandit==1.7.9; python_version >= '3.8'
6+
black==24.8.0; python_version >= '3.8'
7+
certifi==2024.8.30; python_version >= '3.6'
8+
charset-normalizer==3.3.2; python_full_version >= '3.7.0'
9+
click==8.1.7; python_version >= '3.7'
10+
coverage==7.6.1; python_version >= '3.8'
11+
darglint==1.8.1; python_version >= '3.6' and python_version < '4.0'
12+
docutils==0.20.1; python_version >= '3.7'
13+
eradicate==2.3.0
14+
exceptiongroup==1.2.2; python_version < '3.11'
15+
faker==28.0.0; python_version >= '3.8'
16+
flake8==7.1.1; python_full_version >= '3.8.1'
17+
flake8-bandit==4.1.1; python_version >= '3.6'
18+
flake8-broken-line==1.0.0; python_version >= '3.8' and python_version < '4.0'
19+
flake8-bugbear==23.12.2; python_full_version >= '3.8.1'
20+
flake8-commas==2.1.0
21+
flake8-comprehensions==3.15.0; python_version >= '3.8'
22+
flake8-debugger==4.1.2; python_version >= '3.7'
23+
flake8-docstrings==1.7.0; python_version >= '3.7'
24+
flake8-eradicate==1.5.0; python_version >= '3.8' and python_version < '4.0'
25+
flake8-isort==6.1.1; python_version >= '3.8'
26+
flake8-quotes==3.4.0
27+
flake8-rst-docstrings==0.3.0; python_version >= '3.7'
28+
flake8-string-format==0.3.0
29+
idna==3.8; python_version >= '3.6'
30+
iniconfig==2.0.0; python_version >= '3.7'
31+
isort==5.13.2; python_full_version >= '3.8.0'
32+
markdown-it-py==3.0.0; python_version >= '3.8'
33+
mccabe==0.7.0; python_version >= '3.6'
34+
mdurl==0.1.2; python_version >= '3.7'
35+
mypy==1.11.2; python_version >= '3.8'
36+
mypy-extensions==1.0.0; python_version >= '3.5'
37+
packaging==24.1; python_version >= '3.8'
38+
pathspec==0.12.1; python_version >= '3.8'
39+
pbr==6.1.0; python_version >= '2.6'
40+
pep8-naming==0.13.3; python_version >= '3.7'
41+
platformdirs==4.2.2; python_version >= '3.8'
42+
pluggy==1.5.0; python_version >= '3.8'
43+
pycodestyle==2.12.1; python_version >= '3.8'
44+
pydocstyle==6.3.0; python_version >= '3.6'
45+
pyflakes==3.2.0; python_version >= '3.8'
46+
pygments==2.18.0; python_version >= '3.8'
47+
pytest==8.3.2; python_version >= '3.8'
48+
pytest-mock==3.14.0; python_version >= '3.8'
49+
python-dateutil==2.9.0.post0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
50+
python-dotenv==1.0.1; python_version >= '3.8'
51+
pyyaml==6.0.2; python_version >= '3.8'
52+
requests==2.32.3; python_version >= '3.8'
53+
requests-mock==1.12.1; python_version >= '3.5'
54+
restructuredtext-lint==1.4.0
55+
rich==13.8.0; python_full_version >= '3.7.0'
56+
setuptools==74.0.0; python_version >= '3.8'
57+
six==1.16.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
58+
snowballstemmer==2.2.0
59+
stevedore==5.3.0; python_version >= '3.8'
60+
tomli==2.0.1; python_version < '3.11'
61+
types-requests==2.32.0.20240712; python_version >= '3.8'
62+
typing-extensions==4.12.2; python_version < '3.11'
63+
urllib3==2.2.2; python_version >= '3.8'
64+
wemake-python-styleguide==0.18.0; python_version < '4.0' and python_full_version >= '3.8.1'

setup.cfg

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,60 @@
11
[flake8]
2-
max-line-length = 160
2+
# flake8 configuration:
3+
# https://flake8.pycqa.org/en/latest/user/configuration.html
4+
format = wemake
5+
show-source = true
6+
statistics = false
7+
doctests = true
8+
enable-extensions = G
9+
max-line-length = 88
10+
extend-select = B950
11+
extend-ignore = E203,E501,E701
12+
13+
# darglint configuration:
14+
# https://github.com/terrencepreilly/darglint
15+
strictness = long
16+
docstring-style = sphinx
17+
18+
# Flake plugins:
19+
max-complexity = 6
20+
21+
# # Excluding some directories:
22+
exclude = .git,__pycache__,venv,.eggs,*.egg
23+
ignore = Q000, WPS602, WPS432, WPS305, WPS221, WPS230, WPS234, WPS433, WPS440, W503, WPS331, WPS306, WPS237, WPS202, RST301, RST306, WPS214, WPS235, WPS226, WPS337, WPS320, F821, WPS201
24+
per-file-ignores =
25+
tests/*.py: S101, WPS226, WPS118, WPS202, WPS204, WPS218, WPS211, WPS604, WPS431, WPS210, WPS201, WPS437
26+
src/typesense/types/*.py: B950, WPS215, WPS111, WPS462, WPS322, WPS428, WPS114, WPS110, WPS202
27+
src/typesense/documents.py: WPS320, E704, D102, WPS428, WPS220
28+
src/typesense/api_call.py: WPS110, WPS211
29+
src/typesense/request_handler.py: WPS110, WPS211
30+
331

432
[metadata]
533
license_file = LICENSE
634

7-
[isort]
35+
[isort]
36+
# isort configuration:
37+
# https://github.com/PyCQA/isort/wiki/isort-Settings
38+
multi_line_output = 3
39+
include_trailing_comma = True
40+
force_grid_wrap = 0
41+
use_parentheses = True
42+
ensure_newline_before_comments = True
43+
line_length = 88
44+
45+
[mypy]
46+
# Mypy configuration:
47+
# https://mypy.readthedocs.io/en/latest/config_file.html
48+
enable_error_code =
49+
truthy-bool,
50+
truthy-iterable,
51+
redundant-expr,
52+
unused-awaitable,
53+
ignore-without-code,
54+
possibly-undefined,
55+
redundant-self,
56+
57+
explicit_package_bases = true
58+
ignore_missing_imports = true
59+
strict = true
60+
warn_unreachable = true

src/typesense/alias.py

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,84 @@
1+
"""
2+
This module provides functionality for managing individual aliases in Typesense.
3+
4+
Classes:
5+
- Alias: Handles operations related to a specific alias.
6+
7+
Methods:
8+
- __init__: Initializes the Alias object.
9+
- retrieve: Retrieves the details of this specific alias.
10+
- delete: Deletes this specific alias.
11+
- _endpoint_path: Constructs the API endpoint path for this specific alias.
12+
13+
The Alias class interacts with the Typesense API to manage operations on a
14+
specific alias. It provides methods to retrieve and delete individual aliases.
15+
16+
For more information on collection aliases, refer to the Collection Alias
17+
[documentation](https://typesense.org/docs/27.0/api/collection-alias.html#create-or-update-an-alias)
18+
19+
This module uses type hinting and is compatible with Python 3.11+ as well as earlier
20+
versions through the use of the typing_extensions library.
21+
"""
22+
23+
from typesense.api_call import ApiCall
24+
from typesense.types.alias import AliasSchema
25+
26+
127
class Alias(object):
2-
def __init__(self, api_call, name):
28+
"""
29+
Class for managing individual aliases in Typesense.
30+
31+
This class provides methods to interact with a specific alias,
32+
including retrieving and deleting it.
33+
34+
Attributes:
35+
api_call (ApiCall): The API call object for making requests.
36+
name (str): The name of the alias.
37+
"""
38+
39+
def __init__(self, api_call: ApiCall, name: str):
40+
"""
41+
Initialize the Alias object.
42+
43+
Args:
44+
api_call (ApiCall): The API call object for making requests.
45+
name (str): The name of the alias.
46+
"""
347
self.api_call = api_call
448
self.name = name
549

6-
def _endpoint_path(self):
7-
from .aliases import Aliases
8-
return u"{0}/{1}".format(Aliases.RESOURCE_PATH, self.name)
50+
def retrieve(self) -> AliasSchema:
51+
"""
52+
Retrieve this specific alias.
53+
54+
Returns:
55+
AliasSchema: The schema containing the alias details.
56+
"""
57+
response: AliasSchema = self.api_call.get(
58+
self._endpoint_path,
59+
entity_type=AliasSchema,
60+
as_json=True,
61+
)
62+
return response
63+
64+
def delete(self) -> AliasSchema:
65+
"""
66+
Delete this specific alias.
67+
68+
Returns:
69+
AliasSchema: The schema containing the deletion response.
70+
"""
71+
response = self.api_call.delete(self._endpoint_path, entity_type=AliasSchema)
72+
return response
73+
74+
@property
75+
def _endpoint_path(self) -> str:
76+
"""
77+
Construct the API endpoint path for this specific alias.
978
10-
def retrieve(self):
11-
return self.api_call.get(self._endpoint_path())
79+
Returns:
80+
str: The constructed endpoint path.
81+
"""
82+
from typesense.aliases import Aliases
1283

13-
def delete(self):
14-
return self.api_call.delete(self._endpoint_path())
84+
return "/".join([Aliases.resource_path, self.name])

0 commit comments

Comments
 (0)