Skip to content

Commit

Permalink
Added support for some special types like callables, coroutines, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoSecundus committed Nov 24, 2023
1 parent 2bc45a8 commit 1607b89
Show file tree
Hide file tree
Showing 18 changed files with 386 additions and 238 deletions.
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ repos:
- id: check-added-large-files
exclude: (docs/module_docs|src/api/static/img)
- id: check-case-conflict
# MyPy pre-commit hook
- repo: local
hooks:
- id: mypy
name: Running MyPy Type Check
entry: mypy
language: system
types: [python]
args: []
exclude: "test"
# Ruff pre-commit hook
- repo: local
hooks:
Expand Down
212 changes: 104 additions & 108 deletions environment.yaml
Original file line number Diff line number Diff line change
@@ -1,125 +1,121 @@
name: pyodb
channels:
- conda-forge
- defaults
dependencies:
- _libgcc_mutex=0.1=main
- _openmp_mutex=5.1=1_gnu
- asttokens=2.2.1=pyhd8ed1ab_0
- backcall=0.2.0=pyh9f0ad1d_0
- backports=1.0=pyhd8ed1ab_3
- backports.functools_lru_cache=1.6.4=pyhd8ed1ab_0
- bzip2=1.0.8=h7b6447c_0
- ca-certificates=2022.12.7=ha878542_0
- debugpy=1.5.1=py310h295c915_0
- decorator=5.1.1=pyhd8ed1ab_0
- entrypoints=0.4=pyhd8ed1ab_0
- executing=1.2.0=pyhd8ed1ab_0
- ipykernel=6.15.0=pyh210e3f2_0
- ipython=8.11.0=pyh41d4057_0
- jedi=0.18.2=pyhd8ed1ab_0
- jupyter_client=7.3.4=pyhd8ed1ab_0
- jupyter_core=5.3.0=py310hff52083_0
- ca-certificates=2023.08.22=h06a4308_0
- ld_impl_linux-64=2.38=h1181459_1
- libffi=3.4.2=h6a678d5_6
- libffi=3.4.4=h6a678d5_0
- libgcc-ng=11.2.0=h1234567_1
- libgomp=11.2.0=h1234567_1
- libsodium=1.0.18=h36c2ea0_1
- libstdcxx-ng=11.2.0=h1234567_1
- libuuid=1.41.5=h5eee18b_0
- matplotlib-inline=0.1.6=pyhd8ed1ab_0
- ncurses=6.4=h6a678d5_0
- nest-asyncio=1.5.6=pyhd8ed1ab_0
- openssl=1.1.1t=h7f8727e_0
- packaging=23.0=pyhd8ed1ab_0
- parso=0.8.3=pyhd8ed1ab_0
- pexpect=4.8.0=pyh1a96a4e_2
- pickleshare=0.7.5=py_1003
- pip=23.0.1=py310h06a4308_0
- platformdirs=3.1.1=pyhd8ed1ab_0
- prompt-toolkit=3.0.38=pyha770c72_0
- prompt_toolkit=3.0.38=hd8ed1ab_0
- psutil=5.9.0=py310h5eee18b_0
- ptyprocess=0.7.0=pyhd3deb0d_0
- pure_eval=0.2.2=pyhd8ed1ab_0
- pygments=2.14.0=pyhd8ed1ab_0
- python=3.10.9=h7a1cb2a_2
- python-dateutil=2.8.2=pyhd8ed1ab_0
- python_abi=3.10=2_cp310
- pyzmq=23.2.0=py310h6a678d5_0
- openssl=3.0.12=h7f8727e_0
- pip=23.3.1=py311h06a4308_0
- python=3.11.5=h955ad1f_0
- readline=8.2=h5eee18b_0
- setuptools=65.6.3=py310h06a4308_0
- six=1.16.0=pyh6c4a22f_0
- sqlite=3.41.1=h5eee18b_0
- stack_data=0.6.2=pyhd8ed1ab_0
- setuptools=68.0.0=py311h06a4308_0
- sqlite=3.41.2=h5eee18b_0
- tk=8.6.12=h1ccaba5_0
- traitlets=5.9.0=pyhd8ed1ab_0
- typing-extensions=4.5.0=hd8ed1ab_0
- typing_extensions=4.5.0=pyha770c72_0
- tzdata=2022g=h04d1e81_0
- wcwidth=0.2.6=pyhd8ed1ab_0
- wheel=0.38.4=py310h06a4308_0
- xz=5.2.10=h5eee18b_1
- zeromq=4.3.4=h9c3ff4c_1
- tzdata=2023c=h04d1e81_0
- wheel=0.41.2=py311h06a4308_0
- xz=5.4.2=h5eee18b_0
- zlib=1.2.13=h5eee18b_0
- pip:
- attrs==22.2.0
- bleach==6.0.0
- build==0.10.0
- cachetools==5.3.0
- certifi==2023.7.22
- cffi==1.15.1
- cfgv==3.3.1
- chardet==5.1.0
- charset-normalizer==3.1.0
- click==8.1.3
- colorama==0.4.6
- coverage==7.2.2
- cryptography==41.0.3
- distlib==0.3.6
- docutils==0.19
- exceptiongroup==1.1.1
- filelock==3.10.0
- identify==2.5.21
- idna==3.4
- importlib-metadata==6.3.0
- iniconfig==2.0.0
- jaraco-classes==3.2.3
- jeepney==0.8.0
- jinja2==3.1.2
- keyring==23.13.1
- markdown-it-py==2.2.0
- markupsafe==2.1.2
- mdurl==0.1.2
- memray==1.7.0
- more-itertools==9.1.0
- nodeenv==1.7.0
- pdoc==13.0.0
- pkginfo==1.9.6
- pluggy==1.0.0
- pre-commit==3.2.0
- pycparser==2.21
- pydantic==1.10.9
- pyodb==0.1.1
- pyproject-api==1.5.1
- pyproject-hooks==1.0.0
- pytest==7.2.2
- pytest-cov==4.0.0
- pyyaml==6.0
- readme-renderer==37.3
- requests==2.31.0
- requests-toolbelt==0.10.1
- rfc3986==2.0.0
- rich==13.3.2
- ruff==0.0.257
- secretstorage==3.3.3
- snakeviz==2.1.1
- tornado==6.2
- tox==4.4.8
- tqdm==4.65.0
- twine==4.0.2
- urllib3==1.26.15
- virtualenv==20.21.0
- webencodings==0.5.1
- zipp==3.15.0
prefix: /usr/miniconda3/envs/pyodb
- asttokens==2.2.1
- attrs==22.2.0
- backcall==0.2.0
- bleach==6.0.0
- build==0.10.0
- cachetools==5.3.0
- certifi==2023.7.22
- cffi==1.15.1
- cfgv==3.3.1
- chardet==5.1.0
- charset-normalizer==3.1.0
- click==8.1.3
- colorama==0.4.6
- comm==0.1.3
- coverage==7.2.2
- cryptography==41.0.3
- debugpy==1.6.7
- decorator==5.1.1
- distlib==0.3.6
- docutils==0.19
- exceptiongroup==1.1.1
- executing==1.2.0
- filelock==3.10.0
- identify==2.5.21
- idna==3.4
- importlib-metadata==6.3.0
- iniconfig==2.0.0
- ipykernel==6.23.1
- ipython==8.13.2
- jaraco-classes==3.2.3
- jedi==0.18.2
- jeepney==0.8.0
- jinja2==3.1.2
- jupyter-client==8.2.0
- jupyter-core==5.3.0
- keyring==23.13.1
- markdown-it-py==2.2.0
- markupsafe==2.1.2
- matplotlib-inline==0.1.6
- mccabe==0.7.0
- mdurl==0.1.2
- memray==1.7.0
- more-itertools==9.1.0
- mypy==1.7.0
- mypy-extensions==1.0.0
- nest-asyncio==1.5.6
- nodeenv==1.7.0
- packaging==23.1
- parso==0.8.3
- pdoc==13.0.0
- pexpect==4.8.0
- pickleshare==0.7.5
- pkginfo==1.9.6
- platformdirs==3.5.1
- pluggy==1.0.0
- pre-commit==3.2.0
- prompt-toolkit==3.0.38
- psutil==5.9.5
- ptyprocess==0.7.0
- pure-eval==0.2.2
- pycparser==2.21
- pydantic==1.10.9
- pygments==2.15.1
- pyodb==0.1.4
- pyproject-api==1.5.1
- pyproject-hooks==1.0.0
- pytest==7.2.2
- pytest-cov==4.0.0
- python-dateutil==2.8.2
- pyyaml==6.0
- pyzmq==25.1.0
- readme-renderer==37.3
- requests==2.31.0
- requests-toolbelt==0.10.1
- rfc3986==2.0.0
- rich==13.3.2
- ruff==0.0.257
- secretstorage==3.3.3
- six==1.16.0
- snakeviz==2.1.1
- stack-data==0.6.2
- tomli==2.0.1
- tornado==6.3.3
- tox==4.4.8
- tqdm==4.65.0
- traitlets==5.9.0
- twine==4.0.2
- typing-extensions==4.8.0
- urllib3==1.26.15
- virtualenv==20.21.0
- wcwidth==0.2.6
- webencodings==0.5.1
- zipp==3.15.0
prefix: /home/teuschl/miniconda3/envs/pyodb
93 changes: 78 additions & 15 deletions performance.ipynb

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pyodb"
version = "0.1.4"
version = "0.1.5"
authors = [
{ name="Nikolas Teuschl", email="[email protected]" },
]
Expand Down Expand Up @@ -81,3 +81,26 @@ max-doc-length = 100

[tool.pytest.ini_options]
pythonpath = ["src"]

[tool.mypy]
implicit_optional = true
ignore_missing_imports = true

[tool.tox]
legacy_tox_ini = """
[tox]
env_list =
py{310,311,312}
minversion = 4.4.8
[testenv]
description = Run tests with pytest
package = wheel
wheel_build_env = .pkg
deps =
pytest>=7
pydantic==1.10.9
commands =
python3 -m pytest {tty:--color=yes} test {posargs}
download = True
"""
8 changes: 6 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ backcall==0.2.0
bleach==6.0.0
build==0.10.0
cachetools==5.3.0
certifi==2023.07.22
certifi==2023.7.22
cffi==1.15.1
cfgv==3.3.1
chardet==5.1.0
Expand Down Expand Up @@ -41,6 +41,8 @@ mccabe==0.7.0
mdurl==0.1.2
memray==1.7.0
more-itertools==9.1.0
mypy==1.7.0
mypy-extensions==1.0.0
nest-asyncio==1.5.6
nodeenv==1.7.0
packaging==23.1
Expand All @@ -59,7 +61,7 @@ pure-eval==0.2.2
pycparser==2.21
pydantic==1.10.9
Pygments==2.15.1
pyodb==0.1.0
pyodb==0.1.4
pyproject_api==1.5.1
pyproject_hooks==1.0.0
pytest==7.2.2
Expand All @@ -74,6 +76,7 @@ rfc3986==2.0.0
rich==13.3.2
ruff==0.0.257
SecretStorage==3.3.3
six==1.16.0
snakeviz==2.1.1
stack-data==0.6.2
tomli==2.0.1
Expand All @@ -82,6 +85,7 @@ tox==4.4.8
tqdm==4.65.0
traitlets==5.9.0
twine==4.0.2
typing_extensions==4.8.0
urllib3==1.26.15
virtualenv==20.21.0
wcwidth==0.2.6
Expand Down
9 changes: 0 additions & 9 deletions scripts/activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,13 @@ export PYTHONPATH="$BASEDIR/src"
alias odb-lint="ruff --config $BASEDIR/pyproject.toml $BASEDIR"
alias odb-test="python -m pytest --cov='./src' --cov-report='html' $BASEDIR/test"
alias odb-profile='python3 -m cProfile -o profiler/results_$(date +%y%m%d-%H%M).prof '
alias odb-mem-profile='memray run -f -o profiler/mem_profile_$(date +%y%m%d-%H%M).bin '
alias odb-docs="pdoc -o docs/module_docs/ -d google --logo $BASEDIR/res/img/Logo.png --favicon $BASEDIR/res/img/Logo.png src"
alias odb-help="echo \"PyODB Repo Commands:
--------------------------
odb-lint - Runs linter and writes logs to lint.log.
odb-test - Runs all tests and generates coverage report.
odb-profile <script> - Profiles the script/program and writes output to profiler/results_<date>.prof
You can then use snakeviz to visualize the profiling: snakeviz profiler/results_<date>.prof
odb-mem-profile <script> - Profiles the script/program and writes output to profiler/mem_profile_<date>.bin
You can use multiple builtin visualization tools from memray:
memray summary <bin_file>
memray flamegraph <bin_file>
memray table <bin_file>
memray tree <bin_file>
memray stats <bin_file>
memray transform <bin_file>
odb-docs - Generates an updated module documentation and saves it to docs/module_docs.
odb-help - Show this help.\"
"
Expand Down
6 changes: 4 additions & 2 deletions src/pyodb/pyodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ def __init__(
self.data_type = data_type
self.lifetime = lifetime
self.dataclass = dataclass
self.data = []
self.expires = 0
self.data: list = []
self.expires: float = 0


def get_data(self) -> list | None:
Expand Down Expand Up @@ -380,6 +380,8 @@ def get_data(self, cache_key: str, *args, **kwargs) -> list[Any]:

try:
data = cache.data_func(*args, **kwargs)
if not data:
return []
expires = time() + cache.lifetime
self.pyodb.save_multiple([cache.dataclass(dp, expires) for dp in data], expires)
cache.set_data(data, expires)
Expand Down
Loading

0 comments on commit 1607b89

Please sign in to comment.