diff --git a/.env b/.env deleted file mode 100644 index 0d64913..0000000 --- a/.env +++ /dev/null @@ -1,5 +0,0 @@ -MYSQL_HOST=${REPO_NAME_SNAKE}_db -MUSQL_PORT=3306 -MYSQL_USER=${REPO_NAME_SNAKE} -MYSQL_PASSWORD= -MYSQL_DATABASE=${REPO_NAME_SNAKE} diff --git a/.env_debug b/.env_debug deleted file mode 100644 index cc0e3a0..0000000 --- a/.env_debug +++ /dev/null @@ -1,5 +0,0 @@ -MYSQL_HOST=localhost -MUSQL_PORT=3306 -MYSQL_USER=darkcat09 -MYSQL_PASSWORD= -MYSQL_DATABASE=apptest diff --git a/.gitea/template b/.gitea/template deleted file mode 100644 index 703649b..0000000 --- a/.gitea/template +++ /dev/null @@ -1,6 +0,0 @@ -app/*.py -templates/base.html -docker-compose.yml -Makefile -.env -README.md diff --git a/.gitignore b/.gitignore index b178e43..5d381cc 100644 --- a/.gitignore +++ b/.gitignore @@ -72,23 +72,56 @@ instance/ # Sphinx documentation docs/_build/ +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + # pyenv -#.python-version +# 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 # poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control #poetry.lock # pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. #pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide .pdm.toml -# PEP 582 +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm __pypackages__/ +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + # Environments +.env .venv env/ venv/ @@ -96,6 +129,13 @@ ENV/ env.bak/ venv.bak/ +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + # mkdocs documentation /site @@ -113,6 +153,10 @@ dmypy.json # Cython debug symbols cython_debug/ -# IDE -.vscode/ -.idea/ +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index db03f5d..0000000 --- a/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM python:3-alpine -RUN apk update && apk upgrade && apk add py-pip make -WORKDIR /app -COPY . . -RUN pip install -r requirements.txt -CMD make prod -EXPOSE 8000 diff --git a/Makefile b/Makefile deleted file mode 100644 index 949d4ba..0000000 --- a/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -dev: - DEBUG="true" python3 -m uvicorn main:app --reload - -prod: - python3 -m uvicorn main:app - -format: - python3 -m autopep8 -r --in-place app/ - -check: - python3 -m mypy app/ - python3 -m pylint app/ - -docker: - docker build -t ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE} . - -clean: - rm -rf app/__pycache__ - rm -rf __pycache__ - rm -rf .mypy_cache diff --git a/app/__init__.py b/app/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/common.py b/app/common.py deleted file mode 100644 index fd32614..0000000 --- a/app/common.py +++ /dev/null @@ -1,24 +0,0 @@ -import secrets -from pathlib import Path - -from fastapi.templating import Jinja2Templates -from pydantic import BaseSettings - - -file_dir = Path(__file__).parent - -class Settings(BaseSettings): - secret_key: str = secrets.token_hex(32) - templates_dir: str = str( - file_dir.parent / 'templates' - ) - static_dir: str = str( - file_dir.parent / 'static' - ) - -settings = Settings() - - -templates = Jinja2Templates( - directory=settings.templates_dir, -) diff --git a/app/errors.py b/app/errors.py deleted file mode 100644 index 402ba91..0000000 --- a/app/errors.py +++ /dev/null @@ -1,50 +0,0 @@ -"""Custom error pages for FastAPI app""" - -from pathlib import Path - -from fastapi import Request, Response -from fastapi import HTTPException - -from . import paths -from . import respond -from .common import settings - -# Add other HTTP error codes -codes = [404, 500] - - -class ErrorsPaths(paths.Paths): - """Sets up custom error pages, - inherited from paths.Paths""" - - def add_paths(self) -> None: - - for code in codes: - self.add_handler(code) - - def add_handler(self, code: int) -> None: - """Adds an error handler to FastAPI app. - Only for internal use! - - Args: - code (int): HTTP error code - """ - - tmpl_dir = ( - Path(__file__).parent / - settings.templates_dir - ) - file = tmpl_dir / f'{code}.html' - - if not file.exists(): - return - - @self.app.exception_handler(code) - async def handler(req: Request, exc: HTTPException) -> Response: - - return respond.with_tmpl( - f'{code}.html', - code=code, - request=req, - exc=exc, - ) diff --git a/app/main.py b/app/main.py deleted file mode 100644 index fed3553..0000000 --- a/app/main.py +++ /dev/null @@ -1,25 +0,0 @@ -from typing import List, Type -from fastapi import FastAPI -from fastapi.staticfiles import StaticFiles - -from .common import settings - -# Add your paths here -from .paths import Paths -from . import pages -from . import errors - -paths: List[Type[Paths]] = [ - pages.MainPaths, - errors.ErrorsPaths, -] - - -app = FastAPI() -app.mount( - '/static', - StaticFiles(directory=settings.static_dir), - name='static', -) -for p in paths: - p(app).add_paths() diff --git a/app/pages.py b/app/pages.py deleted file mode 100644 index 56c4094..0000000 --- a/app/pages.py +++ /dev/null @@ -1,20 +0,0 @@ -"""Main FastAPI paths""" - -from fastapi import Request, Response - -from . import paths -from . import respond - - -class MainPaths(paths.Paths): - """Main FastAPI app paths, - inherits paths.Paths""" - - def add_paths(self) -> None: - - @self.app.get('/') - def index(req: Request) -> Response: - return respond.with_tmpl( - 'index.html', - request=req, - ) diff --git a/app/paths.py b/app/paths.py deleted file mode 100644 index 82670ae..0000000 --- a/app/paths.py +++ /dev/null @@ -1,21 +0,0 @@ -import abc - -from fastapi import FastAPI - - -class Paths(abc.ABC): - """Abstract class for storing paths for FastAPI app""" - - def __init__(self, app: FastAPI) -> None: - """Abstract class for storing paths - for FastAPI app - - Args: - app (FastAPI): Application object - """ - - self.app = app - - @abc.abstractmethod - def add_paths(self) -> None: - """Add paths to the FastAPI application""" diff --git a/app/respond.py b/app/respond.py deleted file mode 100644 index 279969f..0000000 --- a/app/respond.py +++ /dev/null @@ -1,77 +0,0 @@ -import os -import mimetypes -from typing import Optional, Mapping - -from fastapi import Response -from fastapi.responses import FileResponse -from starlette.background import BackgroundTask - -from .common import templates - - -def with_tmpl( - name: str, - code: int = 200, - headers: Optional[Mapping[str, str]] = None, - background: Optional[BackgroundTask] = None, - **context) -> Response: - """Render a Jinja2 template and return Response object. - `response_class` parameter is not needed - - Args: - name (str): Template filename - code (int, optional): HTTP response code - headers (Optional[Mapping[str, str]], optional): - Additional headers, passed to Response constructor - background (Optional[BackgroundTask], optional): - Background task, passed to Response constructor - - Returns: - FastAPI's TemplateResponse object - """ - - return templates.TemplateResponse( - name=name, - context=context, - status_code=code, - headers=headers, - background=background, - ) - - -def with_file( - path: os.PathLike, - mime: Optional[str] = None, - code: int = 200, - headers: Optional[Mapping[str, str]] = None, - background: Optional[BackgroundTask] = None) -> FileResponse: - """Send a file specified in `path` - automatically guessing mimetype if `mime` is None - - Args: - path (os.PathLike): File path - mime (Optional[str], optional): File mimetype - code (int, optional): HTTP response code - headers (Optional[Mapping[str, str]], optional): - Additional headers, passed to Response constructor - background (Optional[BackgroundTask], optional): - Background task, passed to Response constructor - - Returns: - FileResponse: FastAPI's FileResponse object - """ - - return FileResponse( - path=path, - media_type=( - mime or - mimetypes.guess_type(path)[0] - ), - status_code=code, - headers=headers, - background=background, - ) - - -# Alias -with_template = with_tmpl diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index c76f131..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,19 +0,0 @@ -version: "3" - -services: - ${REPO_NAME_SNAKE}: - image: ${REPO_OWNER}/${REPO_NAME_SNAKE}:latest - container_name: ${REPO_NAME_SNAKE} - restart: unless-stopped - ports: - - "8080:8000" - links: - - ${REPO_NAME_SNAKE}_db - env_file: .env - ${REPO_NAME_SNAKE}_db: - image: mariadb:latest - container_name: ${REPO_NAME_SNAKE}_db - restart: unless-stopped - volumes: - - "./database:/var/lib/mysql" - env_file: .env diff --git a/main.py b/main.py deleted file mode 100755 index 664c498..0000000 --- a/main.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python3 - -import uvicorn - -from app.main import app - - -if __name__ == '__main__': - uvicorn.run(app) diff --git a/pylintrc b/pylintrc deleted file mode 100644 index 258b920..0000000 --- a/pylintrc +++ /dev/null @@ -1,187 +0,0 @@ -[MAIN] -analyse-fallback-blocks=no -extension-pkg-allow-list= -extension-pkg-whitelist= -fail-on= -fail-under=10 -ignore=CVS -ignore-paths= -ignore-patterns=^\.# -ignored-modules= -jobs=4 -limit-inference-results=100 -load-plugins= -persistent=yes -py-version=3.10 -recursive=no -suggestion-mode=yes -unsafe-load-any-extension=no - -[REPORTS] -evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)) -msg-template= -reports=no -score=yes - -[MESSAGES CONTROL] -confidence=HIGH, - CONTROL_FLOW, - INFERENCE, - INFERENCE_FAILURE, - UNDEFINED -disable=raw-checker-failed, - bad-inline-option, - locally-disabled, - file-ignored, - suppressed-message, - useless-suppression, - deprecated-pragma, - use-symbolic-message-instead -enable=c-extension-no-member - -[SIMILARITIES] -ignore-comments=yes -ignore-docstrings=yes -ignore-imports=yes -ignore-signatures=yes -min-similarity-lines=4 - -[MISCELLANEOUS] -notes=FIXME, - XXX, - TODO -notes-rgx= - -[DESIGN] -exclude-too-few-public-methods= -ignored-parents= -max-args=5 -max-attributes=7 -max-bool-expr=5 -max-branches=12 -max-locals=15 -max-parents=7 -max-public-methods=20 -max-returns=6 -max-statements=50 -min-public-methods=1 - -[STRING] -check-quote-consistency=no -check-str-concat-over-line-jumps=no - -[CLASSES] -check-protected-access-in-special-methods=no -defining-attr-methods=__init__, - __new__, - setUp, - __post_init__ -exclude-protected=_asdict, - _fields, - _replace, - _source, - _make -valid-classmethod-first-arg=cls -valid-metaclass-classmethod-first-arg=cls - -[FORMAT] -expected-line-ending-format= -ignore-long-lines=^\s*(# )??$ -indent-after-paren=4 -indent-string=' ' -max-line-length=100 -max-module-lines=1000 -single-line-class-stmt=no -single-line-if-stmt=no - -[IMPORTS] -allow-any-import-level= -allow-wildcard-with-all=no -deprecated-modules= -ext-import-graph= -import-graph= -int-import-graph= -known-standard-library= -known-third-party=enchant -preferred-modules= - -[VARIABLES] -additional-builtins= -allow-global-unused-variables=yes -allowed-redefined-builtins= -callbacks=cb_, - _cb -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ -ignored-argument-names=_.*|^ignored_|^unused_ -init-import=no -redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io - -[LOGGING] -logging-format-style=old -logging-modules=logging - -[EXCEPTIONS] -overgeneral-exceptions=BaseException, - Exception - -[BASIC] -argument-naming-style=snake_case -attr-naming-style=snake_case -bad-names=foo, - bar, - baz, - toto, - tutu, - tata -bad-names-rgxs= -class-attribute-naming-style=any -class-const-naming-style=UPPER_CASE -class-naming-style=PascalCase -const-naming-style=any -docstring-min-length=-1 -function-naming-style=snake_case -good-names=i, - j, - k, - f, - db, - ex, - Run, - _ -good-names-rgxs= -include-naming-hint=no -inlinevar-naming-style=any -method-naming-style=snake_case -module-naming-style=snake_case -name-group= -no-docstring-rgx=^_ -property-classes=abc.abstractproperty -variable-naming-style=snake_case - -[SPELLING] -max-spelling-suggestions=4 -spelling-dict= -spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy: -spelling-ignore-words= -spelling-private-dict-file= -spelling-store-unknown-words=no - -[TYPECHECK] -contextmanager-decorators=contextlib.contextmanager -generated-members= -ignore-none=yes -ignore-on-opaque-inference=yes -ignored-checks-for-mixins=no-member, - not-async-context-manager, - not-context-manager, - attribute-defined-outside-init -ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace -missing-member-hint=yes -missing-member-hint-distance=1 -missing-member-max-choices=1 -mixin-class-rgx=.*[Mm]ixin -signature-mutators= - -[REFACTORING] -max-nested-blocks=5 -never-returning-functions=sys.exit,argparse.parse_error diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 9d933d0..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -fastapi==0.92.0 -uvicorn[standard]==0.20.0 -jinja2==3.1.2 -starlette-wtf==0.4.3 -python-dotenv==0.21.1 diff --git a/static/css/style.css b/static/css/style.css deleted file mode 100644 index cdaca35..0000000 --- a/static/css/style.css +++ /dev/null @@ -1,60 +0,0 @@ -body { - height: 100vh; - padding: 0; - margin: 0; - font-family: sans-serif; - - display: flex; - flex-direction: column; - justify-content: space-between; - align-items: center; - - --bg: #fff; - --fg: #000; - - background: var(--bg); - color: var(--fg); -} - -@media (prefers-color-scheme: dark) { - body { - --bg: #202023; - --fg: #eee; - } -} - -header { margin-top: 5px; } -footer { margin-bottom: 5px; } - -a { - color: #5b8a55; -} -a:hover { - filter: brightness(120%); -} - -form { - display: flex; - flex-direction: column; -} -form > div { - margin-top: 5px; - display: flex; - flex-direction: row; - justify-content: end; -} -form > div > label { - width: 50%; - margin-right: 10px; -} -form > div > input { - width: 50%; - border: 1px solid var(--fg); - outline: none; - background: var(--bg); - color: var(--fg); -} -form > div > input:hover, -form > div > input:focus { - filter: brightness(130%); -} diff --git a/static/js/script.js b/static/js/script.js deleted file mode 100644 index 65e1260..0000000 --- a/static/js/script.js +++ /dev/null @@ -1,4 +0,0 @@ -addEventListener('load', () => { - document.getElementById('js') - .innerText = new Date().toLocaleString() -}) diff --git a/templates/404.html b/templates/404.html deleted file mode 100644 index 3faabe7..0000000 --- a/templates/404.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends "base.html" %} - -{% block title %}404{% endblock %} - -{% block content %} -
- Go to the - main page -
-{% endblock %} diff --git a/templates/500.html b/templates/500.html deleted file mode 100644 index 2835a07..0000000 --- a/templates/500.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "base.html" %} - -{% block title %}500{% endblock %} - -{% block content %} -- An error occured while - processing your request. -
-- Please, try again later - or contact web site admin. -
-{% endblock %} diff --git a/templates/admin.html b/templates/admin.html deleted file mode 100644 index 219eb96..0000000 --- a/templates/admin.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends "base.html" %} - -{% block title %}Admin{% endblock %} - -{% block content %} -{{ cell }} | - {% endfor %} -