Skip to content

Commit

Permalink
Merge pull request #71 from michaeljoseph/fabric
Browse files Browse the repository at this point in the history
Use fabric for local virtualenv operations
  • Loading branch information
michaeljoseph committed Jul 14, 2014
2 parents 7252d5a + 7f514a0 commit 127911b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 32 deletions.
33 changes: 14 additions & 19 deletions changes/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@

def install():
module_name, dry_run, new_version = config.common_arguments()
commands = ['setup.py', 'clean', 'bdist_wheel']

result = shell.handle_dry_run(sh.python, tuple(commands))

if result:
with util.mktmpdir() as tmp_dir:
venv.create_venv(tmp_dir=tmp_dir)
package_name = config.arguments.get('--package-name') or module_name
try:
print(package_name)
print(tmp_dir)
venv.install(package_name, tmp_dir)
log.info('Successfully installed %s sdist', module_name)
if verification.run_test_command():
log.info('Successfully ran test command: %s',
config.arguments['--test-command'])
except Exception, e:
raise Exception('Error installing %s sdist', module_name, e)
commands = ['setup.py', 'clean', 'sdist', 'bdist_wheel']
try:
if (shell.handle_dry_run(sh.python, tuple(commands))):
with util.mktmpdir() as tmp_dir:
venv.create_venv(tmp_dir=tmp_dir)
for distribution in path('dist').files():
venv.install(distribution, tmp_dir)
log.info('Successfully installed %s sdist', module_name)
if verification.run_test_command():
log.info('Successfully ran test command: %s',
config.arguments['--test-command'])
except Exception, e:
raise Exception('Error installing distribution %s' % distribution, e)


def upload():
Expand All @@ -40,7 +35,7 @@ def upload():

upload_result = shell.handle_dry_run(sh.python, tuple(upload_args))
if not upload_result:
raise Exception('Error uploading')
raise Exception('Error uploading: %s' % upload_result)
else:
log.info('Successfully uploaded %s %s', module_name, new_version)

Expand Down
10 changes: 5 additions & 5 deletions changes/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
log = logging.getLogger(__name__)


def handle_dry_run(function, *args):
def handle_dry_run(fn, *args):
if not config.arguments.get('--dry-run', True):
return function(*args)
return fn(*args)
else:
log.debug('dry run of %s %s, skipping' % (function, args))
return True
log.debug('dry run of %s %s, skipping' % (fn, args))
return True


def execute(command, dry_run=True):
if not dry_run:
try:
return check_output(command.split(' ')).split('\n')
except CalledProcessError as e:
log.debug('return code: %s, output: %s', e.returncode, e.output)
log.error('return code: %s, output: %s', e.returncode, e.output)
return False
else:
log.debug('dry run of %s, skipping' % command)
Expand Down
9 changes: 3 additions & 6 deletions changes/venv.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import os
import tempfile

import virtualenv
from fabric.api import local


def create_venv(tmp_dir=None):
if not tmp_dir:
tmp_dir = tempfile.mkdtemp()
virtualenv.create_environment(tmp_dir, site_packages=False)
local('virtualenv --no-site-packages %s' % tmp_dir)
return tmp_dir


def install(package_name, venv_dir):
if not os.path.exists(venv_dir):
venv_dir = create_venv()
virtualenv.install_wheel(
[package_name],
'%s/bin/python' % venv_dir,
)
local('%s/bin/pip install %s' % (venv_dir, package_name))
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Fabric < 2.0.0
coverage < 4.0.0
docopt < 1.0.0
flake8 < 3.0.0
Expand All @@ -14,5 +15,4 @@ sphinxcontrib-httpdomain < 2.0.0
testtube < 1.0.0
tox < 2.0.0
unittest2 < 1.0.0
virtualenv-api < 2.1.0
wheel < 1.0.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
url=metadata['url'],
packages=['changes'],
install_requires=[
'Fabric < 2.0.0',
'docopt < 1.0.0',
'path.py < 5.0.0',
'semantic_version < 3.0.0',
'sh < 2.0.0',
'virtualenv < 2.0.0',
'wheel < 1.0.0',
],
entry_points={
Expand Down

0 comments on commit 127911b

Please sign in to comment.