summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/install.py
diff options
context:
space:
mode:
authorTarek Ziade <tarek@ziade.org>2011-05-31 10:09:34 (GMT)
committerTarek Ziade <tarek@ziade.org>2011-05-31 10:09:34 (GMT)
commit5a5ce388ed3d67cd32f83a00ccf00ebbeaecb323 (patch)
tree2bdc0b05fe7195abfd8e3f7ae83124e7aa148ba6 /Lib/packaging/install.py
parent62ecb6aa0ae8dbfabe1f42cdda1eb6c1a184c3e7 (diff)
downloadcpython-5a5ce388ed3d67cd32f83a00ccf00ebbeaecb323.zip
cpython-5a5ce388ed3d67cd32f83a00ccf00ebbeaecb323.tar.gz
cpython-5a5ce388ed3d67cd32f83a00ccf00ebbeaecb323.tar.bz2
make sure we check for write access before starting the install, and add correct exit code
Diffstat (limited to 'Lib/packaging/install.py')
-rw-r--r--Lib/packaging/install.py48
1 files changed, 40 insertions, 8 deletions
diff --git a/Lib/packaging/install.py b/Lib/packaging/install.py
index 9f94532..4b82088 100644
--- a/Lib/packaging/install.py
+++ b/Lib/packaging/install.py
@@ -6,7 +6,6 @@ obtained from an index (e.g. PyPI), with dependencies.
This is a higher-level module built on packaging.database and
packaging.pypi.
"""
-
import os
import sys
import stat
@@ -14,7 +13,7 @@ import errno
import shutil
import logging
import tempfile
-from sysconfig import get_config_var
+from sysconfig import get_config_var, get_path
from packaging import logger
from packaging.dist import Distribution
@@ -28,6 +27,8 @@ from packaging.depgraph import generate_graph
from packaging.errors import (PackagingError, InstallationException,
InstallationConflict, CCompilerError)
from packaging.pypi.errors import ProjectNotFound, ReleaseNotFound
+from packaging import database
+
__all__ = ['install_dists', 'install_from_infos', 'get_infos', 'remove',
'install', 'install_local_project']
@@ -75,6 +76,7 @@ def _run_distutils_install(path):
def _run_setuptools_install(path):
cmd = '%s setup.py install --record=%s --single-version-externally-managed'
record_file = os.path.join(path, 'RECORD')
+
os.system(cmd % (sys.executable, record_file))
if not os.path.exists(record_file):
raise ValueError('failed to install')
@@ -88,8 +90,10 @@ def _run_packaging_install(path):
dist.parse_config_files()
try:
dist.run_command('install_dist')
+ name = dist.metadata['name']
+ return database.get_distribution(name) is not None
except (IOError, os.error, PackagingError, CCompilerError) as msg:
- raise SystemExit("error: " + str(msg))
+ raise ValueError("Failed to install, " + str(msg))
def _install_dist(dist, path):
@@ -115,18 +119,20 @@ def install_local_project(path):
If the source directory contains a setup.py install using distutils1.
If a setup.cfg is found, install using the install_dist command.
+ Returns True on success, False on Failure.
"""
path = os.path.abspath(path)
if os.path.isdir(path):
logger.info('Installing from source directory: %s', path)
- _run_install_from_dir(path)
+ return _run_install_from_dir(path)
elif _is_archive_file(path):
logger.info('Installing from archive: %s', path)
_unpacked_dir = tempfile.mkdtemp()
shutil.unpack_archive(path, _unpacked_dir)
- _run_install_from_archive(_unpacked_dir)
+ return _run_install_from_archive(_unpacked_dir)
else:
logger.warning('No projects to install.')
+ return False
def _run_install_from_archive(source_dir):
@@ -152,7 +158,13 @@ def _run_install_from_dir(source_dir):
func = install_methods[install_method]
try:
func = install_methods[install_method]
- return func(source_dir)
+ try:
+ func(source_dir)
+ return True
+ except ValueError as err:
+ # failed to install
+ logger.info(str(err))
+ return False
finally:
os.chdir(old_dir)
@@ -472,16 +484,34 @@ def remove(project_name, paths=sys.path, auto_confirm=True):
def install(project):
+ """Installs a project.
+
+ Returns True on success, False on failure
+ """
+ logger.info('Checking the installation location...')
+ purelib_path = get_path('purelib')
+ # trying to write a file there
+ try:
+ with tempfile.NamedTemporaryFile(suffix=project,
+ dir=purelib_path) as testfile:
+ testfile.write(b'test')
+ except OSError:
+ # was unable to write a file
+ logger.info('Unable to write in "%s". Do you have the permissions ?'
+ % purelib_path)
+ return False
+
+
logger.info('Getting information about %r...', project)
try:
info = get_infos(project)
except InstallationException:
logger.info('Cound not find %r', project)
- return
+ return False
if info['install'] == []:
logger.info('Nothing to install')
- return
+ return False
install_path = get_config_var('base')
try:
@@ -493,6 +523,8 @@ def install(project):
projects = ['%s %s' % (p.name, p.version) for p in e.args[0]]
logger.info('%r conflicts with %s', project, ','.join(projects))
+ return True
+
def _main(**attrs):
if 'script_args' not in attrs: