What is the best Python project structure for a non-trivial end-user desktop application?

What is the best Python project structure for a non-trivial end-user desktop application?

Imagine you’re developing a desktop (not web) application in Python. What is the ideal folder hierarchy to use for your project, considering the following desirable features: ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install packages?

Specifically:

  • Where should the source code be placed?
  • Where should the application startup scripts go?
  • Where should the IDE project configuration files be stored?
  • Where should the unit/acceptance tests be placed?
  • Where should non-Python data, such as config files, be stored?
  • Where should non-Python source files, such as C++ for pyd/so binary extension modules, be stored?
  • Source Code (src/): Place the core application code here, ensuring a clear separation between business logic and any external dependencies or extensions.
  • Tests (tests/): Structure your tests into subdirectories based on type (unit, integration).
  • Configuration Files (config/): Store any non-Python resources such as config files.
  • Scripts (scripts/): Place the startup scripts in a dedicated folder.
  • IDE and Source Control: Keep project metadata (.git/, .vscode/) separate from the codebase, enabling ease of version control.
  • Source Code (myapp/): All Python code, including core and UI logic, can be placed in a single folder.
  • Tests (tests/): Keep test modules within a dedicated folder, separate from production code.
  • Resources (resources/): Store non-Python resources here (config files, images, etc.).
  • Startup Scripts (scripts/): Simple folder for any command-line scripts or entry points.
  • Modular Design: Code is split into app (core) and UI components. The modular design helps scale the project as new features are added.
  • Build and Packaging (build/): Keeps build scripts for packaging and distribution (like using PyInstaller for desktop applications).
  • Clear Separation: Configuration and test folders remain separate for clarity.