-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from python-ellar/new_command_template
New command template
- Loading branch information
Showing
21 changed files
with
313 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.3" | ||
__version__ = "0.3.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
ellar_cli/scaffolding/new_manage_template/folder_name/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# {{project_name}} | ||
Project Description | ||
|
||
## Requirements | ||
Python >= 3.8 | ||
ellar | ||
|
||
## Project setup | ||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### Development Server | ||
``` | ||
python manage.py runserver --reload | ||
``` |
13 changes: 13 additions & 0 deletions
13
ellar_cli/scaffolding/new_manage_template/folder_name/manage.ellar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import os | ||
|
||
from ellar.common.constants import ELLAR_CONFIG_MODULE | ||
from ellar_cli.main import create_ellar_cli | ||
|
||
|
||
if __name__ == '__main__': | ||
os.environ.setdefault(ELLAR_CONFIG_MODULE, "{{project_name}}.config:DevelopmentConfig") | ||
|
||
# initialize Commandline program | ||
cli = create_ellar_cli('{{project_name}}.server:bootstrap') | ||
# start commandline execution | ||
cli(prog_name="Ellar Web Framework CLI") |
1 change: 1 addition & 0 deletions
1
ellar_cli/scaffolding/new_manage_template/folder_name/tests/conftest.ellar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ellar.testing import Test, TestClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"context": ["folder_name", "project_name"], | ||
"files": [ | ||
{ | ||
"name": "folder_name", | ||
"is_directory": "true", | ||
"files": [ | ||
{ | ||
"name": "manage.ellar" | ||
}, | ||
{ | ||
"name": "README.md" | ||
}, | ||
{ | ||
"name": "tests", | ||
"is_directory": "true", | ||
"files": [ | ||
{ | ||
"name": "conftest.ellar" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# plain_project | ||
Project Description | ||
|
||
## Requirements | ||
Python >= 3.8 | ||
ellar | ||
|
||
## Project setup | ||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### Development Server | ||
``` | ||
python manage.py runserver --reload | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import os | ||
|
||
from ellar.common.constants import ELLAR_CONFIG_MODULE | ||
|
||
from ellar_cli.main import create_ellar_cli | ||
|
||
os.environ.setdefault(ELLAR_CONFIG_MODULE, "plain_project.config:DevelopmentConfig") | ||
|
||
|
||
if __name__ == "__main__": | ||
# initialize Commandline program | ||
cli = create_ellar_cli("plain_project.server:bootstrap") | ||
# start commandline execution | ||
cli(prog_name="Ellar Web Framework CLI") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Application Configurations | ||
Default Ellar Configurations are exposed here through `ConfigDefaultTypesMixin` | ||
Make changes and define your own configurations specific to your application | ||
export ELLAR_CONFIG_MODULE=exy.config:DevelopmentConfig | ||
""" | ||
|
||
import typing as t | ||
|
||
from ellar.common import IExceptionHandler, JSONResponse | ||
from ellar.core import ConfigDefaultTypesMixin | ||
from ellar.core.versioning import BaseAPIVersioning, DefaultAPIVersioning | ||
from ellar.pydantic import ENCODERS_BY_TYPE as encoders_by_type | ||
from starlette.middleware import Middleware | ||
|
||
|
||
class BaseConfig(ConfigDefaultTypesMixin): | ||
DEBUG: bool = False | ||
|
||
DEFAULT_JSON_CLASS: t.Type[JSONResponse] = JSONResponse | ||
SECRET_KEY: str = "ellar_fmk86xpbSS12NsbGTGw52xek6OHmRUn466hQ61iFBV4" | ||
|
||
# injector auto_bind = True allows you to resolve types that are not registered on the container | ||
# For more info, read: https://injector.readthedocs.io/en/latest/index.html | ||
INJECTOR_AUTO_BIND = False | ||
|
||
# jinja Environment options | ||
# https://jinja.palletsprojects.com/en/3.0.x/api/#high-level-api | ||
JINJA_TEMPLATES_OPTIONS: t.Dict[str, t.Any] = {} | ||
|
||
# Application route versioning scheme | ||
VERSIONING_SCHEME: BaseAPIVersioning = DefaultAPIVersioning() | ||
|
||
# Enable or Disable Application Router route searching by appending backslash | ||
REDIRECT_SLASHES: bool = False | ||
|
||
# Define references to static folders in python packages. | ||
# eg STATIC_FOLDER_PACKAGES = [('boostrap4', 'statics')] | ||
STATIC_FOLDER_PACKAGES: t.Optional[t.List[t.Union[str, t.Tuple[str, str]]]] = [] | ||
|
||
# Define references to static folders defined within the project | ||
STATIC_DIRECTORIES: t.Optional[t.List[t.Union[str, t.Any]]] = [] | ||
|
||
# static route path | ||
STATIC_MOUNT_PATH: str = "/static" | ||
|
||
CORS_ALLOW_ORIGINS: t.List[str] = ["*"] | ||
CORS_ALLOW_METHODS: t.List[str] = ["*"] | ||
CORS_ALLOW_HEADERS: t.List[str] = ["*"] | ||
ALLOWED_HOSTS: t.List[str] = ["*"] | ||
|
||
# Application middlewares | ||
MIDDLEWARE: t.Sequence[Middleware] = [] | ||
|
||
# A dictionary mapping either integer status codes, | ||
# or exception class types onto callables which handle the exceptions. | ||
# Exception handler callables should be of the form | ||
# `handler(context:IExecutionContext, exc: Exception) -> response` | ||
# and may be either standard functions, or async functions. | ||
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 | ||
|
||
|
||
class DevelopmentConfig(BaseConfig): | ||
DEBUG: bool = True |
Empty file.
Empty file.
27 changes: 27 additions & 0 deletions
27
tests/sample_app/plain_project/plain_project/root_module.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from ellar.app import current_app | ||
from ellar.common import ( | ||
IExecutionContext, | ||
JSONResponse, | ||
Module, | ||
Response, | ||
exception_handler, | ||
) | ||
from ellar.core import Config, ModuleBase | ||
from ellar.samples.modules import HomeModule | ||
|
||
import ellar_cli.click as click | ||
|
||
|
||
@click.command() | ||
@click.with_app_context | ||
def plain_project(): | ||
"""Project 2 Custom Command""" | ||
assert isinstance(current_app.config, Config) | ||
print("Plain Project Command works. Executed within application context") | ||
|
||
|
||
@Module(modules=[HomeModule], commands=[plain_project]) | ||
class ApplicationModule(ModuleBase): | ||
@exception_handler(404) | ||
def exception_404_handler(cls, ctx: IExecutionContext, exc: Exception) -> Response: | ||
return JSONResponse({"detail": "Resource not found."}, status_code=404) |
Oops, something went wrong.