本文整理汇总了Python中pip.commands.install.InstallCommand方法的典型用法代码示例。如果您正苦于以下问题:Python install.InstallCommand方法的具体用法?Python install.InstallCommand怎么用?Python install.InstallCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip.commands.install
的用法示例。
在下文中一共展示了install.InstallCommand方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: patch_setuptools
# 需要导入模块: from pip.commands import install [as 别名]
# 或者: from pip.commands.install import InstallCommand [as 别名]
def patch_setuptools(fetch_directives=('index_url', 'find_links')):
orig = easy_install.finalize_options
def patched_finalize_options(self):
cmd = PipInstallCommand()
config = cmd.parser.parse_args([])[0]
for option in fetch_directives:
try:
value = getattr(config, option)
except AttributeError:
continue
setattr(self, option, value)
orig(self)
easy_install.finalize_options = patched_finalize_options
示例2: install_missing_requirements
# 需要导入模块: from pip.commands import install [as 别名]
# 或者: from pip.commands.install import InstallCommand [as 别名]
def install_missing_requirements(module):
"""
Some of the modules require external packages to be installed. This gets
the list from the `REQUIREMENTS` module attribute and attempts to
install the requirements using pip.
:param module: GPIO module
:type module: ModuleType
:return: None
:rtype: NoneType
"""
reqs = getattr(module, "REQUIREMENTS", [])
if not reqs:
_LOG.info("Module %r has no extra requirements to install." % module)
return
import pkg_resources
pkgs_installed = pkg_resources.WorkingSet()
pkgs_required = []
for req in reqs:
if pkgs_installed.find(pkg_resources.Requirement.parse(req)) is None:
pkgs_required.append(req)
if pkgs_required:
from pip.commands.install import InstallCommand
from pip.status_codes import SUCCESS
cmd = InstallCommand()
result = cmd.main(pkgs_required)
if result != SUCCESS:
raise CannotInstallModuleRequirements(
"Unable to install packages for module %r (%s)..." % (
module, pkgs_required))
示例3: install
# 需要导入模块: from pip.commands import install [as 别名]
# 或者: from pip.commands.install import InstallCommand [as 别名]
def install(params):
"""
Install third-party Mod
"""
from pip import main as pip_main
from pip.commands.install import InstallCommand
params = [param for param in params]
options, mod_list = InstallCommand().parse_args(params)
params = ["install"] + params
for mod_name in mod_list:
mod_name_index = params.index(mod_name)
if mod_name in system_mod:
print('System Mod can not be installed or uninstalled')
return
if "rqalpha_mod_" in mod_name:
lib_name = mod_name
mod_name = lib_name.replace("rqalpha_mod_", "")
else:
lib_name = "rqalpha_mod_" + mod_name
params[mod_name_index] = lib_name
# Install Mod
pip_main(params)
# Export config
config_path = get_default_config_path()
config = load_config(config_path, loader=yaml.RoundTripLoader)
for mod_name in mod_list:
if "rqalpha_mod_" in mod_name:
lib_name = mod_name
mod_name = lib_name.replace("rqalpha_mod_", "")
else:
lib_name = "rqalpha_mod_" + mod_name
mod = import_module(lib_name)
mod_config = yaml.load(mod.__mod_config__, yaml.RoundTripLoader)
config['mod'][mod_name] = mod_config
config['mod'][mod_name]['lib'] = lib_name
config['mod'][mod_name]['enabled'] = False
config['mod'][mod_name]['priority'] = 1000
dump_config(config_path, config)
示例4: bootstrap
# 需要导入模块: from pip.commands import install [as 别名]
# 或者: from pip.commands.install import InstallCommand [as 别名]
def bootstrap(tmpdir=None):
# Import pip so we can use it to install pip and maybe setuptools too
import pip
from pip.commands.install import InstallCommand
# Wrapper to provide default certificate with the lowest priority
class CertInstallCommand(InstallCommand):
def parse_args(self, args):
# If cert isn't specified in config or environment, we provide our
# own certificate through defaults.
# This allows user to specify custom cert anywhere one likes:
# config, environment variable or argv.
if not self.parser.get_default_values().cert:
self.parser.defaults["cert"] = cert_path # calculated below
return super(CertInstallCommand, self).parse_args(args)
pip.commands_dict["install"] = CertInstallCommand
# We always want to install pip
packages = ["pip"]
# Check if the user has requested us not to install setuptools
if "--no-setuptools" in sys.argv or os.environ.get("PIP_NO_SETUPTOOLS"):
args = [x for x in sys.argv[1:] if x != "--no-setuptools"]
else:
args = sys.argv[1:]
# We want to see if setuptools is available before attempting to
# install it
try:
import setuptools # noqa
except ImportError:
packages += ["setuptools"]
delete_tmpdir = False
try:
# Create a temporary directory to act as a working directory if we were
# not given one.
if tmpdir is None:
tmpdir = tempfile.mkdtemp()
delete_tmpdir = True
# We need to extract the SSL certificates from requests so that they
# can be passed to --cert
cert_path = os.path.join(tmpdir, "cacert.pem")
with open(cert_path, "wb") as cert:
cert.write(pkgutil.get_data("pip._vendor.requests", "cacert.pem"))
# Execute the included pip and use it to install the latest pip and
# setuptools from PyPI
sys.exit(pip.main(["install", "--upgrade"] + packages + args))
finally:
# Remove our temporary directory
if delete_tmpdir and tmpdir:
shutil.rmtree(tmpdir, ignore_errors=True)
开发者ID:PacktPublishing,项目名称:Arduino-Building-exciting-LED-based-projects-and-espionage-devices,代码行数:57,代码来源:get-pip.py