Skip to content

Commit

Permalink
Merge pull request #71 from python-ellar/ellar_updates
Browse files Browse the repository at this point in the history
Ellar 0.7.0 support
  • Loading branch information
eadwinCode authored Feb 14, 2024
2 parents 6de1741 + b3e5064 commit bc5df1b
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 43 deletions.
2 changes: 1 addition & 1 deletion ellar_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Ellar CLI Tool for Scaffolding Ellar Projects, Modules and also running Ellar Commands"""

__version__ = "0.3.4"
__version__ = "0.3.5"
3 changes: 2 additions & 1 deletion ellar_cli/click/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@
from click.utils import get_binary_stream as get_binary_stream
from click.utils import get_text_stream as get_text_stream
from click.utils import open_file as open_file
from ellar.threading import run_as_async

from .argument import Argument
from .command import Command
from .group import AppContextGroup, EllarCommandGroup
from .util import run_as_async, with_app_context
from .util import with_app_context


def argument(
Expand Down
30 changes: 2 additions & 28 deletions ellar_cli/click/util.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import asyncio
import functools
import typing as t
from functools import update_wrapper

import click
from ellar.threading.sync_worker import (
execute_async_context_manager_with_sync_worker,
execute_coroutine_with_sync_worker,
execute_async_context_manager,
)

from ellar_cli.constants import ELLAR_META
Expand All @@ -24,32 +21,9 @@ def decorator(__ctx: click.Context, *args: t.Any, **kwargs: t.Any) -> t.Any:

if meta_ and meta_.has_meta:
__ctx.with_resource(
execute_async_context_manager_with_sync_worker(
meta_.get_application_context()
)
execute_async_context_manager(meta_.get_application_context())
)

return __ctx.invoke(f, *args, **kwargs)

return update_wrapper(decorator, f)


def run_as_async(f: t.Callable) -> t.Callable:
"""
Runs async click commands
eg:
@click.command()
@click.argument('name')
@click.run_as_async
async def print_name(name: str):
click.echo(f'Hello {name}, this is an async command.')
"""
assert asyncio.iscoroutinefunction(f), "Decorated function must be Coroutine"

@functools.wraps(f)
def _decorator(*args: t.Any, **kw: t.Any) -> t.Any:
return execute_coroutine_with_sync_worker(f(*args, **kw))

return _decorator
2 changes: 1 addition & 1 deletion ellar_cli/manage_commands/create_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from importlib import import_module
from pathlib import Path

from ellar.common.utils.module_loading import module_dir
from ellar.utils.module_loading import module_dir

import ellar_cli.click as eClick
from ellar_cli import scaffolding
Expand Down
2 changes: 1 addition & 1 deletion ellar_cli/manage_commands/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from importlib import import_module
from pathlib import Path

from ellar.common.utils.module_loading import module_dir
from ellar.utils.module_loading import module_dir

import ellar_cli.click as eClick
from ellar_cli import scaffolding
Expand Down
2 changes: 1 addition & 1 deletion ellar_cli/manage_commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import typing as t

from ellar.common.utils.module_loading import module_dir
from ellar.utils.module_loading import module_dir

import ellar_cli.click as eClick
from ellar_cli import scaffolding
Expand Down
2 changes: 1 addition & 1 deletion ellar_cli/manage_commands/runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import datetime

from ellar import __version__ as ellar_version
from ellar.common.utils.enums import create_enums_from_list
from ellar.utils.enums import create_enums_from_list
from uvicorn import config as uvicorn_config
from uvicorn import run as uvicorn_run
from uvicorn.config import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def bootstrap() -> App:
# document_builder.set_title('{{project_name | capitalize}} Title') \
# .set_version('1.0.2') \
# .set_contact(name='Author Name', url='https://www.author-name.com', email='[email protected]') \
# .set_license('MIT Licence', url='https://www.google.com')
# .set_license('MIT Licence', url='https://www.google.com') \
# .add_server('/', description='Development Server')
#
# document = document_builder.build_document(application)
# module = OpenAPIDocumentModule.setup(
Expand Down
2 changes: 1 addition & 1 deletion ellar_cli/service/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from ellar.app import App
from ellar.app.context import ApplicationContext
from ellar.common.constants import ELLAR_CONFIG_MODULE
from ellar.common.utils.importer import import_from_string, module_import
from ellar.core import Config, ModuleBase
from ellar.utils.importer import import_from_string, module_import
from tomlkit import dumps as tomlkit_dumps
from tomlkit import parse as tomlkit_parse
from tomlkit.items import Table
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ classifiers = [
dependencies = [
# exclude 0.11.2 and 0.11.3 due to https://github.com/sdispater/tomlkit/issues/225
"tomlkit >=0.11.1,<1.0.0,!=0.11.2,!=0.11.3",
"uvicorn[standard] == 0.25.0",
"uvicorn[standard] == 0.27.1",
"ellar >= 0.6.6",
]

Expand Down
5 changes: 3 additions & 2 deletions tests/click/test_app_context_group.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ellar.app import current_app
from ellar.app import current_injector
from ellar.core import Config

from ellar_cli.click.group import AppContextGroup

Expand All @@ -12,7 +13,7 @@ def app_group():

@app_group.command(with_app_context=False)
def invoke_without_app_context():
assert current_app.config
assert current_injector.get(Config)
print("Application Context wont be initialized.")


Expand Down
5 changes: 3 additions & 2 deletions tests/sample_app/example_project/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ellar.app import current_config
from ellar.app import current_injector
from ellar.core import Config

import ellar_cli.click as click

Expand Down Expand Up @@ -29,5 +30,5 @@ def say_hello():
@click.with_app_context
def command_with_app_context():
print(
f"Running a command with application context - {current_config.APPLICATION_NAME}"
f"Running a command with application context - {current_injector.get(Config).APPLICATION_NAME}"
)
4 changes: 2 additions & 2 deletions tests/sample_app/plain_project/plain_project/root_module.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ellar.app import current_app
from ellar.app import current_injector
from ellar.common import (
IExecutionContext,
JSONResponse,
Expand All @@ -16,7 +16,7 @@
@click.with_app_context
def plain_project():
"""Project 2 Custom Command"""
assert isinstance(current_app.config, Config)
assert isinstance(current_injector.get(Config), Config)
print("Plain Project Command works. Executed within application context")


Expand Down

0 comments on commit bc5df1b

Please sign in to comment.