Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tsiresymila1 committed Feb 26, 2024
1 parent 91b7198 commit a443f22
Show file tree
Hide file tree
Showing 172 changed files with 628 additions and 125 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/git_toolbox_prj.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
2 changes: 1 addition & 1 deletion exemple/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_DATABASE=pesty
DB_DATABASE=nestipy
6 changes: 3 additions & 3 deletions exemple/app_middleware.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pesty.common.decorator.injectable import Injectable
from pesty.common.decorator.middleware import PestyMiddleware
from nestipy.common.decorator.injectable import Injectable
from nestipy.common.decorator.middleware import NestipyMiddleware


@Injectable()
class AppMiddleware(PestyMiddleware):
class AppMiddleware(NestipyMiddleware):
def use(self, scope, receive, send):
pass
16 changes: 8 additions & 8 deletions exemple/app_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from app_middleware import AppMiddleware
from src.graphql.graphql_module import GraphqlModule
from pesty.common.decorator.module import Module
from pesty.core.module.pesty import PestyModule
from pesty.plugins.config_module.config_module import ConfigModule
from pesty.plugins.config_module.config_service import ConfigService
from pesty.plugins.dynamic_module.dynamic_module import ModuleOption
from pesty.plugins.peewee_module.peewee_module import PeeweeModule
from pesty.plugins.strawberry_module.strawberry_module import StrawberryModule
from nestipy.common.decorator.module import Module
from nestipy.core.module.nestipy import NestipyModule
from nestipy.plugins.config_module.config_module import ConfigModule
from nestipy.plugins.config_module.config_service import ConfigService
from nestipy.plugins.dynamic_module.dynamic_module import ModuleOption
from nestipy.plugins.peewee_module.peewee_module import PeeweeModule
from nestipy.plugins.strawberry_module.strawberry_module import StrawberryModule
from src.auth.auth_module import AuthModule
from src.user.user_module import UserModule

Expand Down Expand Up @@ -40,7 +40,7 @@ async def database_factory(config: ConfigService):
],
providers=[AppMiddleware]
)
class AppModule(PestyModule):
class AppModule(NestipyModule):

def on_startup(self):
pass
4 changes: 2 additions & 2 deletions exemple/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import uvicorn

from app_module import AppModule
from pesty.core.factory import AppPestyFactory
from nestipy.core.factory import AppNestipyFactory

app = AppPestyFactory.create(AppModule, title="My app")
app = AppNestipyFactory.create(AppModule, title="My app")

if __name__ == '__main__':
uvicorn.run('main:app', host="0.0.0.0", port=8000, reload=True)
6 changes: 3 additions & 3 deletions exemple/src/auth/auth_controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pesty.common.decorator.controller import Controller
from pesty.common.decorator.inject import Inject
from pesty.common.decorator.methods import Post
from nestipy.common.decorator.controller import Controller
from nestipy.common.decorator.inject import Inject
from nestipy.common.decorator.methods import Post
from .auth_service import AuthService


Expand Down
2 changes: 1 addition & 1 deletion exemple/src/auth/auth_module.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pesty.common.decorator.module import Module
from nestipy.common.decorator.module import Module
from .auth_controller import AuthController
from .auth_service import AuthService

Expand Down
2 changes: 1 addition & 1 deletion exemple/src/auth/auth_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pesty.common.decorator.injectable import Injectable
from nestipy.common.decorator.injectable import Injectable


@Injectable()
Expand Down
Binary file modified exemple/src/graphql/__pycache__/graphql_module.cpython-311.pyc
Binary file not shown.
Binary file modified exemple/src/graphql/__pycache__/graphql_resolver.cpython-311.pyc
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion exemple/src/graphql/graphql_module.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from exemple.src.graphql.graphql_resolver import GraphqlResolver
from exemple.src.graphql.graphql_service import GraphqlService
from exemple.src.user.user_module import UserModule
from pesty.common.decorator import Module
from nestipy.common.decorator import Module


@Module(providers=[GraphqlService, GraphqlResolver], imports=[UserModule])
Expand Down
4 changes: 2 additions & 2 deletions exemple/src/graphql/graphql_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from strawberry.types import Info

from exemple.src.graphql.graphql_service import GraphqlService
from pesty.common.decorator import Inject
from pesty.plugins.strawberry_module.decorator import Resolver, Query, Mutation
from nestipy.common.decorator import Inject
from nestipy.plugins.strawberry_module.decorator import Resolver, Query, Mutation


@Resolver()
Expand Down
2 changes: 1 addition & 1 deletion exemple/src/graphql/graphql_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from exemple.src.user import UserService
from pesty.common.decorator import Injectable, Inject
from nestipy.common.decorator import Injectable, Inject


@Injectable()
Expand Down
Binary file modified exemple/src/user/__pycache__/user_module.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion exemple/src/user/entities/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from peewee import TextField, IntegerField

from pesty.plugins.peewee_module.decorator import Model
from nestipy.plugins.peewee_module.decorator import Model


@Model
Expand Down
4 changes: 2 additions & 2 deletions exemple/src/user/user_auth_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pesty.common.decorator.inject import Inject
from pesty.common.decorator.injectable import Injectable
from nestipy.common.decorator.inject import Inject
from nestipy.common.decorator.injectable import Injectable
from ..auth import AuthService
from ..user.entities.user import User

Expand Down
8 changes: 4 additions & 4 deletions exemple/src/user/user_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pesty.common.decorator.controller import Controller
from pesty.common.decorator.inject import Inject
from pesty.common.decorator.methods import Get, Post
from pesty.common.decorator.middleware import Middleware
from nestipy.common.decorator.controller import Controller
from nestipy.common.decorator.inject import Inject
from nestipy.common.decorator.methods import Get, Post
from nestipy.common.decorator.middleware import Middleware
from .user_middleware import UserMiddleware, create_middleware
from ..auth.auth_service import AuthService
from .dto import CreateUserDto
Expand Down
4 changes: 2 additions & 2 deletions exemple/src/user/user_middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pesty.common.decorator.middleware import Middleware, PestyMiddleware
from nestipy.common.decorator.middleware import Middleware, NestipyMiddleware


class UserMiddleware(PestyMiddleware):
class UserMiddleware(NestipyMiddleware):

def use(self, scope, receive, send):
print('UserMiddleware called ')
Expand Down
4 changes: 2 additions & 2 deletions exemple/src/user/user_module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pesty.common.decorator.module import Module
from pesty.plugins.peewee_module.peewee_module import PeeweeModule
from nestipy.common.decorator.module import Module
from nestipy.plugins.peewee_module.peewee_module import PeeweeModule
from .entities.user import User
from .user_auth_service import UserAuthService
from .user_controller import UserController
Expand Down
8 changes: 4 additions & 4 deletions exemple/src/user/user_service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pesty.common.decorator.inject import Inject
from pesty.common.decorator.injectable import Injectable
from pesty.plugins.config_module.config_service import ConfigService
from pesty.plugins.peewee_module.peewee_service import PeeweeService
from nestipy.common.decorator.inject import Inject
from nestipy.common.decorator.injectable import Injectable
from nestipy.plugins.config_module.config_service import ConfigService
from nestipy.plugins.peewee_module.peewee_service import PeeweeService
from ..auth import AuthService
from .dto import CreateUserDto
from .entities.user import User
Expand Down
2 changes: 1 addition & 1 deletion exemple/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def Model(cls):
return type(cls.__name__, (BaseModel,), class_attrs)


db = MySQLDatabase('pesty', host='localhost', port=3306, user='root', password='')
db = MySQLDatabase('nestipy', host='localhost', port=3306, user='root', password='')


@Model
Expand Down
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tool.poetry]
name = "pesty"
name = "nestipy"
version = "0.1.0"
description = ""
authors = ["tsiresymila <[email protected]>"]
readme = "README.md"
packages = [{include = "pesty", from = "src"}]
packages = [{include = "nestipy", from = "src"}]

[tool.poetry.dependencies]
python = "^3.11"
Expand All @@ -18,8 +18,12 @@ minijinja = "^1.0.8"
pyee = "^11.1.0"
snakecase = "^1.0.1"
strawberry-graphql = "^0.219.2"
pathlib2 = "^2.3.7.post1"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
nestipy = "nestipy.cli.cli:main"
File renamed without changes.
Binary file added src/nestipy/cli/__pycache__/cli.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added src/nestipy/cli/__pycache__/style.cpython-311.pyc
Binary file not shown.
96 changes: 96 additions & 0 deletions src/nestipy/cli/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import click

from nestipy.cli.handler import NestipyCliHandler
from nestipy.cli.style import CliStyle

handler = NestipyCliHandler()
echo = CliStyle()


@click.group()
def main():
pass


@main.command()
@click.argument('name')
def new(name):
""" Create new project """
# if not shutil.which('poetry'):
click.clear()
created = handler.create_project(name)
if not created:
echo.error(f"Folder {name} already exist.")
echo.info(f"Project {name} created successfully.\nStart your project by running:\n\tcd {name}"
f"\n\tpython -m pip install -r requirements.py\n\tpython main.py")
# else:
# echo.error(f"Nestipy need poetry as dependency manager.")


@main.group(name='generate')
def make():
""" Generate resource, module, controller, service, resolver, graphql input """
pass


@make.command(name='resource')
@click.argument('name')
def resource(name):
"""Create new resource for project."""
name = str(name).lower()
choice = click.prompt('Select resource type:', type=click.Choice(['api', 'graphql'], case_sensitive=False))
if choice == 'graphql':
handler.generate_resource_graphql(name)
else:
handler.generate_resource_api(name)
echo.success(f"Resource created successfully inside src/{name}."
f"\nDon't forget to include {name.capitalize()}Module as imports of AppModule")


@make.command()
@click.argument('name')
def module(name):
"""Create new module"""
name = str(name).lower()
handler.generate_module(name, prefix='single')
echo.success(f"Module created successfully inside src/{name}."
f"\nDon't forget to include {name.capitalize()}Module as imports of AppModule")


@make.command()
@click.argument('name')
def controller(name):
""" Create new controller """
name = str(name).lower()
handler.generate_controller(name, prefix='single')
echo.success(f"Controller created successfully inside src/{name}.")


@make.command()
@click.argument('name')
def resolver(name):
""" Create new graphql resolver """
handler.generate_resolver(name, prefix='single')
echo.success(f"Resolver created successfully inside src/{name}.")


@make.command()
@click.argument('name')
def service(name):
""" Create new service """
name = str(name).lower()
handler.generate_service(name, prefix='single')
echo.success(f"Service created successfully inside src/{name}.")


@make.command(name='input')
@click.argument('name')
def graphql_input(name):
""" Create new service """
name = str(name).lower()
handler.generate_service(name, prefix='single')
echo.success(f"Graphql Input created successfully inside src/{name}.")


if __name__ == "__main__":
main()
Loading

0 comments on commit a443f22

Please sign in to comment.