From 6bb3d1837312f86b0d4f51dcca36ac4d45f904a4 Mon Sep 17 00:00:00 2001 From: aarizona Date: Thu, 2 May 2024 11:51:56 +0300 Subject: [PATCH] 1st --- .gitignore | 3 + .vscode/PythonImportHelper-v2-Completion.json | 204 ++++++++++++++++++ app/constants.py | 11 + app/main.py | 17 ++ pyproject.toml | 28 +++ readme.md | 4 + 6 files changed, 267 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/PythonImportHelper-v2-Completion.json create mode 100644 app/constants.py create mode 100644 app/main.py create mode 100644 pyproject.toml create mode 100644 readme.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7142ef8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.venv/ +__pycache__/ +poetry.lock \ No newline at end of file diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json new file mode 100644 index 0000000..a939be4 --- /dev/null +++ b/.vscode/PythonImportHelper-v2-Completion.json @@ -0,0 +1,204 @@ +[ + { + "label": "annotations", + "importPath": "__future__", + "description": "__future__", + "isExtraImport": true, + "detail": "__future__", + "documentation": {} + }, + { + "label": "os", + "kind": 6, + "isExtraImport": true, + "importPath": "os", + "description": "os", + "detail": "os", + "documentation": {} + }, + { + "label": "site", + "kind": 6, + "isExtraImport": true, + "importPath": "site", + "description": "site", + "detail": "site", + "documentation": {} + }, + { + "label": "sys", + "kind": 6, + "isExtraImport": true, + "importPath": "sys", + "description": "sys", + "detail": "sys", + "documentation": {} + }, + { + "label": "logging", + "kind": 6, + "isExtraImport": true, + "importPath": "logging", + "description": "logging", + "detail": "logging", + "documentation": {} + }, + { + "label": "uuid", + "kind": 6, + "isExtraImport": true, + "importPath": "uuid", + "description": "uuid", + "detail": "uuid", + "documentation": {} + }, + { + "label": "load_dotenv", + "importPath": "dotenv", + "description": "dotenv", + "isExtraImport": true, + "detail": "dotenv", + "documentation": {} + }, + { + "label": "Union", + "importPath": "typing", + "description": "typing", + "isExtraImport": true, + "detail": "typing", + "documentation": {} + }, + { + "label": "FastAPI", + "importPath": "fastapi", + "description": "fastapi", + "isExtraImport": true, + "detail": "fastapi", + "documentation": {} + }, + { + "label": "logger", + "importPath": "app.constants", + "description": "app.constants", + "isExtraImport": true, + "detail": "app.constants", + "documentation": {} + }, + { + "label": "bin_dir", + "kind": 5, + "importPath": ".venv.bin.activate_this", + "description": ".venv.bin.activate_this", + "peekOfCode": "bin_dir = os.path.dirname(abs_file)\nbase = bin_dir[: -len(\"bin\") - 1] # strip away the bin part from the __file__, plus the path separator\n# prepend bin to PATH (this file is inside the bin directory)\nos.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"gitea-integration-py3.10\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))", + "detail": ".venv.bin.activate_this", + "documentation": {} + }, + { + "label": "base", + "kind": 5, + "importPath": ".venv.bin.activate_this", + "description": ".venv.bin.activate_this", + "peekOfCode": "base = bin_dir[: -len(\"bin\") - 1] # strip away the bin part from the __file__, plus the path separator\n# prepend bin to PATH (this file is inside the bin directory)\nos.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"gitea-integration-py3.10\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path.decode(\"utf-8\") if \"\" else path)", + "detail": ".venv.bin.activate_this", + "documentation": {} + }, + { + "label": "os.environ[\"PATH\"]", + "kind": 5, + "importPath": ".venv.bin.activate_this", + "description": ".venv.bin.activate_this", + "peekOfCode": "os.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"gitea-integration-py3.10\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path.decode(\"utf-8\") if \"\" else path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix", + "detail": ".venv.bin.activate_this", + "documentation": {} + }, + { + "label": "os.environ[\"VIRTUAL_ENV\"]", + "kind": 5, + "importPath": ".venv.bin.activate_this", + "description": ".venv.bin.activate_this", + "peekOfCode": "os.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"gitea-integration-py3.10\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path.decode(\"utf-8\") if \"\" else path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base", + "detail": ".venv.bin.activate_this", + "documentation": {} + }, + { + "label": "os.environ[\"VIRTUAL_ENV_PROMPT\"]", + "kind": 5, + "importPath": ".venv.bin.activate_this", + "description": ".venv.bin.activate_this", + "peekOfCode": "os.environ[\"VIRTUAL_ENV_PROMPT\"] = \"gitea-integration-py3.10\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path.decode(\"utf-8\") if \"\" else path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base", + "detail": ".venv.bin.activate_this", + "documentation": {} + }, + { + "label": "prev_length", + "kind": 5, + "importPath": ".venv.bin.activate_this", + "description": ".venv.bin.activate_this", + "peekOfCode": "prev_length = len(sys.path)\nfor lib in \"../lib/python3.10/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path.decode(\"utf-8\") if \"\" else path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base", + "detail": ".venv.bin.activate_this", + "documentation": {} + }, + { + "label": "sys.path[:]", + "kind": 5, + "importPath": ".venv.bin.activate_this", + "description": ".venv.bin.activate_this", + "peekOfCode": "sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base", + "detail": ".venv.bin.activate_this", + "documentation": {} + }, + { + "label": "sys.real_prefix", + "kind": 5, + "importPath": ".venv.bin.activate_this", + "description": ".venv.bin.activate_this", + "peekOfCode": "sys.real_prefix = sys.prefix\nsys.prefix = base", + "detail": ".venv.bin.activate_this", + "documentation": {} + }, + { + "label": "sys.prefix", + "kind": 5, + "importPath": ".venv.bin.activate_this", + "description": ".venv.bin.activate_this", + "peekOfCode": "sys.prefix = base", + "detail": ".venv.bin.activate_this", + "documentation": {} + }, + { + "label": "logger", + "kind": 5, + "importPath": "app.constants", + "description": "app.constants", + "peekOfCode": "logger = logging.getLogger(__name__)", + "detail": "app.constants", + "documentation": {} + }, + { + "label": "read_root", + "kind": 2, + "importPath": "app.main", + "description": "app.main", + "peekOfCode": "def read_root():\n return {\"Hello\": \"World\"}\n@app.post(\"/integration\")\ndef intgr(body):\n logger.info(body)\n return {\"status\": \"success\"}", + "detail": "app.main", + "documentation": {} + }, + { + "label": "intgr", + "kind": 2, + "importPath": "app.main", + "description": "app.main", + "peekOfCode": "def intgr(body):\n logger.info(body)\n return {\"status\": \"success\"}", + "detail": "app.main", + "documentation": {} + }, + { + "label": "app", + "kind": 5, + "importPath": "app.main", + "description": "app.main", + "peekOfCode": "app = FastAPI()\n@app.get(\"/\")\ndef read_root():\n return {\"Hello\": \"World\"}\n@app.post(\"/integration\")\ndef intgr(body):\n logger.info(body)\n return {\"status\": \"success\"}", + "detail": "app.main", + "documentation": {} + } +] \ No newline at end of file diff --git a/app/constants.py b/app/constants.py new file mode 100644 index 0000000..40c4966 --- /dev/null +++ b/app/constants.py @@ -0,0 +1,11 @@ +import logging +import uuid +from dotenv import load_dotenv + +load_dotenv() +logging.basicConfig( + format="%(asctime)s - %(name)s - %(filename)s:%(lineno)d %(levelname)s - %(message)s", + level=logging.INFO, +) +logging.getLogger("httpx").setLevel(logging.WARNING) +logger = logging.getLogger(__name__) diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..72bec1c --- /dev/null +++ b/app/main.py @@ -0,0 +1,17 @@ +from typing import Union +from fastapi import FastAPI + +from app.constants import logger + +app = FastAPI() + + +@app.get("/") +def read_root(): + return {"Hello": "World"} + + +@app.post("/integration") +def intgr(body): + logger.info(body) + return {"status": "success"} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6222fa7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,28 @@ +[tool.poetry] +name = "gitea-integration" +version = "0.1.0" +description = "" +authors = ["aarizona "] +readme = "README.md" +package-mode = false + +[tool.poetry.dependencies] +python = "^3.10" +fastapi = "^0.110.3" +uvicorn = "^0.29.0" +python-dotenv = "^1.0.1" + + +[tool.poetry.group.dev.dependencies] +taskipy = "^1.12.2" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.taskipy.tasks] +# Launch Commands for Local Development +app = "uvicorn app.main:app --reload" +# Docker-Compose Tasks +# compose-up = "docker-compose -f docker-compose.local.yml -f docker-compose.worker.yml -f docker-compose.yml up --build" +# compose-down = "docker-compose -f docker-compose.local.yml -f docker-compose.worker.yml -f docker-compose.yml down --remove-orphans" diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..46d29e0 --- /dev/null +++ b/readme.md @@ -0,0 +1,4 @@ +# gitea webhook fastapi app + +## start ++ `poetry run task app` \ No newline at end of file