Skip to content

Instantly share code, notes, and snippets.

@gavinwhyte
Last active August 29, 2021 11:09
Show Gist options
  • Save gavinwhyte/3e899801b21dac9bce93a396d98bc334 to your computer and use it in GitHub Desktop.
Save gavinwhyte/3e899801b21dac9bce93a396d98bc334 to your computer and use it in GitHub Desktop.
fabfile.py
"""
Fabric configuration for a Python 3.3 environment using Anaconda.
"""
from fabric.api import run, cd
from fabric.context_managers import prefix
CONDA_REPO = 'http://repo.continuum.io/miniconda/'
CONDA_VERS = 'Miniconda3-3.0.0-Linux-x86_64.sh'
DEPENDENCIES = [
'pip',
'numpy',
'scipy',
'matplotlib',
'ipython',
'scikit-learn',
'scikit-image',
'pandas',
'geos',
'requests']
def setup(install_prefix='~'):
"""
Install an anaconda environment.
"""
_base_environment(install_prefix)
_dependencies(install_prefix)
def _dependencies(install_prefix):
"""
Install a set of binary packages and then some patched packages to support
Python > 3.
"""
with prefix('source {}/anaconda/bin/activate python-devel'.format(install_prefix)):
for module in DEPENDENCIES:
run('{}/anaconda/bin/conda install --yes {}'.format(install_prefix, module))
# PyProj (requires proj4 on the remote system)
with cd('{}/downloads'.format(install_prefix)):
run('svn checkout http://pyproj.googlecode.com/svn/trunk/ pyproj')
with cd('pyproj'):
run('python setup.py build install')
run('rm -rf pyproj')
# CartoPy (like basemap)
run('pip install git+https://github.com/esc24/cartopy.git@three_osx_new')
# Fabric
run('pip install git+https://github.com/scottkmaxwell/paramiko.git@py3-support-without-py25')
run('pip install contextlib2')
run('pip install git+https://github.com/pashinin/fabric.git@p33')
def _base_environment(install_prefix):
"""
Creates a "standard" python working environment.
"""
run('mkdir -p {}/downloads'.format(install_prefix))
with cd('{}/downloads'.format(install_prefix)):
run('wget -nv -N {}{}'.format(CONDA_REPO, CONDA_VERS))
run('sh {} -b -p {}/anaconda/'.format(CONDA_VERS, install_prefix))
with cd('{}/anaconda/bin'.format(install_prefix)):
run('./conda create --yes -n python-devel python=3.7')
def clean(install_prefix='~'):
"""
Removes a standard working environment.
"""
run('rm -rf {}/anaconda'.format(install_prefix))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment