Skip to content

Commit bc5df1b

Browse files
authored
Merge pull request #71 from python-ellar/ellar_updates
Ellar 0.7.0 support
2 parents 6de1741 + b3e5064 commit bc5df1b

File tree

13 files changed

+21
-43
lines changed

13 files changed

+21
-43
lines changed

ellar_cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Ellar CLI Tool for Scaffolding Ellar Projects, Modules and also running Ellar Commands"""
22

3-
__version__ = "0.3.4"
3+
__version__ = "0.3.5"

ellar_cli/click/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@
4242
from click.utils import get_binary_stream as get_binary_stream
4343
from click.utils import get_text_stream as get_text_stream
4444
from click.utils import open_file as open_file
45+
from ellar.threading import run_as_async
4546

4647
from .argument import Argument
4748
from .command import Command
4849
from .group import AppContextGroup, EllarCommandGroup
49-
from .util import run_as_async, with_app_context
50+
from .util import with_app_context
5051

5152

5253
def argument(

ellar_cli/click/util.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import asyncio
2-
import functools
31
import typing as t
42
from functools import update_wrapper
53

64
import click
75
from ellar.threading.sync_worker import (
8-
execute_async_context_manager_with_sync_worker,
9-
execute_coroutine_with_sync_worker,
6+
execute_async_context_manager,
107
)
118

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

2522
if meta_ and meta_.has_meta:
2623
__ctx.with_resource(
27-
execute_async_context_manager_with_sync_worker(
28-
meta_.get_application_context()
29-
)
24+
execute_async_context_manager(meta_.get_application_context())
3025
)
3126

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

3429
return update_wrapper(decorator, f)
35-
36-
37-
def run_as_async(f: t.Callable) -> t.Callable:
38-
"""
39-
Runs async click commands
40-
41-
eg:
42-
43-
@click.command()
44-
@click.argument('name')
45-
@click.run_as_async
46-
async def print_name(name: str):
47-
click.echo(f'Hello {name}, this is an async command.')
48-
"""
49-
assert asyncio.iscoroutinefunction(f), "Decorated function must be Coroutine"
50-
51-
@functools.wraps(f)
52-
def _decorator(*args: t.Any, **kw: t.Any) -> t.Any:
53-
return execute_coroutine_with_sync_worker(f(*args, **kw))
54-
55-
return _decorator

ellar_cli/manage_commands/create_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from importlib import import_module
55
from pathlib import Path
66

7-
from ellar.common.utils.module_loading import module_dir
7+
from ellar.utils.module_loading import module_dir
88

99
import ellar_cli.click as eClick
1010
from ellar_cli import scaffolding

ellar_cli/manage_commands/create_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from importlib import import_module
55
from pathlib import Path
66

7-
from ellar.common.utils.module_loading import module_dir
7+
from ellar.utils.module_loading import module_dir
88

99
import ellar_cli.click as eClick
1010
from ellar_cli import scaffolding

ellar_cli/manage_commands/new.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import subprocess
44
import typing as t
55

6-
from ellar.common.utils.module_loading import module_dir
6+
from ellar.utils.module_loading import module_dir
77

88
import ellar_cli.click as eClick
99
from ellar_cli import scaffolding

ellar_cli/manage_commands/runserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from datetime import datetime
66

77
from ellar import __version__ as ellar_version
8-
from ellar.common.utils.enums import create_enums_from_list
8+
from ellar.utils.enums import create_enums_from_list
99
from uvicorn import config as uvicorn_config
1010
from uvicorn import run as uvicorn_run
1111
from uvicorn.config import (

ellar_cli/scaffolding/project_template/project_name/server.ellar

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def bootstrap() -> App:
2121
# document_builder.set_title('{{project_name | capitalize}} Title') \
2222
# .set_version('1.0.2') \
2323
# .set_contact(name='Author Name', url='https://www.author-name.com', email='authorname@gmail.com') \
24-
# .set_license('MIT Licence', url='https://www.google.com')
24+
# .set_license('MIT Licence', url='https://www.google.com') \
25+
# .add_server('/', description='Development Server')
2526
#
2627
# document = document_builder.build_document(application)
2728
# module = OpenAPIDocumentModule.setup(

ellar_cli/service/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from ellar.app import App
88
from ellar.app.context import ApplicationContext
99
from ellar.common.constants import ELLAR_CONFIG_MODULE
10-
from ellar.common.utils.importer import import_from_string, module_import
1110
from ellar.core import Config, ModuleBase
11+
from ellar.utils.importer import import_from_string, module_import
1212
from tomlkit import dumps as tomlkit_dumps
1313
from tomlkit import parse as tomlkit_parse
1414
from tomlkit.items import Table

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ classifiers = [
4242
dependencies = [
4343
# exclude 0.11.2 and 0.11.3 due to https://github.com/sdispater/tomlkit/issues/225
4444
"tomlkit >=0.11.1,<1.0.0,!=0.11.2,!=0.11.3",
45-
"uvicorn[standard] == 0.25.0",
45+
"uvicorn[standard] == 0.27.1",
4646
"ellar >= 0.6.6",
4747
]
4848

tests/click/test_app_context_group.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from ellar.app import current_app
1+
from ellar.app import current_injector
2+
from ellar.core import Config
23

34
from ellar_cli.click.group import AppContextGroup
45

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

1314
@app_group.command(with_app_context=False)
1415
def invoke_without_app_context():
15-
assert current_app.config
16+
assert current_injector.get(Config)
1617
print("Application Context wont be initialized.")
1718

1819

tests/sample_app/example_project/commands.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from ellar.app import current_config
1+
from ellar.app import current_injector
2+
from ellar.core import Config
23

34
import ellar_cli.click as click
45

@@ -29,5 +30,5 @@ def say_hello():
2930
@click.with_app_context
3031
def command_with_app_context():
3132
print(
32-
f"Running a command with application context - {current_config.APPLICATION_NAME}"
33+
f"Running a command with application context - {current_injector.get(Config).APPLICATION_NAME}"
3334
)

tests/sample_app/plain_project/plain_project/root_module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ellar.app import current_app
1+
from ellar.app import current_injector
22
from ellar.common import (
33
IExecutionContext,
44
JSONResponse,
@@ -16,7 +16,7 @@
1616
@click.with_app_context
1717
def plain_project():
1818
"""Project 2 Custom Command"""
19-
assert isinstance(current_app.config, Config)
19+
assert isinstance(current_injector.get(Config), Config)
2020
print("Plain Project Command works. Executed within application context")
2121

2222

0 commit comments

Comments
 (0)