Skip to content

Use Poetry to manage dependencies, read configuration from a YAML file using PyYAML, customize logging to generate logs, and use APScheduler and py7zr to periodically compress and archive logs. | Poetry 管理依赖,使用 PyYAML 从 yml 读取配置,自定义 logging 生成日志,使用 APScheduler 和 py7zr 定时压缩归档日志。

License

Notifications You must be signed in to change notification settings

duanluan/py-poetry-config-log-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

py-poetry-config-log-example

English | 简体中文

Use Poetry to manage dependencies, read configuration from a YAML file using PyYAML, customize logging to generate logs, and use APScheduler and py7zr to periodically compress and archive logs.

Usage in PyCharm

  • In the Project view, right-click the src directory and select Mark Directory as -> Sources Root. This allows for direct imports of modules located under src.
  • If running as a module, set the 'Module name' to app1.app1 and the 'Working directory' to the project's root directory.

Command

Enter the project directory.

# Globally set the virtual environment to be created in the project's .venv directory
poetry config virtualenvs.in-project true

# Temporarily set the virtual environment to be created in the project's .venv directory
# Linux
POETRY_VIRTUALENVS_IN_PROJECT=true
# Windows CMD
set POETRY_VIRTUALENVS_IN_PROJECT=true
# Windows PowerShell
$env:POETRY_VIRTUALENVS_IN_PROJECT="true"

# Install dependencies (by default in the virtualenvs directory under "poetry config cache-dir")
poetry install

# Show the command to activate the virtual environment
poetry env info -p
# Activate the virtual environment (Windows)
.venv\Scripts\activate.bat
# Deactivate the virtual environment (Windows)
.venv\Scripts\deactivate.bat

# Start the application
poetry run app1

# Remove the virtual environment
poetry env remove python

Packaging EXE

Initial Build:

  • -F Single-file executable, -D Single-directory executable
  • -n Specifies the name of the exe file
  • --add-data Adds resource files
  • -p Add the specified path to the module search path (sys.path)
pyinstaller -n app1 -D --add-data "src/app1/res;res" -p src src/app1/app1.py

Build Using a .spec File:

  • --noconfirm No need to confirm whether to overwrite the last built file
pyinstaller app1.spec --noconfirm

Run the EXE:

app1.exe --config _internal\res\config.yml

About

Use Poetry to manage dependencies, read configuration from a YAML file using PyYAML, customize logging to generate logs, and use APScheduler and py7zr to periodically compress and archive logs. | Poetry 管理依赖,使用 PyYAML 从 yml 读取配置,自定义 logging 生成日志,使用 APScheduler 和 py7zr 定时压缩归档日志。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages