mirror of
https://github.com/ycd/manage-fastapi.git
synced 2021-11-08 01:34:39 +03:00
✨ Make docker support optional
This commit is contained in:
@@ -18,6 +18,7 @@ The package plans are here. If you want to contribute with new ideas, or develop
|
|||||||
- [ ] Integrate databases on `startproject`.
|
- [ ] Integrate databases on `startproject`.
|
||||||
- [ ] Create `migrations`/`migrate` command.
|
- [ ] Create `migrations`/`migrate` command.
|
||||||
- [ ] Different Authentication support on `startproject`.
|
- [ ] Different Authentication support on `startproject`.
|
||||||
|
- [ ] Configuration file support: being able to run `fastapi startproject --config-file myconfig`.
|
||||||
|
|
||||||
## Questions
|
## Questions
|
||||||
|
|
||||||
|
|||||||
141
haha/.gitignore
vendored
Normal file
141
haha/.gitignore
vendored
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# Text Editor
|
||||||
|
.vscode
|
||||||
36
haha/.pre-commit-config.yaml
Normal file
36
haha/.pre-commit-config.yaml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/myint/autoflake
|
||||||
|
rev: v1.4
|
||||||
|
hooks:
|
||||||
|
- id: autoflake
|
||||||
|
exclude: .*/__init__.py
|
||||||
|
args:
|
||||||
|
- --in-place
|
||||||
|
- --remove-all-unused-imports
|
||||||
|
- --expand-star-imports
|
||||||
|
- --remove-duplicate-keys
|
||||||
|
- --remove-unused-variables
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: flake8
|
||||||
|
name: flake8
|
||||||
|
entry: flake8
|
||||||
|
language: system
|
||||||
|
types: [python]
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-isort
|
||||||
|
rev: v5.4.2
|
||||||
|
hooks:
|
||||||
|
- id: isort
|
||||||
|
args: ["--profile", "black"]
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: mypy
|
||||||
|
name: mypy
|
||||||
|
entry: mypy
|
||||||
|
language: system
|
||||||
|
types: [python]
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v3.3.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
12
haha/Dockerfile
Normal file
12
haha/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
|
||||||
|
|
||||||
|
ENV PYTHONPATH "${PYTHONPATH}:/"
|
||||||
|
ENV PORT=8000
|
||||||
|
|
||||||
|
RUN pip install --upgrade pip
|
||||||
|
|
||||||
|
COPY ./requirements.txt /app/
|
||||||
|
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
COPY ./app /app
|
||||||
21
haha/LICENSE
Normal file
21
haha/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 Marcelo Trylesinski
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
7
haha/README.md
Normal file
7
haha/README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# haha
|
||||||
|
|
||||||
|
This project was generated via [manage-fastapi](https://ycd.github.io/manage-fastapi/)! :tada:
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is licensed under the terms of the MIT license.
|
||||||
0
haha/app/__init__.py
Normal file
0
haha/app/__init__.py
Normal file
0
haha/app/core/__init__.py
Normal file
0
haha/app/core/__init__.py
Normal file
@@ -16,6 +16,7 @@ class Settings(BaseSettings):
|
|||||||
raise ValueError(v)
|
raise ValueError(v)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
case_sensitive = True
|
||||||
env_file = ".env"
|
env_file = ".env"
|
||||||
|
|
||||||
|
|
||||||
21
haha/app/main.py
Normal file
21
haha/app/main.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from fastapi import FastAPI
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
|
from app.core.config import settings
|
||||||
|
|
||||||
|
|
||||||
|
def get_application():
|
||||||
|
_app = FastAPI(title=settings.PROJECT_NAME)
|
||||||
|
|
||||||
|
_app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
|
return _app
|
||||||
|
|
||||||
|
|
||||||
|
app = get_application()
|
||||||
8
haha/docker-compose.yaml
Normal file
8
haha/docker-compose.yaml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
env_file: ".env"
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
2
haha/requirements.txt
Normal file
2
haha/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fastapi==0.61.2
|
||||||
|
uvicorn==0.12.2
|
||||||
17
haha/setup.cfg
Normal file
17
haha/setup.cfg
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
[isort]
|
||||||
|
profile = black
|
||||||
|
known_first_party = app
|
||||||
|
|
||||||
|
[flake8]
|
||||||
|
max-complexity = 7
|
||||||
|
statistics = True
|
||||||
|
max-line-length = 88
|
||||||
|
ignore = W503,E203
|
||||||
|
per-file-ignores =
|
||||||
|
__init__.py: F401
|
||||||
|
|
||||||
|
[mypy]
|
||||||
|
plugins = pydantic.mypy
|
||||||
|
ignore_missing_imports = True
|
||||||
|
follow_imports = skip
|
||||||
|
strict_optional = True
|
||||||
0
haha/tests/__init__.py
Normal file
0
haha/tests/__init__.py
Normal file
@@ -1,5 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
from typing import TypeVar
|
from typing import Tuple, TypeVar
|
||||||
|
|
||||||
from bullet import Bullet, SlidePrompt, colors
|
from bullet import Bullet, SlidePrompt, colors
|
||||||
from bullet.client import YesNo
|
from bullet.client import YesNo
|
||||||
@@ -31,6 +31,7 @@ def yes_no(option: str) -> YesNo:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def launch_cli(*prompt_objs: Bullet):
|
def launch_cli(*prompt_objs: Tuple[str, Bullet]):
|
||||||
results = SlidePrompt(prompt_objs).launch()
|
names, objs = zip(*prompt_objs)
|
||||||
return [result[1] for result in results]
|
results = SlidePrompt(objs).launch()
|
||||||
|
return {name: result[1] for name, result in zip(names, results)}
|
||||||
|
|||||||
@@ -20,21 +20,17 @@ def startproject(name: str, default: bool = typer.Option(False)):
|
|||||||
python=PythonVersion.THREE_DOT_EIG,
|
python=PythonVersion.THREE_DOT_EIG,
|
||||||
license=License.MIT,
|
license=License.MIT,
|
||||||
pre_commit=True,
|
pre_commit=True,
|
||||||
|
docker=True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
result = launch_cli(
|
result = launch_cli(
|
||||||
bullet(PackageManager),
|
("packaging", bullet(PackageManager)),
|
||||||
bullet(PythonVersion),
|
("python", bullet(PythonVersion)),
|
||||||
bullet(License),
|
("license", bullet(License)),
|
||||||
yes_no("pre commit"),
|
("pre_commit", yes_no("pre commit")),
|
||||||
)
|
("docker", yes_no("docker")),
|
||||||
context = Context(
|
|
||||||
name=name,
|
|
||||||
packaging=result[0],
|
|
||||||
python=result[1],
|
|
||||||
license=result[2],
|
|
||||||
pre_commit=result[3],
|
|
||||||
)
|
)
|
||||||
|
context = Context(name=name, **result)
|
||||||
generate_project(context)
|
generate_project(context)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class Context(BaseModel):
|
|||||||
year: int
|
year: int
|
||||||
|
|
||||||
pre_commit: bool
|
pre_commit: bool
|
||||||
|
docker: bool
|
||||||
|
|
||||||
@root_validator(pre=True)
|
@root_validator(pre=True)
|
||||||
def git_info(cls, values: dict):
|
def git_info(cls, values: dict):
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "{{ cookiecutter.name }}",
|
"docker": "{{ cookiecutter.docker }}",
|
||||||
"folder_name": "{{ cookiecutter.folder_name }}",
|
|
||||||
"packaging": "{{ cookiecutter.packaging }}",
|
|
||||||
"username": "{{ cookiecutter.username }}",
|
|
||||||
"email": "{{ cookiecutter.email }}",
|
"email": "{{ cookiecutter.email }}",
|
||||||
"python": "{{ cookiecutter.python }}",
|
"env": ".env",
|
||||||
"fastapi": "{{ cookiecutter.fastapi }}",
|
"fastapi": "{{ cookiecutter.fastapi }}",
|
||||||
|
"folder_name": "{{ cookiecutter.folder_name }}",
|
||||||
"gitignore": ".gitignore",
|
"gitignore": ".gitignore",
|
||||||
"license": "{{ cookiecutter.license }}",
|
"license": "{{ cookiecutter.license }}",
|
||||||
"year": "{{ cookiecutter.year }}",
|
"name": "{{ cookiecutter.name }}",
|
||||||
"pre_commit": "{{ cookiecutter.pre_commit }}"
|
"packaging": "{{ cookiecutter.packaging }}",
|
||||||
|
"pre_commit": "{{ cookiecutter.pre_commit }}",
|
||||||
|
"python": "{{ cookiecutter.python }}",
|
||||||
|
"username": "{{ cookiecutter.username }}",
|
||||||
|
"year": "{{ cookiecutter.year }}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,16 @@ def set_pre_commit():
|
|||||||
remove_paths([".pre-commit-config.yaml", "setup.cfg"])
|
remove_paths([".pre-commit-config.yaml", "setup.cfg"])
|
||||||
|
|
||||||
|
|
||||||
|
def set_docker():
|
||||||
|
docker: bool = eval("{{ cookiecutter.docker }}")
|
||||||
|
if docker is False:
|
||||||
|
remove_paths(["Dockerfile", "docker-compose.yaml"])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
set_packaging()
|
set_packaging()
|
||||||
set_pre_commit()
|
set_pre_commit()
|
||||||
|
set_docker()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
from typing import List, Union
|
||||||
|
|
||||||
|
from pydantic import AnyHttpUrl, BaseSettings, validator
|
||||||
|
|
||||||
|
|
||||||
|
class Settings(BaseSettings):
|
||||||
|
PROJECT_NAME: str
|
||||||
|
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
|
||||||
|
|
||||||
|
@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
|
||||||
|
env_file = ".env"
|
||||||
|
|
||||||
|
|
||||||
|
settings = Settings()
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
from app.config import settings
|
from app.core.config import settings
|
||||||
|
|
||||||
|
|
||||||
def get_application():
|
def get_application():
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
PROJECT_NAME={{ cookiecutter.name }}
|
||||||
|
BACKEND_CORS_ORIGINS=["http://localhost:8000", "https://localhost:8000", "http://localhost", "https://localhost"]
|
||||||
Reference in New Issue
Block a user