Skip to content

duanluan/py-poetry-config-log-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

py-poetry-config-log-example

English | 简体中文

Use Poetry to manage dependencies, load YAML configuration via PyYAML, generate rotating logs with logging, and compress archived logs using APScheduler and py7zr.

Quick Start (First Run)

# 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

# Run app script entry
poetry run app1


# 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

# Remove the virtual environment
poetry env remove python

Notes:

  • poetry run does not require manually activating .venv.
  • If dependencies or lockfile change, run poetry install again.

Daily Run

poetry run app1

Optional one-off module form:

poetry run python -m app1.app1

Usage in PyCharm

Set once, then reuse:

  1. Interpreter: select project .venv (Poetry-created environment).
  2. Mark src as Sources Root in Project view.
  3. Run Configuration:
    • Type: Python
    • Run: Module name
    • Module name: app1.app1
    • Working directory: project root
  4. Save the run configuration (optionally as shared).

If you see ModuleNotFoundError: No module named 'app1' or 'common':

poetry install

Packaging EXE

Initial build:

  • -F single-file executable, -D single-directory executable
  • -n executable name
  • --add-data include resource files
  • -p append search path to sys.path
pyinstaller -n app1 -D --add-data "src/app1/res;res" -p src src/app1/app1.py

Build with .spec:

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

Run EXE:

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

About

Use Poetry to manage dependencies, load YAML configuration via PyYAML, generate rotating logs with logging, and compress archived logs using APScheduler and py7zr. | 使用 Poetry 管理依赖,使用 PyYAML 读取 YAML 配置,基于 logging 输出并轮转日志,再结合 APScheduler 和 py7zr 对归档日志进行压缩清理。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages