Python базовый шаблон

1. Структура каталогов проекта. Пример:

my_project/ ├── src/ # Source code │ └── my_package/ # Package/module │ ├── __init__.py # Initialize the package │ └── module.py # Your code ├── tests/ # Unit/integration tests │ ├── __init__.py │ └── test_module.py ├── docs/ # Documentation (e.g., Sphinx) ├── .gitignore # Ignore files for Git ├── requirements.txt # Dependencies ├── setup.py # For packaging (optional) ├── pyproject.toml # Modern build/packaging config ├── README.md # Project description └── LICENSE # License (MIT, Apache, etc.)

2. Виртуальное окружение.

python -m venv venv # Create a virtual environment source venv/bin/activate # Activate (Linux/macOS) venv\Scripts\activate # Activate (Windows)

3. Зависимости. pip или poetry

pip install one two three # Install packages pip freeze > requirements.txt # Save dependencies

4. Контроль версий. Git

git init

5. Документирование. Sphinx

pip install sphinx sphinx-quickstart docs # Follow prompts

6. Тестирование. Pytest

pip install pytest pytest tests/ # Run tests

Начало проекта по шагам:

  • Создание каталога и структуры проекта.
  • Настройка виртуальной среды.
  • Установка зависимостей и сохранение в requirements.txt.
  • Написание кода с тестами и документацией.
  • Использование Git для контроля версий.
Начать дискуссию