Managing pyproject.toml and poetry.lock in Version Control
Including pyproject. toml
The pyproject.toml file is the central configuration file for Poetry projects. It is something that includes your project and its requirement or other project on which it depends. This file should always remain under version control so that all the team members as well as the CI/CD pipelines rely upon the same project.
Including poetry.lock
The poetry. Lock file freezes the versions of your dependencies. With this file included into the version control, everyone will use the specified dependencies, avoiding the situation when some of the participants employed different versions of the required tools. When updating from previous versions of this file, ensure that a backup of this file exists in the desired control system path.
.gitignore Configuration
This means poetry is a global tool that creates a virtual setting for your project. It might be quite useful rarely and usually, you do not want to include this virtual environment in your version control system. Configure your . gitignore file to exclude it:
1. Byte-compiled / optimized / DLL files
Python generates bytecode files with extensions like .pyc, .pyo, and .pyd in the __pycache__ directory. These files are specific to the machine they were generated on and do not need to be versioned.
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
2. Virtual environment directory
Virtual environments are used to manage project-specific dependencies, and their contents are generated based on pyproject.toml and poetry.lock, so they don’t need to be tracked.
# Virtual environment directory
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
3. Distribution / packaging
These directories and files are related to Python package distribution. They are generated during the build and packaging process and do not need to be included in version control.
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
4. Poetry virtual environment
hese lines should not be included in the .gitignore file. Both pyproject.toml and poetry.lock should be versioned because they define the project dependencies and ensure reproducibility.
# Poetry virtual environment
poetry.lock
pyproject.toml
5. PyInstaller
PyInstaller generates these files when creating executable applications. They contain metadata and configuration specific to the build process and should not be included in version control.
# PyInstaller
*.manifest
*.spec
Integrating Poetry in Python with version control systems
Version control systems, like Git, are crucial components in today’s software application development processes. They assist in controlling modification to the project’s source code, working with other developers, and, reviewing the history of the project. In this tutorial, crucial steps of Poetry’s integration with the project’s version control are discussed to improve the Python project’s development environment. This article will demonstrate recommended approaches and practical methods for using Poetry with a VCS, specifically Git.
Contact Us