Development Environment & Poetry
Relevant source files
The following files were used as context for generating this wiki page:
The MT5-Docker project utilizes a dual-Python architecture managed by Poetry to ensure compatibility between modern Linux tooling and the specific requirements of MetaTrader 5 (MT5). This environment is designed to support high-performance gRPC communication and robust automated testing across different execution contexts.
Introduction
The development environment is centered around Poetry, which serves as the primary tool for dependency management, virtual environment isolation, and project configuration. The architecture is unique in its "Dual Python" approach: it utilizes Python 3.13 for the Linux system (host/system level) to maintain compatibility with the latest mt5linux features and modern static analysis tools, while the containerized Wine environment uses Python 3.12 to satisfy the strict numpy 1.26.4 requirement of the MetaTrader 5 terminal.
Sources: README.md:14-16, pyproject.toml:47-49, tests/test_static.py:126-129
Architecture & Dependency Management
The project distinguishes between development and production environments through its handling of the mt5linux dependency. In a local development setup, Poetry is configured to use a local path dependency, allowing developers to make and test changes to the bridge library simultaneously with the container environment.
Dual-Python Environment Strategy
The environment is split into two distinct execution domains:
- System/Host (Linux): Python 3.13 is used for running
pytest,ruff,mypy, and themt5linuxclient library. - Container (Wine/Windows): Python 3.12 is pre-installed to run the MT5 terminal and the gRPC bridge server.
The following diagram illustrates the separation of concerns and how dependencies are orchestrated:
This diagram shows the relationship between Poetry on the host and the internal Python structure of the container.
Sources: README.md:89-94, tests/test_static.py:126-135, scripts/setup-dependencies.sh:10-15
Configuration & Tooling
Poetry centralizes the configuration for various development tools within pyproject.toml. This includes strict type-checking modes, linting rules, and test markers.
Core Dependencies (System Level)
| Package | Version | Purpose |
|---|---|---|
python | ^3.13 | System-level execution environment |
grpcio | ^1.60.0 | High-performance RPC framework |
mt5linux | master | Remote MetaTrader 5 bridge (Git/Local) |
python-dotenv | ^1.0.0 | Environment variable management |
Sources: pyproject.toml:44-50, README.md:204-209
Development Tooling
The project enforces high code quality through a comprehensive suite of tools configured in the Poetry groups:
- Static Analysis:
ruff(v0.11.13) for linting and formatting,mypyandpyrightfor strict type checking. - Testing:
pytestwith plugins for environment variables (pytest-dotenv), timeouts, and property-based testing (hypothesis). - Protocols:
grpc-stubsfor type-safe gRPC development.
Sources: pyproject.toml:52-61, CLAUDE.md:16-19, tests/constants.py:270-280
Setup & Dependency Orchestration
The project provides a utility script, scripts/setup-dependencies.sh, to manage the transition between local development and CI/Production environments. This script dynamically adjusts the mt5linux installation mode.
Dependency Resolution Flow
The sequence illustrates how the project differentiates between local editable installs and remote git-based dependencies.
Sources: scripts/setup-dependencies.sh:140-165, README.md:95-103
Testing Framework & Static Validation
The project utilizes pytest alongside Poetry to run two primary categories of tests. These are defined via custom markers in pyproject.toml:
Test Categories and Markers
| Marker | Description | File Path |
|---|---|---|
test_static.py | Validates versions.env, Dockerfile ARGs, and script syntax without a container. | tests/test_static.py |
test_runtime.py | Requires a running Docker container to validate MT5 connectivity and gRPC services. | tests/test_runtime.py |
requires_container | Custom marker for tests that need the Docker environment. | pyproject.toml:117 |
Version Consistency Enforcement
A critical part of the development environment is the TestVersionConsistency class, which ensures that version pins in versions.env match those declared in the Dockerfile, compose.yaml, and pyproject.toml. For example, it verifies that the PYTHON_VERSION (3.12 for Wine) and NUMPY_VERSION (1.26.x) remain synchronized across all build artifacts to prevent runtime crashes.
Sources: tests/test_static.py:102-120, tests/test_runtime.py:20-30, pyproject.toml:116-120
Conclusion
The Development Environment & Poetry system in MT5-Docker provides a robust, type-safe, and highly compatible foundation for MetaTrader 5 automation. By leveraging Poetry's group management and path dependencies, the project maintains a seamless workflow between host-side client development and containerized bridge execution. The dual-Python strategy specifically addresses the legacy requirements of the MT5 terminal while allowing the rest of the ecosystem to benefit from modern Python 3.13 features.