Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.cli.req_command Namespace Reference

Data Structures

class  IndexGroupCommand
 
class  RequirementCommand
 
class  SessionCommandMixin
 

Functions

Optional["SSLContext"] _create_truststore_ssl_context ()
 
None warn_if_run_as_root ()
 
Any with_cleanup (Any func)
 

Variables

 logger = logging.getLogger(__name__)
 
list KEEPABLE_TEMPDIR_TYPES
 
 tempdir_registry
 

Detailed Description

Contains the Command base classes that depend on PipSession.

The classes in this module are in a separate module so the commands not
needing download / PackageFinder capability don't unnecessarily import the
PackageFinder machinery and all its vendored dependencies, etc.

Function Documentation

◆ _create_truststore_ssl_context()

Optional["SSLContext"] _create_truststore_ssl_context ( )
protected

Definition at line 50 of file req_command.py.

50def _create_truststore_ssl_context() -> Optional["SSLContext"]:
51 if sys.version_info < (3, 10):
52 raise CommandError("The truststore feature is only available for Python 3.10+")
53
54 try:
55 import ssl
56 except ImportError:
57 logger.warning("Disabling truststore since ssl support is missing")
58 return None
59
60 try:
61 import truststore
62 except ImportError:
63 raise CommandError(
64 "To use the truststore feature, 'truststore' must be installed into "
65 "pip's current environment."
66 )
67
69
70
for i

References i.

Referenced by SessionCommandMixin._build_session().

Here is the caller graph for this function:

◆ warn_if_run_as_root()

None warn_if_run_as_root ( )
Output a warning for sudo users on Unix.

In a virtual environment, sudo pip still writes to virtualenv.
On Windows, users may run pip as Administrator without issues.
This warning only applies to Unix root users outside of virtualenv.

Definition at line 201 of file req_command.py.

201def warn_if_run_as_root() -> None:
202 """Output a warning for sudo users on Unix.
203
204 In a virtual environment, sudo pip still writes to virtualenv.
205 On Windows, users may run pip as Administrator without issues.
206 This warning only applies to Unix root users outside of virtualenv.
207 """
208 if running_under_virtualenv():
209 return
210 if not hasattr(os, "getuid"):
211 return
212 # On Windows, there are no "system managed" Python packages. Installing as
213 # Administrator via pip is the correct way of updating system environments.
214 #
215 # We choose sys.platform over utils.compat.WINDOWS here to enable Mypy platform
216 # checks: https://mypy.readthedocs.io/en/stable/common_issues.html
217 if sys.platform == "win32" or sys.platform == "cygwin":
218 return
219
220 if os.getuid() != 0:
221 return
222
224 "Running pip as the 'root' user can result in broken permissions and "
225 "conflicting behaviour with the system package manager. "
226 "It is recommended to use a virtual environment instead: "
227 "https://pip.pypa.io/warnings/venv"
228 )
229
230

References i.

◆ with_cleanup()

Any with_cleanup ( Any  func)
Decorator for common logic related to managing temporary
directories.

Definition at line 231 of file req_command.py.

231def with_cleanup(func: Any) -> Any:
232 """Decorator for common logic related to managing temporary
233 directories.
234 """
235
236 def configure_tempdir_registry(registry: TempDirectoryTypeRegistry) -> None:
237 for t in KEEPABLE_TEMPDIR_TYPES:
238 registry.set_delete(t, False)
239
240 def wrapper(
241 self: RequirementCommand, options: Values, args: List[Any]
242 ) -> Optional[int]:
243 assert self.tempdir_registry is not None
245 configure_tempdir_registry(self.tempdir_registry)
246
247 try:
248 return func(self, options, args)
249 except PreviousBuildDirError:
250 # This kind of conflict can occur when the user passes an explicit
251 # build directory with a pre-existing folder. In that case we do
252 # not want to accidentally remove it.
253 configure_tempdir_registry(self.tempdir_registry)
254 raise
255
256 return wrapper
257
258

References i.

Variable Documentation

◆ KEEPABLE_TEMPDIR_TYPES

list KEEPABLE_TEMPDIR_TYPES
Initial value:

Definition at line 194 of file req_command.py.

◆ logger

logger = logging.getLogger(__name__)

Definition at line 47 of file req_command.py.

◆ tempdir_registry

tempdir_registry

Definition at line 245 of file req_command.py.