Skip to content

Commit d096358

Browse files
committed
Initial dev commit.
Changes ======= * Basic query functionality is available for both sync and async APIs * Rough handling of timeouts and cancellation is available (but more work needs to be done) * Error handling is incomplete * Linting is not in place (and will require changes) * Typing is not in place (and will require changes) * Test suite is minimal
1 parent cdd9d05 commit d096358

110 files changed

Lines changed: 11296 additions & 0 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
.idea/
161+
162+
# Distribution / packaging
163+
build/
164+
couchbase_columnar/_version.py
165+
couchbase_columnar/*.so
166+
couchbase_columnar/*.dylib*.*
167+
couchbase_columnar/*.dll
168+
couchbase_columnar/*.pyd
169+
deps/couchbase-cxx-cache/
170+
171+
# Sphinx
172+
docs/_build/
173+
174+
# VS Code
175+
.vscode/
176+
177+
# tests
178+
tests/test_logs/
179+
CouchbaseMock*.jar
180+
gocaves*
181+
.pytest_cache/
182+
test_scripts/

LICENSE

Whitespace-only changes.

acouchbase_analytics/__init__.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright 2016-2024. Couchbase, Inc.
2+
# All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import asyncio
17+
import selectors
18+
from asyncio import AbstractEventLoop
19+
from typing import Optional
20+
21+
from couchbase_analytics.common import JSONType as JSONType # noqa: F401
22+
23+
24+
class _LoopValidator:
25+
"""
26+
**INTERNAL**
27+
"""
28+
29+
REQUIRED_METHODS = {'add_reader', 'remove_reader',
30+
'add_writer', 'remove_writer'}
31+
32+
@staticmethod
33+
def _get_working_loop() -> AbstractEventLoop:
34+
"""
35+
**INTERNAL**
36+
"""
37+
evloop = asyncio.get_event_loop()
38+
gen_new_loop = not _LoopValidator._is_valid_loop(evloop)
39+
if gen_new_loop:
40+
evloop.close()
41+
selector = selectors.SelectSelector()
42+
new_loop = asyncio.SelectorEventLoop(selector)
43+
asyncio.set_event_loop(new_loop)
44+
return new_loop
45+
46+
return evloop
47+
48+
@staticmethod
49+
def _is_valid_loop(evloop: Optional[AbstractEventLoop] = None) -> bool:
50+
"""
51+
**INTERNAL**
52+
"""
53+
if not evloop:
54+
return False
55+
for meth in _LoopValidator.REQUIRED_METHODS:
56+
abs_meth, actual_meth = (
57+
getattr(asyncio.AbstractEventLoop, meth), getattr(evloop.__class__, meth))
58+
if abs_meth == actual_meth:
59+
return False
60+
return True
61+
62+
@staticmethod
63+
def get_event_loop(evloop: Optional[AbstractEventLoop] = None) -> AbstractEventLoop:
64+
"""
65+
**INTERNAL**
66+
"""
67+
if evloop and _LoopValidator._is_valid_loop(evloop):
68+
return evloop
69+
return _LoopValidator._get_working_loop()
70+
71+
@staticmethod
72+
def close_loop() -> None:
73+
"""
74+
**INTERNAL**
75+
"""
76+
evloop = asyncio.get_event_loop()
77+
evloop.close()
78+
79+
80+
def get_event_loop(evloop: Optional[AbstractEventLoop] = None) -> AbstractEventLoop:
81+
"""
82+
Get an event loop compatible with acouchbase_analytics.
83+
Some Event loops, such as ProactorEventLoop (the default asyncio event
84+
loop for Python 3.8 on Windows) are not compatible with acouchbase_analytics as
85+
they don't implement all members in the abstract base class.
86+
87+
:param evloop: preferred event loop
88+
:return: The preferred event loop, if compatible, otherwise, a compatible
89+
alternative event loop.
90+
"""
91+
return _LoopValidator.get_event_loop(evloop)

0 commit comments

Comments
 (0)