From fd2cc9872c8a016643910fdff12118cfcfbc38a9 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Thu, 4 Sep 2014 13:08:43 +0530 Subject: [PATCH] add git cache, fix #43 --- bench/app.py | 7 ++++++- bench/cli.py | 8 +++++++- bench/templates/cached_requirements.txt | 26 +++++++++++++++++++++++++ bench/utils.py | 18 ++++++++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 bench/templates/cached_requirements.txt diff --git a/bench/app.py b/bench/app.py index c5ba0142..9b4d5513 100644 --- a/bench/app.py +++ b/bench/app.py @@ -35,7 +35,12 @@ def new_app(app, bench='.'): def install_app(app, bench='.'): logger.info('installing {}'.format(app)) - exec_cmd("{pip} install -e {app}".format(pip=os.path.join(bench, 'env', 'bin', 'pip'), app=os.path.join(bench, 'apps', app))) + conf = get_config() + find_links = '--find-links={}'.format(conf.get('wheel_cache_dir')) if conf.get('wheel_cache_dir') else '' + exec_cmd("{pip} install {find_links} -e {app}".format( + pip=os.path.join(bench, 'env', 'bin', 'pip'), + app=os.path.join(bench, 'apps', app), + find_links=find_links)) add_to_appstxt(app, bench=bench) def pull_all_apps(bench='.'): diff --git a/bench/cli.py b/bench/cli.py index 7cf7de3f..538efcd6 100644 --- a/bench/cli.py +++ b/bench/cli.py @@ -11,7 +11,7 @@ from .utils import set_nginx_port as _set_nginx_port from .utils import set_default_site as _set_default_site from .utils import (build_assets, patch_sites, exec_cmd, update_bench, get_frappe, setup_logging, get_config, update_config, restart_supervisor_processes, put_config, default_config, update_requirements, - backup_all_sites, backup_site, get_sites) + backup_all_sites, backup_site, get_sites, prime_wheel_cache) from .app import get_app as _get_app from .app import new_app as _new_app from .app import pull_all_apps @@ -169,6 +169,11 @@ def _backup_all_sites(): "backup all sites" backup_all_sites(bench='.') +@click.command('prime-wheel-cache') +def _prime_wheel_cache(): + "Update wheel cache" + prime_wheel_cache(bench='.') + ## Setup @click.group() def setup(): @@ -303,3 +308,4 @@ bench.add_command(migrate_3to4) bench.add_command(shell) bench.add_command(_backup_all_sites) bench.add_command(_backup_site) +bench.add_command(_prime_wheel_cache) diff --git a/bench/templates/cached_requirements.txt b/bench/templates/cached_requirements.txt new file mode 100644 index 00000000..dbbb6b05 --- /dev/null +++ b/bench/templates/cached_requirements.txt @@ -0,0 +1,26 @@ +chardet +cssmin +dropbox +gunicorn +httplib2 +jinja2 +markdown2 +markupsafe +mysql-python +pygeoip +python-dateutil +python-memcached +pytz==2013d +six +slugify +termcolor +werkzeug +semantic_version +rauth>=0.6.2 +requests==1.2.3 +celery +redis +selenium +unidecode +babel +pdfkit diff --git a/bench/utils.py b/bench/utils.py index 7cd757da..edea7086 100644 --- a/bench/utils.py +++ b/bench/utils.py @@ -25,7 +25,7 @@ def get_frappe(bench='.'): return frappe def init(path, apps_path=None, no_procfile=False, no_backups=False, - no_auto_update=False, frappe_path=None): + no_auto_update=False, frappe_path=None, wheel_cache_dir=None): from .app import get_app, install_apps_from_path if os.path.exists(path): print 'Directory {} already exists!'.format(path) @@ -39,6 +39,9 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, setup_env(bench=path) put_config(default_config, bench=path) + if wheel_cache_dir: + update_config({"wheel_cache_dir":wheel_cache_dir}, bench=path) + prime_wheel_cache(bench=path) if not frappe_path: frappe_path = 'https://github.com/frappe/frappe.git' get_app('frappe', frappe_path, bench=path) @@ -60,6 +63,7 @@ def exec_cmd(cmd, cwd='.'): def setup_env(bench='.'): exec_cmd('virtualenv {} -p {}'.format('env', sys.executable), cwd=bench) + exec_cmd('./env/bin/pip install wheel', cwd=bench) def setup_procfile(bench='.'): with open(os.path.join(bench, 'Procfile'), 'w') as f: @@ -244,3 +248,15 @@ def backup_site(site, bench='.'): def backup_all_sites(bench='.'): for site in get_sites(bench=bench): backup_site(site, bench=bench) + +def prime_wheel_cache(bench='.'): + conf = get_config(bench=bench) + wheel_cache_dir = conf.get('wheel_cache_dir') + if not wheel_cache_dir: + raise Exception("Wheel cache dir not configured") + requirements = os.path.join(os.path.dirname(__file__), 'templates', 'cached_requirements.txt') + cmd = "{pip} wheel --find-links {wheelhouse} --wheel-dir {wheelhouse} -r {requirements}".format( + pip=os.path.join(bench, 'env', 'bin', 'pip'), + wheelhouse=wheel_cache_dir, + requirements=requirements) + exec_cmd(cmd)