mirror of
https://github.com/ycd/manage-fastapi.git
synced 2021-11-08 01:34:39 +03:00
Release 0.1.60
Release 0.1.60
This commit is contained in:
37
README.md
37
README.md
@@ -38,8 +38,7 @@
|
||||
* #### Creates customizable **project boilerplate.**
|
||||
* #### Creates customizable **app boilerplate.**
|
||||
* #### Handles the project structing for you.
|
||||
* #### Get fancy information about your Pydantic models.
|
||||
* #### Running development server.
|
||||
|
||||
|
||||
## Starting a new project
|
||||
|
||||
@@ -79,34 +78,6 @@ fastproject/
|
||||
└── __init__.py
|
||||
```
|
||||
|
||||
## Getting information about our Pydantic models.
|
||||
|
||||
```
|
||||
manage-fastapi showmodels
|
||||
```
|
||||
|
||||
|
||||
## With this command we are getting a fancy output of our models.
|
||||
|
||||
```
|
||||
╔════════════════════════════════╗
|
||||
║ item.py ║
|
||||
║ ------- ║
|
||||
║ ItemBase ║
|
||||
║ ItemCreate ║
|
||||
║ ItemUpdate ║
|
||||
║ ItemInDBBase ║
|
||||
║ Item ║
|
||||
║ ItemInDB ║
|
||||
╚════════════════════════════════╝
|
||||
╔════════════════════════════════╗
|
||||
║ token.py ║
|
||||
║ -------- ║
|
||||
║ Token ║
|
||||
║ TokenPayload ║
|
||||
╚════════════════════════════════╝
|
||||
```
|
||||
|
||||
|
||||
## Installation :pushpin:
|
||||
|
||||
@@ -117,6 +88,12 @@ manage-fastapi showmodels
|
||||
|
||||
### Latest Changes
|
||||
|
||||
### 0.1.60
|
||||
|
||||
* Delete run-server command
|
||||
* Delete show-models command
|
||||
* Create new template for settings without database
|
||||
* Small fix for project utils
|
||||
|
||||
### 0.1.52
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
When working with bigger application sometimes, you get lost sometimes, a lot...
|
||||
|
||||
|
||||
### Manage FastAPI's **`showmodels`** goes to your **core/models** folder and creates a schema of your models.
|
||||
|
||||
|
||||
#### Let's say we have 4 folders under my **core/models**
|
||||
|
||||
- `item.py`
|
||||
- `token.py`
|
||||
- `msg.py`
|
||||
- `user.py`
|
||||
|
||||
```
|
||||
manage-fastapi showmodels
|
||||
```
|
||||
|
||||
With this command we are getting a fancy output of our models.
|
||||
|
||||
```
|
||||
╔════════════════════════════════╗
|
||||
║ item.py ║
|
||||
║ ------- ║
|
||||
║ ItemBase ║
|
||||
║ ItemCreate ║
|
||||
║ ItemUpdate ║
|
||||
║ ItemInDBBase ║
|
||||
║ Item ║
|
||||
║ ItemInDB ║
|
||||
╚════════════════════════════════╝
|
||||
╔════════════════════════════════╗
|
||||
║ token.py ║
|
||||
║ -------- ║
|
||||
║ Token ║
|
||||
║ TokenPayload ║
|
||||
╚════════════════════════════════╝
|
||||
╔════════════════════════════════╗
|
||||
║ msg.py ║
|
||||
║ ------ ║
|
||||
║ Msg ║
|
||||
╚════════════════════════════════╝
|
||||
╔════════════════════════════════╗
|
||||
║ user.py ║
|
||||
║ ------- ║
|
||||
║ UserBase ║
|
||||
║ UserCreate ║
|
||||
║ UserUpdate ║
|
||||
║ UserInDBBase ║
|
||||
║ User ║
|
||||
║ UserInDB ║
|
||||
╚════════════════════════════════╝
|
||||
```
|
||||
@@ -2,12 +2,17 @@
|
||||
|
||||
### Latest Changes
|
||||
|
||||
### 0.1.5
|
||||
### 0.1.60
|
||||
|
||||
* Added showmodels
|
||||
* Added runserver
|
||||
* Fix little bugs
|
||||
* Update docs
|
||||
* Delete run-server command
|
||||
* Delete show-models command
|
||||
* Create new template for settings without database
|
||||
* Small fix for project utils
|
||||
|
||||
|
||||
### 0.1.52
|
||||
|
||||
* Temporary fix for Path issue when running with uvicorn
|
||||
|
||||
|
||||
### 0.1.51
|
||||
|
||||
@@ -1 +1 @@
|
||||
__version__ = "0.1.52"
|
||||
__version__ = "0.1.60"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import pkg_resources
|
||||
import typer
|
||||
|
||||
from .models_utils import show_models
|
||||
from .project_utils import run_server, select_database, start_app, start_project
|
||||
|
||||
from .project_utils import select_database, start_app, start_project
|
||||
|
||||
app = typer.Typer(
|
||||
add_completion=False,
|
||||
@@ -20,16 +20,3 @@ def startproject(projectname: str = typer.Argument(...)):
|
||||
@app.command(help="Creates a app with the given name.")
|
||||
def startapp(appname: str = typer.Argument(...)):
|
||||
start_app(appname)
|
||||
|
||||
|
||||
@app.command(help="Runs the development server")
|
||||
def runserver():
|
||||
installed_pkgs = [d.project_name for d in pkg_resources.working_set]
|
||||
if "uvicorn" not in installed_pkgs:
|
||||
print(f"Default(uvicorn) server not found in installed packages.")
|
||||
run_server()
|
||||
|
||||
|
||||
@app.command(help="Shows all Pydantic models")
|
||||
def showmodels():
|
||||
show_models()
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
|
||||
|
||||
def find_models() -> Dict[str, str]:
|
||||
main_path = ""
|
||||
result = {}
|
||||
|
||||
for path, directories, files in os.walk(str(Path.cwd())):
|
||||
if "schemas" in directories:
|
||||
main_path = path + "/schemas"
|
||||
break
|
||||
|
||||
for path, directories, files in os.walk(main_path):
|
||||
for file in files:
|
||||
|
||||
class_name_list = []
|
||||
if not file.startswith("__"):
|
||||
with open(f"{path}/{file}", "r") as f:
|
||||
for line in f.read().splitlines():
|
||||
if line.startswith("class"):
|
||||
class_name = "".join(
|
||||
[i for i in (line.replace(" ", "(")).split("(")][1]
|
||||
).replace(":", "")
|
||||
class_name_list.append(class_name)
|
||||
|
||||
result.update({file: class_name_list})
|
||||
return result
|
||||
|
||||
|
||||
def msg_box(msg: str, indent: int = 1, width: int = None, title: str = None) -> str:
|
||||
space = " " * indent
|
||||
if not width:
|
||||
width = max((map(len, msg)))
|
||||
box = f'╔{"═" * (width + indent * 2)}╗\n'
|
||||
if title:
|
||||
box += f"║{space}{title:<{width}}{space}║\n"
|
||||
box += f'║{space}{"-" * len(title):<{width}}{space}║\n'
|
||||
box += "".join([f"║{space}{line:<{width}}{space}║\n" for line in msg])
|
||||
box += f'╚{"═" * (width + indent * 2)}╝'
|
||||
return box
|
||||
|
||||
|
||||
def show_models() -> str:
|
||||
models = find_models()
|
||||
for key, value in models.items():
|
||||
print(msg_box(msg=value, title=key, width=30))
|
||||
@@ -16,6 +16,7 @@ from .templates import (
|
||||
test_template,
|
||||
tortoise_database_template,
|
||||
tortoise_main_template,
|
||||
settings_without_database,
|
||||
)
|
||||
|
||||
|
||||
@@ -116,6 +117,17 @@ def start_project(
|
||||
with open(f"{current_path}/{project_name}/main.py", "a+") as main:
|
||||
main.write(empty_main_template.replace("{project_name}", project_name))
|
||||
|
||||
# Delete settings
|
||||
settings = Path(f"{current_path}/{project_name}/core/settings.py")
|
||||
settings.unlink()
|
||||
|
||||
with open(
|
||||
f"{current_path}/{project_name}/core/settings.py", "a+"
|
||||
) as settings:
|
||||
settings.write(
|
||||
settings_without_database.replace("{project_name}", project_name)
|
||||
)
|
||||
|
||||
except FileExistsError:
|
||||
print(f"Project {project_name} already exists!")
|
||||
|
||||
@@ -152,9 +164,3 @@ def start_app(app_name: str, current_path: str = Path.cwd()) -> str:
|
||||
def select_database() -> int:
|
||||
option = input(database_options_template + "Select a database: ")
|
||||
return option
|
||||
|
||||
|
||||
def run_server() -> None:
|
||||
import subprocess
|
||||
|
||||
subprocess.run(["uvicorn", "main:app", "--reload"])
|
||||
|
||||
@@ -62,6 +62,37 @@ class Settings(BaseSettings):
|
||||
case_sensitive = True
|
||||
|
||||
|
||||
settings = Settings()
|
||||
"""
|
||||
|
||||
|
||||
settings_without_database = """from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
from pydantic import BaseSettings, AnyHttpUrl, HttpUrl, validator
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
PROJECT_NAME: str = "{project_name}"
|
||||
|
||||
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = [
|
||||
"http://localhost",
|
||||
"http://localhost:80",
|
||||
"http://localhost:8000",
|
||||
]
|
||||
|
||||
@validator("BACKEND_CORS_ORIGINS", pre=True)
|
||||
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
|
||||
if isinstance(v, str) and not v.startswith("["):
|
||||
return [i.strip() for i in v.split(",")]
|
||||
elif isinstance(v, (list, str)):
|
||||
return v
|
||||
raise ValueError(v)
|
||||
|
||||
|
||||
class Config:
|
||||
case_sensitive = True
|
||||
|
||||
|
||||
settings = Settings()
|
||||
"""
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ nav:
|
||||
- Start new project: managing_projects/startproject.md
|
||||
- Manage Apps:
|
||||
- Start new app: managing_apps/startapp.md
|
||||
- Manage Models:
|
||||
- Show models: managing_models/showmodels.md
|
||||
- Release Notes: 'release-notes.md'
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "manage-fastapi"
|
||||
version = "0.1.52"
|
||||
version = "0.1.60"
|
||||
description = "Managing FastAPI projects made easy."
|
||||
authors = ["ycd <yagizcanilbey1903@gmail.com>"]
|
||||
readme = "README.md"
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
from typer.testing import CliRunner
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
# TODO add more tests
|
||||
|
||||
# def test_runserver():
|
||||
# os.system("cd test_one")
|
||||
# result = runner.invoke(app, ["runserver"])
|
||||
# assert result.exit_code == 0
|
||||
@@ -1,11 +0,0 @@
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from manage_fastapi.main import app
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
# TODO add more tests
|
||||
def test_showmodels():
|
||||
result = runner.invoke(app, ["showmodels"])
|
||||
assert result.exit_code == 0
|
||||
@@ -2,4 +2,4 @@ from manage_fastapi import __version__
|
||||
|
||||
|
||||
def test_version():
|
||||
assert __version__ == "0.1.52"
|
||||
assert __version__ == "0.1.60"
|
||||
|
||||
Reference in New Issue
Block a user