Skip to content

Commit

Permalink
Port packaging to sh
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljoseph committed Oct 24, 2013
1 parent 182fb0a commit e22b2d5
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions changes/packaging.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import virtualenv
import logging
import tempfile

from path import path
import sh
import virtualenv

from changes import config, shell, testing
from changes import config, shell, verification

log = logging.getLogger(__name__)


def make_virtualenv():
Expand All @@ -13,19 +19,19 @@ def make_virtualenv():
def install():
app_name, dry_run, new_version = config.common_arguments()

result = shell.execute('python setup.py clean sdist', dry_run=dry_run)
result = shell.handle_dry_run(sh.python, ('setup.py', 'clean', 'sdist'))
if result:
tmp_dir = make_virtualenv()
try:
virtualenv.install_sdist(
arguments['<app_name>'],
config.arguments['<app_name>'],
'dist/%s-%s.tar.gz' % (app_name, new_version),
'%s/bin/python' % tmp_dir
)
log.info('Successfully installed %s sdist', app_name)
if testing.run_test_command():
if verification.run_test_command():
log.info('Successfully ran test command: %s',
arguments['--test-command'])
config.arguments['--test-command'])
except:
raise Exception('Error installing %s sdist', app_name)

Expand All @@ -34,41 +40,45 @@ def install():

def upload():
app_name, dry_run, new_version = config.common_arguments()
pypi = arguments['--pypi']
pypi = config.arguments['--pypi']

upload = 'python setup.py clean sdist upload'
upload_args = 'setup.py clean sdist upload'.split(' ')
if pypi:
upload = upload + '-r %s' % pypi
upload_args.extend(['-r', pypi])

if not shell.execute(upload, dry_run=dry_run):
upload_result = shell.handle_dry_run(sh.python, tuple(upload_args))
if not upload_result:
raise Exception('Error uploading')
else:
log.info('Succesfully uploaded %s %s', app_name, new_version)


def pypi():
app_name, dry_run, _ = config.common_arguments()
pypi = arguments['--pypi']
package_index = 'pypi'

tmp_dir = make_virtualenv()
install = '%s/bin/pip install %s' % (tmp_dir, app_name)
install_args = ('%s/bin/pip install %s' % (tmp_dir, app_name)).split(' ')

package_index = 'pypi'
pypi = config.arguments['--pypi']
if pypi:
install = install + '-i %s' % pypi
install_args.extend('-i', pypi)
package_index = pypi

install_args = tuple(install_args)
log.debug(install_args)
try:
result = shell.execute(install, dry_run=dry_run)
result = shell.handle_dry_run(sh, install_args)
if result:
log.info('Successfully installed %s from %s',
app_name, package_index)
else:
log.error('Failed to install %s from %s',
app_name, package_index)

testing.run_test_command()
verification.run_test_command()
except:
log.exception('error installing %s from %s', app_name, package_index)
raise Exception('Error installing %s from %s', app_name, package_index)

path(tmp_dir).rmtree(path(tmp_dir))

0 comments on commit e22b2d5

Please sign in to comment.