pjdev-sqlmodel 0.0.1a0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,165 @@
1
+ .DS_Store
2
+ .idea
3
+
4
+ !**/.gitkeep
5
+
6
+ # Byte-compiled / optimized / DLL files
7
+ __pycache__/
8
+ *.py[cod]
9
+ *$py.class
10
+
11
+ # C extensions
12
+ *.so
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+ cover/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+ db.sqlite3-journal
68
+
69
+ # Flask stuff:
70
+ instance/
71
+ .webassets-cache
72
+
73
+ # Scrapy stuff:
74
+ .scrapy
75
+
76
+ # Sphinx documentation
77
+ docs/_build/
78
+
79
+ # PyBuilder
80
+ .pybuilder/
81
+ target/
82
+
83
+ # Jupyter Notebook
84
+ .ipynb_checkpoints
85
+
86
+ # IPython
87
+ profile_default/
88
+ ipython_config.py
89
+
90
+ # pyenv
91
+ # For a library or package, you might want to ignore these files since the code is
92
+ # intended to run in multiple environments; otherwise, check them in:
93
+ # .python-version
94
+
95
+ # pipenv
96
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
98
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
99
+ # install all needed dependencies.
100
+ #Pipfile.lock
101
+
102
+ # poetry
103
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
104
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
105
+ # commonly ignored for libraries.
106
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
107
+ #poetry.lock
108
+
109
+ # pdm
110
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
111
+ #pdm.lock
112
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
113
+ # in version control.
114
+ # https://pdm.fming.dev/#use-with-ide
115
+ .pdm.toml
116
+
117
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
118
+ __pypackages__/
119
+
120
+ # Celery stuff
121
+ celerybeat-schedule
122
+ celerybeat.pid
123
+
124
+ # SageMath parsed files
125
+ *.sage.py
126
+
127
+ # Environments
128
+ .env
129
+ .venv
130
+ env/
131
+ venv/
132
+ ENV/
133
+ env.bak/
134
+ venv.bak/
135
+
136
+ # Spyder project settings
137
+ .spyderproject
138
+ .spyproject
139
+
140
+ # Rope project settings
141
+ .ropeproject
142
+
143
+ # mkdocs documentation
144
+ /site
145
+
146
+ # mypy
147
+ .mypy_cache/
148
+ .dmypy.json
149
+ dmypy.json
150
+
151
+ # Pyre type checker
152
+ .pyre/
153
+
154
+ # pytype static type analyzer
155
+ .pytype/
156
+
157
+ # Cython debug symbols
158
+ cython_debug/
159
+
160
+ # PyCharm
161
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
162
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
163
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
164
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
165
+ #.idea/
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Chris O'Neill <chris@purplejay.io>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.3
2
+ Name: pjdev-sqlmodel
3
+ Version: 0.0.1a0
4
+ Project-URL: Documentation, https://gitlab.purplejay.net/keystone/python/-/tree/main/pjdev-sqlmodel#readme
5
+ Project-URL: Issues, https://gitlab.purplejay.net/keystone/python/issues
6
+ Project-URL: Source, https://gitlab.purplejay.net/keystone/python
7
+ Author-email: Purple Jay LLC <app-support@purplejay.io>
8
+ License-Expression: MIT
9
+ License-File: LICENSE.txt
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: Implementation :: CPython
14
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
15
+ Requires-Python: >=3.12
16
+ Requires-Dist: pydantic-settings>=2.3.4
17
+ Requires-Dist: sqlmodel>=0.0.19
18
+ Description-Content-Type: text/markdown
19
+
20
+ # pjdev-sqlmodel
21
+
22
+ [![PyPI - Version](https://img.shields.io/pypi/v/pjdev-sqlmodel.svg)](https://pypi.org/project/pjdev-sqlmodel)
23
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pjdev-sqlmodel.svg)](https://pypi.org/project/pjdev-sqlmodel)
24
+
25
+ -----
26
+
27
+ ## Table of Contents
28
+
29
+ - [Installation](#installation)
30
+ - [License](#license)
31
+
32
+ ## Installation
33
+
34
+ ```console
35
+ pip install pjdev-sqlmodel
36
+ ```
37
+
38
+ ## License
39
+
40
+ `pjdev-sqlmodel` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -0,0 +1,21 @@
1
+ # pjdev-sqlmodel
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/pjdev-sqlmodel.svg)](https://pypi.org/project/pjdev-sqlmodel)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pjdev-sqlmodel.svg)](https://pypi.org/project/pjdev-sqlmodel)
5
+
6
+ -----
7
+
8
+ ## Table of Contents
9
+
10
+ - [Installation](#installation)
11
+ - [License](#license)
12
+
13
+ ## Installation
14
+
15
+ ```console
16
+ pip install pjdev-sqlmodel
17
+ ```
18
+
19
+ ## License
20
+
21
+ `pjdev-sqlmodel` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -0,0 +1,60 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pjdev-sqlmodel"
7
+ dynamic = ["version"]
8
+ description = ''
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "MIT"
12
+ keywords = []
13
+ authors = [
14
+ { name = "Purple Jay LLC", email = "app-support@purplejay.io" },
15
+ ]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Programming Language :: Python",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: Implementation :: CPython",
21
+ "Programming Language :: Python :: Implementation :: PyPy",
22
+ ]
23
+ dependencies = [
24
+ "pydantic-settings>=2.3.4",
25
+ "sqlmodel>=0.0.19",
26
+ ]
27
+
28
+ [project.urls]
29
+ Documentation = "https://gitlab.purplejay.net/keystone/python/-/tree/main/pjdev-sqlmodel#readme"
30
+ Issues = "https://gitlab.purplejay.net/keystone/python/issues"
31
+ Source = "https://gitlab.purplejay.net/keystone/python"
32
+
33
+ [tool.hatch.version]
34
+ path = "src/pjdev_sqlmodel/__about__.py"
35
+
36
+ [tool.hatch.envs.types]
37
+ extra-dependencies = [
38
+ "mypy>=1.0.0",
39
+ ]
40
+ [tool.hatch.envs.types.scripts]
41
+ check = "mypy --install-types --non-interactive {args:src/pjdev_sqlmodel tests}"
42
+
43
+ [tool.coverage.run]
44
+ source_pkgs = ["pjdev_sqlmodel", "tests"]
45
+ branch = true
46
+ parallel = true
47
+ omit = [
48
+ "src/pjdev_sqlmodel/__about__.py",
49
+ ]
50
+
51
+ [tool.coverage.paths]
52
+ pjdev_sqlmodel = ["src/pjdev_sqlmodel", "*/pjdev-sqlmodel/src/pjdev_sqlmodel"]
53
+ tests = ["tests", "*/pjdev-sqlmodel/tests"]
54
+
55
+ [tool.coverage.report]
56
+ exclude_lines = [
57
+ "no cov",
58
+ "if __name__ == .__main__.:",
59
+ "if TYPE_CHECKING:",
60
+ ]
@@ -0,0 +1,4 @@
1
+ # SPDX-FileCopyrightText: 2024-present Chris O'Neill <chris@purplejay.io>
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ __version__ = "0.0.1a0"
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: 2024-present Chris O'Neill <chris@purplejay.io>
2
+ #
3
+ # SPDX-License-Identifier: MIT
@@ -0,0 +1,55 @@
1
+ from contextlib import contextmanager
2
+ from typing import (
3
+ Optional,
4
+ Type,
5
+ List,
6
+ )
7
+
8
+ from sqlalchemy import Engine, NullPool
9
+ from sqlmodel import SQLModel, create_engine, Session as SQLModelSession
10
+
11
+ from pjdev_sqlmodel.pjdev_db_settings import SqlModelSettings
12
+
13
+
14
+ class DBContext:
15
+ initialized: bool = False
16
+ engine: Optional[Engine] = None
17
+
18
+
19
+ __ctx = DBContext()
20
+
21
+
22
+ def init(settings: SqlModelSettings) -> None:
23
+ database_url = f"sqlite:///{settings.data_path}"
24
+ __ctx.engine = create_engine(database_url, echo=False, poolclass=NullPool)
25
+
26
+
27
+ def initialize_engine(
28
+ settings: SqlModelSettings,
29
+ tables: List[Type[SQLModel]],
30
+ echo: bool = False,
31
+ ) -> Engine:
32
+ if len(tables) == 0:
33
+ raise ValueError("Must specify at least one table")
34
+
35
+ database_url = f"sqlite:///{settings.data_path}"
36
+
37
+ engine = create_engine(database_url, echo=echo, poolclass=NullPool)
38
+
39
+ for t in tables:
40
+ t.__table__.create(bind=engine, checkfirst=True)
41
+
42
+ return engine
43
+
44
+
45
+ def configure_single_context(settings: SqlModelSettings, tables: List[Type[SQLModel]]):
46
+ __ctx.engine = initialize_engine(settings, tables)
47
+
48
+
49
+ @contextmanager
50
+ def session_context() -> SQLModelSession:
51
+ with SQLModelSession(__ctx.engine) as session:
52
+ try:
53
+ yield session
54
+ finally:
55
+ session.close()
@@ -0,0 +1,34 @@
1
+ from pathlib import Path
2
+ from typing import (
3
+ Optional,
4
+ )
5
+
6
+ from pydantic_settings import BaseSettings, SettingsConfigDict
7
+
8
+
9
+ class SqlModelSettings(BaseSettings):
10
+ data_path: Path
11
+
12
+ model_config = SettingsConfigDict(
13
+ case_sensitive=False, extra="ignore", env_prefix="PJDEV_"
14
+ )
15
+
16
+
17
+ class Context:
18
+ settings: Optional[SqlModelSettings] = None
19
+
20
+
21
+ __ctx = Context()
22
+
23
+
24
+ def init_settings(root: Path, data_directory_name: str = ".data") -> None:
25
+ __ctx.settings = SqlModelSettings(
26
+ _env_file=root / ".env", data_path=root / data_directory_name
27
+ )
28
+
29
+
30
+ def get_settings() -> SqlModelSettings:
31
+ if __ctx.settings is None:
32
+ msg = "Settings are not initialized -- call init_settings()"
33
+ raise Exception(msg)
34
+ return __ctx.settings
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: 2024-present Chris O'Neill <chris@purplejay.io>
2
+ #
3
+ # SPDX-License-Identifier: MIT