Python Project Layout: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 10: Line 10:
  ├─ run
  ├─ run
  ├─ src
  ├─ src
  │  └─ main
  │  └─ mypackage
  │       └─ python
  │           ├─  __init__.py
  │          └─ main.py
  │          ├─  __main__.py  
  ├─ venv <font color=teal># created automatically upon virtual environment initialization</font>
  │          └─ VERSION
│    ├─ bin
├─ tests
│    ...
│  └─ mypackage
│          ├─
│         
└─ venv <font color=teal># created automatically upon virtual environment initialization</font>
      ├─ bin
 
 
</font>
</font>



Revision as of 19:21, 25 October 2022

Internal

Overview

A typical Python project layout, which allows for code written in other programming languages as well, is similar to:

.
├─ .gitignore
├─ requirements.txt
├─ run
├─ src
│   └─ mypackage
│           ├─   __init__.py
│           ├─   __main__.py 
│           └─ VERSION
├─ tests
│   └─ mypackage
│           ├─  
│           
└─ venv # created automatically upon virtual environment initialization
      ├─ bin
 
 

Setting a Manual Project

A project set up this way will be compatible with PyCharm. Also see:

Simple PyCharm Project

Add the dependencies to requirements.txt. For more details, see:

requirements.txt

Initialize the virtual environment:

cd ${PROJECT_HOME}
python3 -m venv venv
venv/bin/pip install -r ./requirements.txt

For more details on virtual environments, see:

Virtual Environment

Example of .gitignore:

venv/

Example of run:

#!/usr/bin/env bash
$(dirname $0)/venv/bin/python $(dirname $0)/src/main/python/main.py

Organizatorium