Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions thoth/solver/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from contextlib import contextmanager
import logging
import typing
from shlex import quote

from thoth.analyzer import CommandError
from thoth.analyzer import run_command
Expand All @@ -30,7 +29,7 @@ def _filter_pipdeptree_entry(entry: dict) ->dict:

def _get_environment_details(python_bin: str) -> list:
"""Get information about packages in environment where packages get installed."""
cmd = '{} -m pipdeptree --json'.format(python_bin)
cmd = [python_bin, '-m', 'pipdeptree', '--json']
output = run_command(cmd, is_json=True).stdout
return [_filter_pipdeptree_entry(entry) for entry in output]

Expand All @@ -40,11 +39,14 @@ def _install_requirement(python_bin: str, package: str, version: str=None, index
"""Install requirements specified using suggested pip binary."""
previous_version = _pipdeptree(python_bin, package)

cmd = '{} -m pip install --force-reinstall --no-cache-dir --no-deps {}'.format(python_bin, quote(package))
cmd = [python_bin, '-m', 'pip', 'install', '--force-reinstall', '--no-cache-dir', '--no-deps']
if version:
cmd += '=={}'.format(quote(version))
cmd.append('{}=={}'.format(package, version))
else:
cmd.append(package)
if index_url:
cmd += ' --index-url "{}" '.format(quote(index_url))
cmd.append('--index_url')
cmd.append(index_url)

_LOGGER.debug("Installing requirement %r in version %r", package, version)
run_command(cmd)
Expand All @@ -57,10 +59,8 @@ def _install_requirement(python_bin: str, package: str, version: str=None, index
_LOGGER.debug("Restoring previous environment setup after installation of %r", package)

if previous_version:
cmd = '{} -m pip install --force-reinstall ' \
'--no-cache-dir --no-deps {}=={}'.format(python_bin,
quote(package),
quote(previous_version['package']['installed_version']))
cmd = [python_bin, '-m', 'pip', 'install', '--force-reinstall', '--no-cache-dir', '--no-deps',
'{}=={}'.format(package, previous_version['package']['installed_version'])]
_LOGGER.debug("Installing previous version %r of package %r",
package, previous_version['package']['installed_version'])
result = run_command(cmd, raise_on_error=False)
Expand All @@ -72,7 +72,7 @@ def _install_requirement(python_bin: str, package: str, version: str=None, index
return
else:
_LOGGER.debug("Removing installed package %r", package)
cmd = '{} -m pip uninstall --yes {}'.format(python_bin, quote(package))
cmd = [python_bin, '-m', 'pip', 'uninstall', '--yes', package]
result = run_command(cmd, raise_on_error=False)

if result.return_code != 0:
Expand All @@ -83,7 +83,7 @@ def _install_requirement(python_bin: str, package: str, version: str=None, index

def _pipdeptree(python_bin, package_name: str=None, warn: bool=False) -> typing.Optional[dict]:
"""Get pip dependency tree by executing pipdeptree tool."""
cmd = '{} -m pipdeptree --json'.format(python_bin)
cmd = [python_bin, '-m', 'pipdeptree', '--json']

_LOGGER.debug("Obtaining pip dependency tree using: %r", cmd)
output = run_command(cmd, is_json=True).stdout
Expand Down