This commit is contained in:
leo
2023-12-31 15:50:28 +08:00
commit d36f0b05ca
11 changed files with 230 additions and 0 deletions

2
.dockerignore Normal file
View File

@@ -0,0 +1,2 @@
.git
.idea

144
.gitignore vendored Normal file
View File

@@ -0,0 +1,144 @@
# 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/
*.db
.idea
.vscode
log

1
.version Normal file
View File

@@ -0,0 +1 @@
testqw

11
Dockerfile Normal file
View File

@@ -0,0 +1,11 @@
FROM python:3.10
COPY requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
COPY . /app
WORKDIR /app
CMD ["python", "/app/main.py"]

2
app/__init__.py Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

2
app/core/__init__.py Normal file
View File

@@ -0,0 +1,2 @@
from .config import settings
from .redis_ import kv_redis_client, redis_client

36
app/core/config.py Normal file
View File

@@ -0,0 +1,36 @@
import os
from loguru import logger
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
BASE_DIR: str = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
VERSION: str | None = None
redis_dsn: str = 'redis://:@localhost:6379/0'
kv_redis_dsn: str = 'redis://:password@localhost:6379/1'
mysql_dsn: str = 'mysql+pymysql://username:password@localhost:3306/data?charset=utf8mb4'
@property
def version(self):
if self.VERSION:
return self.VERSION
if not os.path.exists(os.path.join(self.BASE_DIR, ".version")):
self.VERSION = "0.0.0"
return self.VERSION
with open(os.path.join(self.BASE_DIR, ".version"), "r") as f:
self.VERSION = f.read().strip()
return self.VERSION
PROJECT_NAME: str = 'project_name'
class Config:
case_sensitive = True
settings = Settings()
if __name__ == '__main__':
logger.debug(settings.BASE_DIR)

15
app/core/redis_.py Normal file
View File

@@ -0,0 +1,15 @@
import redis
from loguru import logger
from app.core.config import settings
redis_client = redis.Redis.from_url(settings.redis_dsn)
kv_redis_client = redis.Redis.from_url(settings.kv_redis_dsn)
if __name__ == '__main__':
kv_redis_client.set("name", "leo")
keys = kv_redis_client.keys("*")
logger.debug(keys)
kv_redis_client.delete("name")
keys = kv_redis_client.keys("*")
logger.debug(keys)

11
main.py Normal file
View File

@@ -0,0 +1,11 @@
from loguru import logger
from app.core import settings
def main():
logger.info(f"{settings.version=}")
if __name__ == '__main__':
main()

4
requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
loguru
pydantic
redis
pydantic-settings

2
utils/__init__.py Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-