1616
1717class PackageManagerNotFoundError (Exception ):
1818 """Raised when no suitable package manager is found."""
19+
1920 pass
2021
2122
@@ -30,41 +31,38 @@ def _check_command_available(command: str) -> bool:
3031
3132def detect_package_manager () -> str :
3233 """Detect the best available package manager.
33-
34+
3435 Returns:
3536 str: The package manager command ('uv' or 'pip')
36-
37+
3738 Raises:
3839 PackageManagerNotFoundError: If no suitable package manager is found
3940 """
4041 # Check for uv first since it's more modern and faster
4142 if _check_command_available ("uv" ):
4243 return "uv"
43-
44+
4445 # Fall back to pip
4546 if _check_command_available ("pip" ):
4647 return "pip"
47-
48+
4849 # As a last resort, try using python -m pip
4950 try :
50- subprocess .run ([sys .executable , "-m" , "pip" , "--version" ],
51- capture_output = True , check = True )
51+ subprocess .run ([sys .executable , "-m" , "pip" , "--version" ], capture_output = True , check = True )
5252 return "python -m pip"
5353 except (subprocess .CalledProcessError , FileNotFoundError ):
5454 pass
55-
56- raise PackageManagerNotFoundError (
57- "No suitable package manager found. Please install either uv or pip."
58- )
55+
56+ raise PackageManagerNotFoundError ("No suitable package manager found. Please install either uv or pip." )
5957
6058
6159def get_install_command (package_manager : str , venv_context = None ) -> list :
6260 """Get the install command for the given package manager.
63-
61+
6462 Args:
6563 package_manager: The package manager command ('uv', 'pip', or 'python -m pip')
6664 venv_context: The virtual environment context (optional, used for pip)
67-
65+
6866 Returns:
6967 list: The base install command as a list
7068 """
@@ -89,17 +87,17 @@ def get_install_command(package_manager: str, venv_context=None) -> list:
8987
9088def install_packages (packages : list , venv_context = None , package_manager : str = None ) -> None :
9189 """Install packages using the available package manager.
92-
90+
9391 Args:
9492 packages: List of packages to install
9593 venv_context: Virtual environment context (optional)
9694 package_manager: Package manager to use (auto-detected if None)
9795 """
9896 if package_manager is None :
9997 package_manager = detect_package_manager ()
100-
98+
10199 install_cmd = get_install_command (package_manager , venv_context )
102-
100+
103101 try :
104102 subprocess .check_call (install_cmd + packages )
105103 except subprocess .CalledProcessError as e :
@@ -108,25 +106,29 @@ def install_packages(packages: list, venv_context=None, package_manager: str = N
108106
109107def create_venv_with_package_manager (venv_path ):
110108 """Create virtual environment using the best available package manager.
111-
109+
112110 Args:
113111 venv_path: Path where to create the virtual environment
114-
112+
115113 Returns:
116114 venv_context: Virtual environment context object
117115 """
118116 package_manager = detect_package_manager ()
119-
117+
120118 if package_manager == "uv" :
121119 # Use uv to create and manage the virtual environment
122120 if not venv_path .exists ():
123121 subprocess .check_call (["uv" , "venv" , str (venv_path )])
124-
122+
125123 # Create a mock venv_context for compatibility
126124 class MockVenvContext :
127125 def __init__ (self , venv_path ):
128- self .env_exe = str (venv_path / "bin" / "python" ) if sys .platform != "win32" else str (venv_path / "Scripts" / "python.exe" )
129-
126+ self .env_exe = (
127+ str (venv_path / "bin" / "python" )
128+ if sys .platform != "win32"
129+ else str (venv_path / "Scripts" / "python.exe" )
130+ )
131+
130132 return MockVenvContext (venv_path )
131133 else :
132134 # Use standard venv for pip
@@ -136,4 +138,4 @@ def __init__(self, venv_path):
136138 else :
137139 env_builder = ExtendedEnvBuilder (with_pip = True , upgrade_deps = True )
138140 env_builder .create (venv_path )
139- return env_builder .context
141+ return env_builder .context
0 commit comments