venv, pip, poetry/uv, pyproject, linting and testing tools
Practise these as flashcards. One or two lines each; the ones you miss come back first.
Start freeA virtual environment is an isolated Python environment that keeps project dependencies separate from the global Python installation. Using one prevents conflicts between packages and ensures reproducibility.
You install packages listed in a requirements file by running pip install -r requirements.txt. This installs all dependencies specified in the file.
A lock file records the exact versions of all installed dependencies, ensuring that everyone working on the project uses the same package versions for consistency and reproducibility.
On Unix systems, you run source myenv/bin/activate; on Windows, it's myenv\Scripts\activate. This switches your shell to use the environment's Python and packages.
Poetry and uv provide better dependency resolution, automatic lock file generation, and integrate with pyproject.toml for configuration. They also simplify publishing packages and managing virtual environments, making workflows more robust and reproducible.
pyproject.toml standardizes build configuration and supports multiple build backends. It's easier to read and maintain, and enables interoperability between tools like Poetry, uv, and flit, replacing the older, less flexible setup.py approach.
I'd check which packages require conflicting versions, review their requirements, and try to upgrade or downgrade dependencies to compatible versions. Tools like Poetry or uv can help identify and resolve conflicts automatically, but sometimes manual intervention is needed.
Pinning means specifying exact versions of dependencies, like requests==2.31.0. It's important because it prevents unexpected updates that could break your code or introduce conflicts, ensuring stable and reproducible builds.
I run ruff check to lint the code and catch errors, and black to auto-format code to a consistent style. Both tools can be integrated into CI pipelines to enforce code quality and style across the team.
Type checking uses tools like mypy to validate type annotations in your code. You add type hints to functions and classes, then run mypy to catch type errors before runtime, improving reliability and documentation.
A pytest test file contains functions prefixed with test_. You can use fixtures for setup, and assertions to check expected outcomes. Tests are discovered automatically by pytest based on naming conventions.
Fixtures provide reusable setup and teardown logic. You define them with @pytest.fixture, then pass them as arguments to test functions, keeping tests DRY and maintainable.