Skip to content

Commit

Permalink
Merge pull request #38 from cloudify-cosmo/36-use-correct-python-exec…
Browse files Browse the repository at this point in the history
…utable

36 use correct python executable
  • Loading branch information
nir0s committed May 26, 2016
2 parents fde6717 + 6d4b4d6 commit 744b8e0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ coverage.xml
docs/_build/

*.iml
.idea/*

*COMMIT_MSG
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# * See the License for the specific language governing permissions and
# * limitations under the License.

from setuptools import setup
import os
import codecs
from setuptools import setup

here = os.path.abspath(os.path.dirname(__file__))

Expand All @@ -27,13 +27,13 @@ def read(*parts):

setup(
name='wagon',
version='0.3.0',
version='0.3.1',
url='https://github.com/cloudify-cosmo/wagon',
author='Gigaspaces',
author_email='[email protected]',
license='LICENSE',
platforms='All',
description='Creates Python Wheel based archives.',
description='Creates Python Wheel based archives with dependencies.',
long_description=read('README.rst'),
packages=['wagon'],
include_package_data=True,
Expand Down
20 changes: 9 additions & 11 deletions wagon/tests/test_wagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
# * See the License for the specific language governing permissions and
# * limitations under the License.

import click.testing as clicktest
from contextlib import closing
import tarfile
import testtools
import os
import json
import shutil
import tarfile
import tempfile
from contextlib import closing

import testtools
import click.testing as clicktest

import wagon.wagon as wagon
import wagon.utils as utils
Expand Down Expand Up @@ -51,12 +52,12 @@ def _invoke_click(func, args_dict):
class TestUtils(testtools.TestCase):

def test_run(self):
p = utils.run('uname')
self.assertEqual(0, p.returncode)
proc = utils.run('uname')
self.assertEqual(0, proc.returncode)

def test_run_bad_command(self):
p = utils.run('suname')
self.assertEqual(1 if utils.IS_WIN else 127, p.returncode)
proc = utils.run('suname')
self.assertEqual(1 if utils.IS_WIN else 127, proc.returncode)

def test_download_file(self):
utils.download_file(TEST_FILE, 'file')
Expand Down Expand Up @@ -163,7 +164,6 @@ class TestCreate(testtools.TestCase):

def setUp(self):
super(TestCreate, self).setUp()
self.runner = clicktest.CliRunner()
self.wagon = wagon.Wagon(TEST_PACKAGE, verbose=True)
if utils.IS_WIN:
self.wagon.platform = 'win32'
Expand Down Expand Up @@ -381,7 +381,6 @@ class TestInstall(testtools.TestCase):

def setUp(self):
super(TestInstall, self).setUp()
self.runner = clicktest.CliRunner()
self.packager = wagon.Wagon(TEST_PACKAGE, verbose=True)
utils.run('virtualenv test_env')
self.archive_path = self.packager.create(force=True)
Expand All @@ -408,7 +407,6 @@ class TestValidate(testtools.TestCase):

def setUp(self):
super(TestValidate, self).setUp()
self.runner = clicktest.CliRunner()
self.packager = wagon.Wagon(TEST_PACKAGE, verbose=True)
self.archive_path = self.packager.create(force=True)
utils.untar(self.archive_path, '.')
Expand Down
32 changes: 19 additions & 13 deletions wagon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
# * limitations under the License.

import os
import subprocess
import re
import sys
import time
import json
import urllib
import shutil
import tarfile
import zipfile
import logging
from threading import Thread
import time
import sys
from contextlib import closing
import platform
import tempfile
import json
import shutil
import subprocess
from threading import Thread
from contextlib import closing

from wheel import pep425tags as wheel_tags

Expand All @@ -40,7 +40,7 @@
PLATFORM = sys.platform
IS_WIN = (os.name == 'nt')
IS_DARWIN = (PLATFORM == 'darwin')
IS_LINUX = (PLATFORM == 'linux2')
IS_LINUX = PLATFORM.startswith('linux')

PROCESS_POLLING_INTERVAL = 0.1

Expand Down Expand Up @@ -98,7 +98,8 @@ def run(cmd, suppress_errors=False, suppress_output=False):
def wheel(package, requirement_files=False, wheels_path='package',
excluded_packages=None, wheel_args=None, no_deps=False):
lgr.info('Downloading Wheels for {0}...'.format(package))
wheel_cmd = ['pip', 'wheel']
pip_executable = os.path.join(os.path.dirname(sys.executable), 'pip')
wheel_cmd = [pip_executable, 'wheel']
wheel_cmd.append('--wheel-dir={0}'.format(wheels_path))
wheel_cmd.append('--find-links={0}'.format(wheels_path))
if no_deps:
Expand All @@ -121,6 +122,7 @@ def wheel(package, requirement_files=False, wheels_path='package',
lgr.error('Could not download wheels for: {0}. '
'Please verify that the package you are trying '
'to wheel is wheelable.'.format(package))
lgr.error(p.aggr_stdout)
sys.exit(codes.errors['failed_to_wheel'])
wheels = get_downloaded_wheels(wheels_path)
excluded_packages = excluded_packages or []
Expand Down Expand Up @@ -158,9 +160,10 @@ def install_package(package, wheels_path, virtualenv_path=None,
# install_args = install_args or []

lgr.info('Installing {0}...'.format(package))

pip_cmd = ['pip', 'install']
pip_executable = os.path.join(os.path.dirname(sys.executable), 'pip')
pip_cmd = [pip_executable, 'install']
if virtualenv_path:
pip_cmd = ['pip', 'install']
pip_cmd[0] = os.path.join(
_get_env_bin_path(virtualenv_path), pip_cmd[0])
if requirements_file:
Expand Down Expand Up @@ -286,8 +289,11 @@ def _get_env_bin_path(env_path):
def check_installed(package, virtualenv):
"""Checks to see if a package is installed within a virtualenv.
"""
pip_path = os.path.join(_get_env_bin_path(virtualenv), 'pip')
p = run('{0} freeze'.format(pip_path), suppress_output=True)
if virtualenv:
pip_executable = os.path.join(_get_env_bin_path(virtualenv), 'pip')
else:
pip_executable = os.path.join(os.path.dirname(sys.executable), 'pip')
p = run('{0} freeze'.format(pip_executable), suppress_output=True)
if re.search(r'{0}'.format(package), p.aggr_stdout.lower()):
lgr.debug('Package {0} is installed in {1}'.format(
package, virtualenv))
Expand Down
14 changes: 7 additions & 7 deletions wagon/wagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# * See the License for the specific language governing permissions and
# * limitations under the License.

import logging
import os
import sys
import json
import shutil
import logging
import tempfile
import json

import click

Expand Down Expand Up @@ -403,10 +403,10 @@ def get_source_name_and_version(self, source):
if os.path.isfile(os.path.join(source, 'setup.py')):
lgr.debug('setup.py file found. Retrieving name and version...')
setuppy_path = os.path.join(source, 'setup.py')
self.name = utils.run('python {0} --name'.format(
setuppy_path)).aggr_stdout.rstrip('\r\n')
self.version = utils.run('python {0} --version'.format(
setuppy_path)).aggr_stdout.rstrip('\r\n')
self.name = utils.run('{0} {1} --name'.format(
sys.executable, setuppy_path)).aggr_stdout.rstrip('\r\n')
self.version = utils.run('{0} {1} --version'.format(
sys.executable, setuppy_path)).aggr_stdout.rstrip('\r\n')
# TODO: maybe we don't want to be that explicit and allow using >=
elif '==' in source:
self.name, self.version = source.split('==')
Expand Down Expand Up @@ -543,7 +543,7 @@ def validate(source, verbose):
logger.configure()
validator = Wagon(source, verbose)
if not validator.validate():
sys.exit('validation_failed')
sys.exit(codes.errors['validation_failed'])


@click.command()
Expand Down

0 comments on commit 744b8e0

Please sign in to comment.