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

Data Structures

class  InstallCommand
 

Functions

List[str] get_lib_location_guesses (bool user=False, Optional[str] home=None, Optional[str] root=None, bool isolated=False, Optional[str] prefix=None)
 
bool site_packages_writable (Optional[str] root, bool isolated)
 
bool decide_user_install (Optional[bool] use_user_site, Optional[str] prefix_path=None, Optional[str] target_dir=None, Optional[str] root_path=None, bool isolated_mode=False)
 
str create_os_error_message (OSError error, bool show_traceback, bool using_user_site)
 

Variables

 logger = getLogger(__name__)
 

Function Documentation

◆ create_os_error_message()

str create_os_error_message ( OSError  error,
bool  show_traceback,
bool   using_user_site 
)
Format an error message for an OSError

It may occur anytime during the execution of the install command.

Definition at line 724 of file install.py.

726) -> str:
727 """Format an error message for an OSError
728
729 It may occur anytime during the execution of the install command.
730 """
731 parts = []
732
733 # Mention the error if we are not going to show a traceback
734 parts.append("Could not install packages due to an OSError")
735 if not show_traceback:
736 parts.append(": ")
737 parts.append(str(error))
738 else:
739 parts.append(".")
740
741 # Spilt the error indication from a helper message (if any)
742 parts[-1] += "\n"
743
744 # Suggest useful actions to the user:
745 # (1) using user site-packages or (2) verifying the permissions
747 user_option_part = "Consider using the `--user` option"
748 permissions_part = "Check the permissions"
749
750 if not running_under_virtualenv() and not using_user_site:
752 [
753 user_option_part,
754 " or ",
756 ]
757 )
758 else:
759 parts.append(permissions_part)
760 parts.append(".\n")
761
762 # Suggest the user to enable Long Paths if path length is
763 # more than 260
764 if (
765 WINDOWS
768 and len(error.filename) > 260
769 ):
771 "HINT: This error might have occurred since "
772 "this system does not have Windows Long Path "
773 "support enabled. You can find information on "
774 "how to enable this at "
775 "https://pip.pypa.io/warnings/enable-long-paths\n"
776 )
777
778 return "".join(parts).strip() + "\n"
for i

References i.

Referenced by InstallCommand.run().

Here is the caller graph for this function:

◆ decide_user_install()

bool decide_user_install ( Optional[bool]  use_user_site,
Optional[str]   prefix_path = None,
Optional[str]   target_dir = None,
Optional[str]   root_path = None,
bool   isolated_mode = False 
)
Determine whether to do a user install based on the input options.

If use_user_site is False, no additional checks are done.
If use_user_site is True, it is checked for compatibility with other
options.
If use_user_site is None, the default behaviour depends on the environment,
which is provided by the other arguments.

Definition at line 663 of file install.py.

669) -> bool:
670 """Determine whether to do a user install based on the input options.
671
672 If use_user_site is False, no additional checks are done.
673 If use_user_site is True, it is checked for compatibility with other
674 options.
675 If use_user_site is None, the default behaviour depends on the environment,
676 which is provided by the other arguments.
677 """
678 # In some cases (config from tox), use_user_site can be set to an integer
679 # rather than a bool, which 'use_user_site is False' wouldn't catch.
680 if (use_user_site is not None) and (not use_user_site):
681 logger.debug("Non-user install by explicit request")
682 return False
683
684 if use_user_site:
685 if prefix_path:
686 raise CommandError(
687 "Can not combine '--user' and '--prefix' as they imply "
688 "different installation locations"
689 )
690 if virtualenv_no_global():
691 raise InstallationError(
692 "Can not perform a '--user' install. User site-packages "
693 "are not visible in this virtualenv."
694 )
695 logger.debug("User install by explicit request")
696 return True
697
698 # If we are here, user installs have not been explicitly requested/avoided
699 assert use_user_site is None
700
701 # user install incompatible with --prefix/--target
702 if prefix_path or target_dir:
703 logger.debug("Non-user install due to --prefix or --target option")
704 return False
705
706 # If user installs are not enabled, choose a non-user install
708 logger.debug("Non-user install because user site-packages disabled")
709 return False
710
711 # If we have permission for a non-user install, do that,
712 # otherwise do a user install.
713 if site_packages_writable(root=root_path, isolated=isolated_mode):
714 logger.debug("Non-user install because site-packages writeable")
715 return False
716
718 "Defaulting to user installation because normal site-packages "
719 "is not writeable"
720 )
721 return True
722
723

References i, and pip._internal.commands.install.site_packages_writable().

Referenced by InstallCommand.run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_lib_location_guesses()

List[str] get_lib_location_guesses ( bool   user = False,
Optional[str]   home = None,
Optional[str]   root = None,
bool   isolated = False,
Optional[str]   prefix = None 
)

Definition at line 638 of file install.py.

644) -> List[str]:
645 scheme = get_scheme(
646 "",
647 user=user,
648 home=home,
649 root=root,
650 isolated=isolated,
651 prefix=prefix,
652 )
654
655

References i.

Referenced by InstallCommand.run(), and pip._internal.commands.install.site_packages_writable().

Here is the caller graph for this function:

◆ site_packages_writable()

bool site_packages_writable ( Optional[str]  root,
bool  isolated 
)

Definition at line 656 of file install.py.

656def site_packages_writable(root: Optional[str], isolated: bool) -> bool:
657 return all(
658 test_writable_dir(d)
659 for d in set(get_lib_location_guesses(root=root, isolated=isolated))
660 )
661
662

References pip._internal.commands.install.get_lib_location_guesses().

Referenced by pip._internal.commands.install.decide_user_install().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ logger

logger = getLogger(__name__)

Definition at line 49 of file install.py.