diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 29d2de6..1216ae4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,12 +17,12 @@ jobs: - name: Install Flit run: pip install flit - name: Install Dependencies - run: flit install --symlink + run: make install - name: Install build dependencies run: pip install build - name: Build distribution run: python -m build - name: Publish - uses: pypa/gh-action-pypi-publish@v1.8.11 + uses: pypa/gh-action-pypi-publish@v1.8.12 with: password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 443ce32..6dc6f9a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,8 +18,8 @@ jobs: - name: Install Flit run: pip install flit - name: Install Dependencies - run: flit install --symlink + run: make install - name: Test run: make test-cov - name: Coverage - uses: codecov/codecov-action@v4.0.1 + uses: codecov/codecov-action@v4.1.0 diff --git a/.github/workflows/test_full.yml b/.github/workflows/test_full.yml index 21b9463..fb64362 100644 --- a/.github/workflows/test_full.yml +++ b/.github/workflows/test_full.yml @@ -21,7 +21,7 @@ jobs: - name: Install Flit run: pip install flit - name: Install Dependencies - run: flit install --symlink + run: make install - name: Test run: pytest tests @@ -36,7 +36,7 @@ jobs: - name: Install Flit run: pip install flit - name: Install Dependencies - run: flit install --symlink + run: make install - name: Linting check run: ruff check ellar_sql tests - name: mypy diff --git a/Makefile b/Makefile index cd3a058..86d9962 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ clean: ## Removing cached python compiled files find . -name .ruff_cache | xargs rm -rfv install: ## Install dependencies - flit install --deps develop --symlink + pip install -r requirements.txt + flit install --symlink install-full: ## Install dependencies make install @@ -24,8 +25,8 @@ lint:fmt ## Run code linters mypy ellar_sql fmt format:clean ## Run code formatters - ruff format ellar_sql tests examples - ruff check --fix ellar_sql tests examples + ruff format ellar_sql tests samples + ruff check --fix ellar_sql tests samples test:clean ## Run tests pytest diff --git a/docs/models/index.md b/docs/models/index.md index 1ef7553..9ef1f6a 100644 --- a/docs/models/index.md +++ b/docs/models/index.md @@ -262,13 +262,13 @@ import ellar.common as ecm from ellar_sql import get_or_404, one_or_404, model @ecm.get("/user-by-id/{user_id:int}") -def user_by_id(user_id: int): - user = get_or_404(User, user_id) +async def user_by_id(user_id: int): + user = await get_or_404(User, user_id) return user.dict() @ecm.get("/user-by-name/{name:str}") -def user_by_username(name: str): - user = one_or_404(model.select(User).filter_by(name=name), error_message=f"No user named '{name}'.") +async def user_by_username(name: str): + user = await one_or_404(model.select(User).filter_by(name=name), error_message=f"No user named '{name}'.") return user.dict() ``` diff --git a/docs/overview/index.md b/docs/overview/index.md index 6c4465c..d05b42e 100644 --- a/docs/overview/index.md +++ b/docs/overview/index.md @@ -82,7 +82,7 @@ class UsersController(ecm.ControllerBase): @ecm.get("/users/{user_id:int}") def user_by_id(self, user_id: int): - user = get_or_404(User, user_id) + user = await get_or_404(User, user_id) return user.dict() @ecm.get("/") @@ -93,7 +93,7 @@ class UsersController(ecm.ControllerBase): @ecm.get("/{user_id:int}") async def user_delete(self, user_id: int, session: ecm.Inject[model.Session]): - user = get_or_404(User, user_id) + user = await get_or_404(User, user_id) session.delete(user) return {'detail': f'User id={user_id} Deleted successfully'} ``` diff --git a/ellar_sql/__init__.py b/ellar_sql/__init__.py index 200fb86..04c3003 100644 --- a/ellar_sql/__init__.py +++ b/ellar_sql/__init__.py @@ -1,6 +1,6 @@ """EllarSQL Module adds support for SQLAlchemy and Alembic package to your Ellar application""" -__version__ = "0.0.2" +__version__ = "0.0.4" from .model.database_binds import get_all_metadata, get_metadata from .module import EllarSQLModule diff --git a/ellar_sql/model/base.py b/ellar_sql/model/base.py index 4bb5d9f..6ac41a4 100644 --- a/ellar_sql/model/base.py +++ b/ellar_sql/model/base.py @@ -157,14 +157,11 @@ class ModelBase(ModelDataExportMixin): __table_args__: t.Any - def __init__(self, **kwargs: t.Any) -> None: - ... + def __init__(self, **kwargs: t.Any) -> None: ... - def _sa_inspect_type(self) -> sa.Mapper["ModelBase"]: - ... + def _sa_inspect_type(self) -> sa.Mapper["ModelBase"]: ... - def _sa_inspect_instance(self) -> sa.InstanceState["ModelBase"]: - ... + def _sa_inspect_instance(self) -> sa.InstanceState["ModelBase"]: ... @classmethod def get_db_session( diff --git a/ellar_sql/model/table.py b/ellar_sql/model/table.py index e1166cf..9c06b4c 100644 --- a/ellar_sql/model/table.py +++ b/ellar_sql/model/table.py @@ -30,8 +30,7 @@ def __init__( *args: sa_sql_schema.SchemaItem, __database__: t.Optional[str] = None, **kwargs: t.Any, - ) -> None: - ... + ) -> None: ... @t.overload def __init__( @@ -40,14 +39,12 @@ def __init__( metadata: sa.MetaData, *args: sa_sql_schema.SchemaItem, **kwargs: t.Any, - ) -> None: - ... + ) -> None: ... @t.overload def __init__( self, name: str, *args: sa_sql_schema.SchemaItem, **kwargs: t.Any - ) -> None: - ... + ) -> None: ... def __init__( self, name: str, *args: sa_sql_schema.SchemaItem, **kwargs: t.Any diff --git a/ellar_sql/pagination/view.py b/ellar_sql/pagination/view.py index 3dbf250..4304268 100644 --- a/ellar_sql/pagination/view.py +++ b/ellar_sql/pagination/view.py @@ -65,8 +65,7 @@ def pagination_context( if t.TYPE_CHECKING: - def __init__(self, **kwargs: t.Any) -> None: - ... + def __init__(self, **kwargs: t.Any) -> None: ... class PageNumberPagination(PaginationBase): diff --git a/pyproject.toml b/pyproject.toml index 3949ae4..4c50a6f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,45 +32,17 @@ classifiers = [ ] dependencies = [ - "ellar >= 0.7.0", + "ellar-cli >= 0.3.7", "sqlalchemy >= 2.0.23", "alembic >= 1.10.0" ] -dev = [ - "pre-commit" -] -doc = [ - "mkdocs >=1.1.2,<2.0.0", - "mkdocs-material >=7.1.9,<10.0.0", - "mdx-include >=1.4.1,<2.0.0", - "mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0", - "markdown-include", - "mkdocstrings", - "mkdocs-minify-plugin", - "mkdocs-git-revision-date-localized-plugin" -] - [project.urls] Documentation = "https://github.com/python-ellar/ellar-sql" Source = "https://github.com/python-ellar/ellar-sql" Homepage = "https://python-ellar.github.io/ellar-sql/" "Bug Tracker" = "https://github.com/python-ellar/ellar-sql/issues" -[project.optional-dependencies] -test = [ - "pytest >= 7.1.3,< 9.0.0", - "pytest-cov >= 2.12.0,<5.0.0", - "pytest-asyncio", - "aiosqlite", - "anyio[trio] >= 3.2.1", - "ruff ==0.1.15", - "mypy == 1.8.0", - "autoflake", - "ellar-cli >= 0.3.3", - "factory-boy >= 3.3.0" -] - [tool.ruff] select = [ "E", # pycodestyle errors diff --git a/pytest.ini b/pytest.ini index b1f9d2f..d41bf17 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,7 +2,7 @@ addopts = --strict-config --strict-markers xfail_strict = true junit_family = "xunit2" -norecursedirs = examples/* +norecursedirs = samples/* [pytest-watch] runner= pytest --failed-first --maxfail=1 --no-success-flaky-report diff --git a/requirements-docs.txt b/requirements-docs.txt new file mode 100644 index 0000000..bc4600a --- /dev/null +++ b/requirements-docs.txt @@ -0,0 +1,8 @@ +markdown-include +mdx-include >=1.4.1,<2.0.0 +mkdocs >=1.1.2,<2.0.0 +mkdocs-git-revision-date-localized-plugin +mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0 +mkdocs-material >=7.1.9,<10.0.0 +mkdocs-minify-plugin +mkdocstrings[python] >=0.19.0, <0.25.0 diff --git a/requirements-tests.txt b/requirements-tests.txt new file mode 100644 index 0000000..ea6dcc4 --- /dev/null +++ b/requirements-tests.txt @@ -0,0 +1,10 @@ +aiosqlite +anyio[trio] >= 3.2.1 +autoflake +ellar-cli >= 0.3.7 +factory-boy >= 3.3.0 +mypy == 1.8.0 +pytest >= 7.1.3,< 9.0.0 +pytest-asyncio +pytest-cov >= 2.12.0,<5.0.0 +ruff ==0.3.0 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8abc45a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +-e . +-r requirements-docs.txt +-r requirements-tests.txt + +pre-commit >=2.17.0,<4.0.0 diff --git a/examples/db-learning/README.md b/samples/db-learning/README.md similarity index 100% rename from examples/db-learning/README.md rename to samples/db-learning/README.md diff --git a/examples/db-learning/db_learning/__init__.py b/samples/db-learning/db_learning/__init__.py similarity index 100% rename from examples/db-learning/db_learning/__init__.py rename to samples/db-learning/db_learning/__init__.py diff --git a/examples/db-learning/db_learning/command.py b/samples/db-learning/db_learning/command.py similarity index 100% rename from examples/db-learning/db_learning/command.py rename to samples/db-learning/db_learning/command.py diff --git a/examples/db-learning/db_learning/config.py b/samples/db-learning/db_learning/config.py similarity index 96% rename from examples/db-learning/db_learning/config.py rename to samples/db-learning/db_learning/config.py index 716ab46..f453d54 100644 --- a/examples/db-learning/db_learning/config.py +++ b/samples/db-learning/db_learning/config.py @@ -61,9 +61,9 @@ class BaseConfig(ConfigDefaultTypesMixin): EXCEPTION_HANDLERS: t.List[IExceptionHandler] = [] # Object Serializer custom encoders - SERIALIZER_CUSTOM_ENCODER: t.Dict[ - t.Any, t.Callable[[t.Any], t.Any] - ] = encoders_by_type + SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = ( + encoders_by_type + ) class DevelopmentConfig(BaseConfig): diff --git a/examples/db-learning/db_learning/controller.py b/samples/db-learning/db_learning/controller.py similarity index 100% rename from examples/db-learning/db_learning/controller.py rename to samples/db-learning/db_learning/controller.py diff --git a/examples/db-learning/db_learning/migrations/README b/samples/db-learning/db_learning/migrations/README similarity index 100% rename from examples/db-learning/db_learning/migrations/README rename to samples/db-learning/db_learning/migrations/README diff --git a/examples/db-learning/db_learning/migrations/alembic.ini b/samples/db-learning/db_learning/migrations/alembic.ini similarity index 100% rename from examples/db-learning/db_learning/migrations/alembic.ini rename to samples/db-learning/db_learning/migrations/alembic.ini diff --git a/examples/db-learning/db_learning/migrations/env.py b/samples/db-learning/db_learning/migrations/env.py similarity index 100% rename from examples/db-learning/db_learning/migrations/env.py rename to samples/db-learning/db_learning/migrations/env.py diff --git a/examples/db-learning/db_learning/migrations/script.py.mako b/samples/db-learning/db_learning/migrations/script.py.mako similarity index 100% rename from examples/db-learning/db_learning/migrations/script.py.mako rename to samples/db-learning/db_learning/migrations/script.py.mako diff --git a/examples/db-learning/db_learning/migrations/versions/2024_01_27_1031-aa924ee1b88a_initial_migration.py b/samples/db-learning/db_learning/migrations/versions/2024_01_27_1031-aa924ee1b88a_initial_migration.py similarity index 99% rename from examples/db-learning/db_learning/migrations/versions/2024_01_27_1031-aa924ee1b88a_initial_migration.py rename to samples/db-learning/db_learning/migrations/versions/2024_01_27_1031-aa924ee1b88a_initial_migration.py index 5da3b82..718fa2d 100644 --- a/examples/db-learning/db_learning/migrations/versions/2024_01_27_1031-aa924ee1b88a_initial_migration.py +++ b/samples/db-learning/db_learning/migrations/versions/2024_01_27_1031-aa924ee1b88a_initial_migration.py @@ -5,6 +5,7 @@ Create Date: 2024-01-27 10:31:22.187308 """ + import sqlalchemy as sa from alembic import op diff --git a/examples/db-learning/db_learning/models.py b/samples/db-learning/db_learning/models.py similarity index 100% rename from examples/db-learning/db_learning/models.py rename to samples/db-learning/db_learning/models.py diff --git a/examples/db-learning/db_learning/pagination/__init__.py b/samples/db-learning/db_learning/pagination/__init__.py similarity index 100% rename from examples/db-learning/db_learning/pagination/__init__.py rename to samples/db-learning/db_learning/pagination/__init__.py diff --git a/examples/db-learning/db_learning/pagination/api.py b/samples/db-learning/db_learning/pagination/api.py similarity index 100% rename from examples/db-learning/db_learning/pagination/api.py rename to samples/db-learning/db_learning/pagination/api.py diff --git a/examples/db-learning/db_learning/pagination/template.py b/samples/db-learning/db_learning/pagination/template.py similarity index 100% rename from examples/db-learning/db_learning/pagination/template.py rename to samples/db-learning/db_learning/pagination/template.py diff --git a/examples/db-learning/db_learning/root_module.py b/samples/db-learning/db_learning/root_module.py similarity index 100% rename from examples/db-learning/db_learning/root_module.py rename to samples/db-learning/db_learning/root_module.py diff --git a/examples/db-learning/db_learning/server.py b/samples/db-learning/db_learning/server.py similarity index 100% rename from examples/db-learning/db_learning/server.py rename to samples/db-learning/db_learning/server.py diff --git a/examples/db-learning/db_learning/templates/list.html b/samples/db-learning/db_learning/templates/list.html similarity index 100% rename from examples/db-learning/db_learning/templates/list.html rename to samples/db-learning/db_learning/templates/list.html diff --git a/examples/db-learning/manage.py b/samples/db-learning/manage.py similarity index 100% rename from examples/db-learning/manage.py rename to samples/db-learning/manage.py diff --git a/examples/db-learning/requirements.txt b/samples/db-learning/requirements.txt similarity index 100% rename from examples/db-learning/requirements.txt rename to samples/db-learning/requirements.txt diff --git a/examples/db-learning/tests/__init__.py b/samples/db-learning/tests/__init__.py similarity index 100% rename from examples/db-learning/tests/__init__.py rename to samples/db-learning/tests/__init__.py diff --git a/examples/db-learning/tests/common.py b/samples/db-learning/tests/common.py similarity index 100% rename from examples/db-learning/tests/common.py rename to samples/db-learning/tests/common.py diff --git a/examples/db-learning/tests/conftest.py b/samples/db-learning/tests/conftest.py similarity index 100% rename from examples/db-learning/tests/conftest.py rename to samples/db-learning/tests/conftest.py diff --git a/examples/db-learning/tests/factories.py b/samples/db-learning/tests/factories.py similarity index 100% rename from examples/db-learning/tests/factories.py rename to samples/db-learning/tests/factories.py diff --git a/examples/db-learning/tests/test_user_model.py b/samples/db-learning/tests/test_user_model.py similarity index 100% rename from examples/db-learning/tests/test_user_model.py rename to samples/db-learning/tests/test_user_model.py diff --git a/examples/index-script/main.py b/samples/index-script/main.py similarity index 100% rename from examples/index-script/main.py rename to samples/index-script/main.py diff --git a/examples/single-db/README.md b/samples/single-db/README.md similarity index 98% rename from examples/single-db/README.md rename to samples/single-db/README.md index 4e9d856..eb6eb8b 100644 --- a/examples/single-db/README.md +++ b/samples/single-db/README.md @@ -23,4 +23,4 @@ ellar db upgrade ```shell ellar runserver --reload ``` -then, visit [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) \ No newline at end of file +then, visit [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs) diff --git a/examples/single-db/db/__init__.py b/samples/single-db/db/__init__.py similarity index 100% rename from examples/single-db/db/__init__.py rename to samples/single-db/db/__init__.py diff --git a/examples/single-db/db/controllers.py b/samples/single-db/db/controllers.py similarity index 100% rename from examples/single-db/db/controllers.py rename to samples/single-db/db/controllers.py diff --git a/examples/single-db/db/migrations/README b/samples/single-db/db/migrations/README similarity index 100% rename from examples/single-db/db/migrations/README rename to samples/single-db/db/migrations/README diff --git a/examples/single-db/db/migrations/alembic.ini b/samples/single-db/db/migrations/alembic.ini similarity index 100% rename from examples/single-db/db/migrations/alembic.ini rename to samples/single-db/db/migrations/alembic.ini diff --git a/examples/single-db/db/migrations/env.py b/samples/single-db/db/migrations/env.py similarity index 100% rename from examples/single-db/db/migrations/env.py rename to samples/single-db/db/migrations/env.py diff --git a/examples/single-db/db/migrations/script.py.mako b/samples/single-db/db/migrations/script.py.mako similarity index 100% rename from examples/single-db/db/migrations/script.py.mako rename to samples/single-db/db/migrations/script.py.mako diff --git a/examples/single-db/db/migrations/versions/2024_01_01_1016-cce418606c45_.py b/samples/single-db/db/migrations/versions/2024_01_01_1016-cce418606c45_.py similarity index 99% rename from examples/single-db/db/migrations/versions/2024_01_01_1016-cce418606c45_.py rename to samples/single-db/db/migrations/versions/2024_01_01_1016-cce418606c45_.py index 2c7151c..9d891d6 100644 --- a/examples/single-db/db/migrations/versions/2024_01_01_1016-cce418606c45_.py +++ b/samples/single-db/db/migrations/versions/2024_01_01_1016-cce418606c45_.py @@ -5,6 +5,7 @@ Create Date: 2024-01-01 10:16:49.511421 """ + import sqlalchemy as sa from alembic import op diff --git a/examples/single-db/db/models/__init__.py b/samples/single-db/db/models/__init__.py similarity index 100% rename from examples/single-db/db/models/__init__.py rename to samples/single-db/db/models/__init__.py diff --git a/examples/single-db/db/models/base.py b/samples/single-db/db/models/base.py similarity index 100% rename from examples/single-db/db/models/base.py rename to samples/single-db/db/models/base.py diff --git a/examples/single-db/db/models/users.py b/samples/single-db/db/models/users.py similarity index 100% rename from examples/single-db/db/models/users.py rename to samples/single-db/db/models/users.py diff --git a/examples/single-db/db/module.py b/samples/single-db/db/module.py similarity index 99% rename from examples/single-db/db/module.py rename to samples/single-db/db/module.py index 0dfb75a..07b1275 100644 --- a/examples/single-db/db/module.py +++ b/samples/single-db/db/module.py @@ -17,6 +17,7 @@ def register_providers(self, container: Container) -> None: pass """ + from ellar.app import App from ellar.common import IApplicationStartup, Module from ellar.core import ModuleBase diff --git a/examples/single-db/db/tests/__init__.py b/samples/single-db/db/tests/__init__.py similarity index 100% rename from examples/single-db/db/tests/__init__.py rename to samples/single-db/db/tests/__init__.py diff --git a/examples/single-db/db/tests/test_controllers.py b/samples/single-db/db/tests/test_controllers.py similarity index 100% rename from examples/single-db/db/tests/test_controllers.py rename to samples/single-db/db/tests/test_controllers.py diff --git a/examples/single-db/db/tests/test_routers.py b/samples/single-db/db/tests/test_routers.py similarity index 100% rename from examples/single-db/db/tests/test_routers.py rename to samples/single-db/db/tests/test_routers.py diff --git a/examples/single-db/db/tests/test_services.py b/samples/single-db/db/tests/test_services.py similarity index 100% rename from examples/single-db/db/tests/test_services.py rename to samples/single-db/db/tests/test_services.py diff --git a/examples/single-db/pyproject.toml b/samples/single-db/pyproject.toml similarity index 100% rename from examples/single-db/pyproject.toml rename to samples/single-db/pyproject.toml diff --git a/examples/single-db/single_db/__init__.py b/samples/single-db/single_db/__init__.py similarity index 100% rename from examples/single-db/single_db/__init__.py rename to samples/single-db/single_db/__init__.py diff --git a/examples/single-db/single_db/config.py b/samples/single-db/single_db/config.py similarity index 96% rename from examples/single-db/single_db/config.py rename to samples/single-db/single_db/config.py index 95ea24d..c9805cd 100644 --- a/examples/single-db/single_db/config.py +++ b/samples/single-db/single_db/config.py @@ -61,9 +61,9 @@ class BaseConfig(ConfigDefaultTypesMixin): EXCEPTION_HANDLERS: t.List[IExceptionHandler] = [] # Object Serializer custom encoders - SERIALIZER_CUSTOM_ENCODER: t.Dict[ - t.Any, t.Callable[[t.Any], t.Any] - ] = encoders_by_type + SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = ( + encoders_by_type + ) class DevelopmentConfig(BaseConfig): diff --git a/examples/single-db/single_db/root_module.py b/samples/single-db/single_db/root_module.py similarity index 100% rename from examples/single-db/single_db/root_module.py rename to samples/single-db/single_db/root_module.py diff --git a/examples/single-db/single_db/server.py b/samples/single-db/single_db/server.py similarity index 100% rename from examples/single-db/single_db/server.py rename to samples/single-db/single_db/server.py diff --git a/examples/single-db/tests/conftest.py b/samples/single-db/tests/conftest.py similarity index 100% rename from examples/single-db/tests/conftest.py rename to samples/single-db/tests/conftest.py pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy