python
dev_tool.services.python
__all__ = ['DependencyResolver', 'DependencySource', 'PackageManager', 'PackageManagerFactory', 'PythonService', 'UnixPipPackageManager', 'UnixUvPackageManager', 'WindowsPipPackageManager', 'WindowsUvPackageManager']
module-attribute
DependencyResolver
A class for discovering and resolving dependency sources.
This class provides methods for finding all available dependency sources and determining the best installation strategy.
The constructor for the DependencyResolver class.
This method initializes the resolver with a config manager and sets up the patterns for discovering dependency sources.
Source code in dev_tool/services/python/package/dependencies.py
clean_content
A method that returns requirements file content with -r references removed.
This method reads a requirements file and filters out any -r directives
to prevent redundant installations while keeping the file's own dependencies.
Parameters:
-
requirements(Path) –The path to the requirements file.
Returns:
-
str–The cleaned requirements content as a string.
Source code in dev_tool/services/python/package/dependencies.py
discover_sources
A method that discovers all available dependency sources.
This method finds both requirements files and pyproject.toml sources and returns them sorted by priority.
Returns:
-
list[DependencySource]–A list of all discovered dependency sources.
Source code in dev_tool/services/python/package/dependencies.py
get_available_sources
A method that gets formatted descriptions of available dependency sources.
This method discovers sources and returns formatted descriptions organized by source type.
Returns:
Source code in dev_tool/services/python/package/dependencies.py
get_fallback_strategy
A method that gets the fallback installation strategy.
This method returns the opposite type of sources for fallback installation.
Parameters:
-
sources(list[DependencySource]) –The primary sources that failed.
Returns:
-
list[DependencySource]–The fallback sources to try.
Source code in dev_tool/services/python/package/dependencies.py
get_strategy
A method that gets the installation strategy for dependencies.
This method returns either all sources for automatic detection or filters sources based on requested dependency types.
Parameters:
-
requested(list[str] | None, default:None) –Optional list of specific dependency types to install.
Returns:
-
list[DependencySource]–The dependency sources to install based on the strategy.
Source code in dev_tool/services/python/package/dependencies.py
DependencySource
dataclass
A class for representing a source of dependencies.
This class holds information about where dependencies can be installed from, either requirements files or pyproject.toml extras.
name
instance-attribute
source
instance-attribute
path = None
class-attribute
instance-attribute
extra = None
class-attribute
instance-attribute
priority = 0
class-attribute
instance-attribute
available
property
A method that checks if this dependency source is available.
This method determines if the source exists and contains content.
Returns:
-
bool–True if the source is available, False otherwise.
formatted
A method that returns a formatted string representation of the source.
This method creates a human-readable description of the dependency source.
Returns:
-
str–A formatted string describing the dependency source.
Source code in dev_tool/services/python/package/dependencies.py
PackageManagerFactory
A factory class for creating package manager instances.
This class provides methods for creating platform-specific package managers.
create_package_manager
staticmethod
A method that creates platform-specific package manager instances.
Returns:
-
tuple[PackageManager, PackageManager]–A tuple containing the primary and fallback package manager instances.
Source code in dev_tool/services/python/package/factory.py
PackageManager
Bases: Protocol
A protocol for package managers.
This class defines the interface for package management operations.
is_available
A method that checks if the package manager is available on the system.
Returns:
-
bool–True if the package manager is available, False otherwise.
install_package
install_package_manager
A method that installs the package manager if it is not already installed.
Returns:
-
bool–True if the installation was successful, False otherwise.
create_virtual_environment
A method that creates a virtual environment.
Returns:
-
bool–True if the creation was successful, False otherwise.
install_from_requirements
install_from_pyproject
A method that installs dependencies from pyproject.toml.
Parameters:
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/manager.py
uninstall_package
upgrade_package_manager
A method that upgrades the package manager to the latest version.
Returns:
-
bool–True if the upgrade was successful, False otherwise.
list_installed_packages
A method that lists all installed packages.
Returns:
UnixPipPackageManager
Bases: PackageManager
A Unix-specific implementation of the Pip package manager.
This class provides methods for managing Python packages using pip on Unix-like systems.
is_available
A method that checks if pip3 is available on the system.
Returns:
-
bool–True if pip3 is available, False otherwise.
Source code in dev_tool/services/python/package/pip.py
install_package
A method that installs a package using pip.
Parameters:
-
package(str) –The name of the package to install.
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
install_package_manager
A method that ensures pip3 is installed.
Returns:
-
bool–True if pip3 is available, False otherwise.
create_virtual_environment
A method that creates a virtual environment using venv.
Returns:
-
bool–True if the creation was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
install_from_requirements
A method that installs dependencies from a requirements file using pip.
Parameters:
-
requirements(Path) –The path to the requirements file.
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
install_from_pyproject
A method that installs dependencies from pyproject.toml using pip.
Parameters:
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
uninstall_package
A method that uninstalls a package using pip.
Parameters:
-
package(str) –The name of the package to uninstall.
Returns:
-
bool–True if the uninstallation was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
upgrade_package_manager
A method that upgrades pip to the latest version.
Returns:
-
bool–True if the upgrade was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
list_installed_packages
A method that lists all installed packages using pip.
Returns:
Source code in dev_tool/services/python/package/pip.py
WindowsPipPackageManager
Bases: PackageManager
A Windows-specific implementation of the Pip package manager.
This class provides methods for managing Python packages using pip on Windows.
is_available
A method that checks if pip is available on the system.
Returns:
-
bool–True if pip is available, False otherwise.
Source code in dev_tool/services/python/package/pip.py
install_package
A method that installs a package using pip.
Parameters:
-
package(str) –The name of the package to install.
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
install_package_manager
create_virtual_environment
A method that creates a virtual environment using venv.
Returns:
-
bool–True if the creation was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
install_from_requirements
A method that installs dependencies from a requirements file using pip.
Parameters:
-
requirements_path–The path to the requirements file.
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
install_from_pyproject
A method that installs dependencies from pyproject.toml using pip.
Parameters:
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
uninstall_package
A method that uninstalls a package using pip.
Parameters:
-
package(str) –The name of the package to uninstall.
Returns:
-
bool–True if the uninstallation was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
upgrade_package_manager
A method that upgrades pip to the latest version.
Returns:
-
bool–True if the upgrade was successful, False otherwise.
Source code in dev_tool/services/python/package/pip.py
list_installed_packages
A method that lists all installed packages using pip.
Returns:
Source code in dev_tool/services/python/package/pip.py
UnixUvPackageManager
Bases: PackageManager
A Unix-specific implementation of the uv package manager.
This class provides methods for managing Python packages using uv on Unix-like systems.
is_available
A method that checks if uv is available on the system.
Returns:
-
bool–True if uv is available, False otherwise.
Source code in dev_tool/services/python/package/uv.py
install_package
A method that installs a package using uv.
Parameters:
-
package(str) –The name of the package to install.
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
install_package_manager
A method that installs uv if it is not already installed.
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
create_virtual_environment
A method that creates a virtual environment using uv.
Returns:
-
bool–True if the creation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
install_from_requirements
A method that installs dependencies from a requirements file using uv.
Parameters:
-
requirements(Path) –The path to the requirements file.
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
install_from_pyproject
A method that installs dependencies from pyproject.toml using uv.
Parameters:
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
uninstall_package
A method that uninstalls a package using uv.
Parameters:
-
package(str) –The name of the package to uninstall.
Returns:
-
bool–True if the uninstallation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
upgrade_package_manager
A method that upgrades uv to the latest version.
Returns:
-
bool–True if the upgrade was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
list_installed_packages
A method that lists all installed packages using uv.
Returns:
Source code in dev_tool/services/python/package/uv.py
WindowsUvPackageManager
Bases: PackageManager
A Windows-specific implementation of the uv package manager.
This class provides methods for managing Python packages using uv on Windows.
create_virtual_environment
A method that creates a virtual environment using uv.
Returns:
-
bool–True if the creation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
install_from_pyproject
A method that installs dependencies from pyproject.toml using uv.
Parameters:
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
install_from_requirements
A method that installs dependencies from a requirements file using uv.
Parameters:
-
requirements(Path) –The path to the requirements file.
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
install_package
A method that installs a package using uv.
Parameters:
-
package(str) –The name of the package to install.
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
install_package_manager
A method that installs uv if it is not already installed.
Returns:
-
bool–True if the installation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
is_available
A method that checks if uv is available on the system.
Returns:
-
bool–True if uv is available, False otherwise.
Source code in dev_tool/services/python/package/uv.py
list_installed_packages
A method that lists all installed packages using uv.
Returns:
Source code in dev_tool/services/python/package/uv.py
uninstall_package
A method that uninstalls a package using uv.
Parameters:
-
package(str) –The name of the package to uninstall.
Returns:
-
bool–True if the uninstallation was successful, False otherwise.
Source code in dev_tool/services/python/package/uv.py
upgrade_package_manager
Source code in dev_tool/services/python/package/uv.py
PythonService
Bases: BaseService
A service class for Python-related operations.
This class provides methods for managing Python virtual environments and dependencies.
The constructor for the PythonService class.
It initializes package managers for dependency management.
Source code in dev_tool/services/python/service.py
resolver = DependencyResolver()
instance-attribute
clean_virtual_environment
A method that removes an existing virtual environment.
Source code in dev_tool/services/python/service.py
create_virtual_environment
A method that creates a Python virtual environment.
Source code in dev_tool/services/python/service.py
get_available_dependencies
A method that lists all available dependency sources.
This method discovers and returns information about all available dependency sources including requirements files and pyproject.toml extras.
Returns:
Source code in dev_tool/services/python/service.py
install_dependencies
A method that installs Python dependencies.
It requires a virtual environment to be active.
Parameters:
-
requirements_file(Path | None, default:None) –Optional path to a specific requirements file. If provided, installs from this file only.
-
types(list[str] | None, default:None) –Optional list of dependency types to install (e.g., ['development', 'production']). If None, auto-detects.
Source code in dev_tool/services/python/service.py
install_dependency
A method that installs a single Python package.
It requires a virtual environment to be active.
Source code in dev_tool/services/python/service.py
install_package_manager
A method that installs the preferred package manager.
It falls back to an alternative if the preferred manager cannot be installed.
Source code in dev_tool/services/python/service.py
setup_venv
A method that sets up a complete virtual environment.
Creates a virtual environment if needed, upgrades the package manager, and installs all dependencies.
Parameters:
Source code in dev_tool/services/python/service.py
uninstall_dependencies
A method that uninstalls a Python package.
It requires a virtual environment to be active.
Source code in dev_tool/services/python/service.py
upgrade_package_manager
A method that upgrades the package manager to the latest version.
It requires a virtual environment to be active.