From 53cee538446ea18f96eb49c28ea226084db22f30 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 29 Jan 2018 16:22:24 +0530 Subject: [PATCH 01/28] Create Bench Virtual Environments --- bench/__init__.py | 2 +- bench/commands/make.py | 18 ++++++++++++------ bench/commands/setup.py | 4 +--- bench/utils.py | 35 +++++++++++++++++++++++++---------- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/bench/__init__.py b/bench/__init__.py index b5c69ef0..e120c37b 100644 --- a/bench/__init__.py +++ b/bench/__init__.py @@ -10,4 +10,4 @@ def set_frappe_version(bench_path='.'): from .app import get_current_frappe_version global FRAPPE_VERSION if not FRAPPE_VERSION: - FRAPPE_VERSION = get_current_frappe_version(bench_path=bench_path) + FRAPPE_VERSION = get_current_frappe_version(bench_path=bench_path) \ No newline at end of file diff --git a/bench/commands/make.py b/bench/commands/make.py index 18a06c92..7a7d289e 100755 --- a/bench/commands/make.py +++ b/bench/commands/make.py @@ -2,6 +2,8 @@ import click @click.command() @click.argument('path') +@click.option('--python', type = click.Choice(['python2', 'python3']), default = 'python2', help = 'Path to Python Executable.') +@click.option('--ignore-exist', is_flag = True, default = False, help = "Ignore if Bench instance exists.") @click.option('--apps_path', default=None, help="path to json files with apps to install after init") @click.option('--frappe-path', default=None, help="path to frappe repo") @click.option('--frappe-branch', default=None, help="path to frappe repo") @@ -9,19 +11,23 @@ import click @click.option('--no-procfile', is_flag=True, help="Pull changes in all the apps in bench") @click.option('--no-backups',is_flag=True, help="Run migrations for all sites in the bench") @click.option('--no-auto-update',is_flag=True, help="Build JS and CSS artifacts for the bench") -@click.option('--verbose',is_flag=True, help="Verbose output during install") -@click.option('--skip-bench-mkdir', is_flag=True, help="Skip mkdir frappe-bench") @click.option('--skip-redis-config-generation', is_flag=True, help="Skip redis config generation if already specifying the common-site-config file") +@click.option('--verbose',is_flag=True, help="Verbose output during install") def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups, - no_auto_update, clone_from, verbose, skip_bench_mkdir, skip_redis_config_generation): - "Create a new bench" + no_auto_update, clone_from, verbose, skip_redis_config_generation, + ignore_exist = False, + python = 'python2'): # Let's change we're ready. - + ''' + Create a New Bench Instance. + ''' from bench.utils import init init(path, apps_path=apps_path, no_procfile=no_procfile, no_backups=no_backups, no_auto_update=no_auto_update, frappe_path=frappe_path, frappe_branch=frappe_branch, - verbose=verbose, clone_from=clone_from, skip_bench_mkdir=skip_bench_mkdir, skip_redis_config_generation=skip_redis_config_generation) + verbose=verbose, clone_from=clone_from, skip_redis_config_generation=skip_redis_config_generation, + ignore_exist = ignore_exist, + python = python) click.echo('Bench {} initialized'.format(path)) - @click.command('get-app') @click.argument('name', nargs=-1) # Dummy argument for backward compatibility @click.argument('git-url') diff --git a/bench/commands/setup.py b/bench/commands/setup.py index adff7ecb..7360a148 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -4,8 +4,7 @@ import click, sys, json def setup(): "Setup bench" pass - - + @click.command('sudoers') @click.argument('user') def setup_sudoers(user): @@ -13,7 +12,6 @@ def setup_sudoers(user): from bench.utils import setup_sudoers setup_sudoers(user) - @click.command('nginx') @click.option('--yes', help='Yes to regeneration of nginx config file', default=False, is_flag=True) def setup_nginx(yes=False): diff --git a/bench/utils.py b/bench/utils.py index caa55445..b6607214 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -27,31 +27,33 @@ def get_env_cmd(cmd, bench_path='.'): def init(path, apps_path=None, no_procfile=False, no_backups=False, no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None, - verbose=False, clone_from=None, skip_bench_mkdir=False, skip_redis_config_generation=False): + verbose=False, clone_from=None, skip_redis_config_generation=False, + ignore_exist = False, + python = 'python2'): # Let's change when we're ready. - from .app import get_app, install_apps_from_path from .config.common_site_config import make_config from .config import redis from .config.procfile import setup_procfile from bench.patches import set_all_patches_executed - if(skip_bench_mkdir): - pass + import os.path as osp + + if osp.exists(path): + if not ignore_exist: + raise ValueError('Bench Instance {path} already exists.'.format(path = path)) else: - if os.path.exists(path): - print('Directory {} already exists!'.format(path)) - raise Exception("Site directory already exists") os.makedirs(path) for dirname in folders_in_bench: try: os.makedirs(os.path.join(path, dirname)) - except OSError, e: + except OSError as e: if e.errno != os.errno.EEXIST: pass setup_logging() - setup_env(bench_path=path) + setup_env(bench_path=path, python = python) make_config(path) @@ -139,8 +141,21 @@ def exec_cmd(cmd, cwd='.'): if return_code > 0: raise CommandFailedError(cmd) -def setup_env(bench_path='.'): - exec_cmd('virtualenv -q {} -p {}'.format('env', sys.executable), cwd=bench_path) +def which(executable, raise_err = False): + from distutils.spawn import find_executable + exec_ = find_executable(executable) + + if not exec_ and raise_err: + raise ValueError('{executable} not found.'.format( + executable = executable + )) + + return exec_ + +def setup_env(bench_path='.', python = 'python2'): + python = which(python, raise_err = True) + + exec_cmd('virtualenv -q {} -p {}'.format('env', python), cwd=bench_path) exec_cmd('./env/bin/pip -q install --upgrade pip', cwd=bench_path) exec_cmd('./env/bin/pip -q install wheel', cwd=bench_path) # exec_cmd('./env/bin/pip -q install https://github.com/frappe/MySQLdb1/archive/MySQLdb-1.2.5-patched.tar.gz', cwd=bench_path) From 1cf00667e94310cd7d62756f3b58c3243a1acf9e Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 29 Jan 2018 17:10:01 +0530 Subject: [PATCH 02/28] generate redis config --- bench/config/redis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bench/config/redis.py b/bench/config/redis.py index 43423c8e..fe102135 100644 --- a/bench/config/redis.py +++ b/bench/config/redis.py @@ -56,8 +56,8 @@ def write_redis_config(template_name, context, bench_path): f.write(template.render(**context)) def get_redis_version(): - version_string = subprocess.check_output('redis-server --version', shell=True).strip() - + version_string = subprocess.check_output('redis-server --version', shell=True) + version_string = version_string.decode('utf-8').strip() # extract version number from string version = re.findall("\d+\.\d+", version_string) if not version: From a120e9e4d6ed00ea87f79124a3920972d4184db9 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 29 Jan 2018 17:30:14 +0530 Subject: [PATCH 03/28] Fixed crontab bytes to str --- bench/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bench/utils.py b/bench/utils.py index b6607214..0b8d7931 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -247,6 +247,7 @@ def setup_backups(bench_path='.'): def add_to_crontab(line): current_crontab = read_crontab() + line = str.encode(line) if not line in current_crontab: cmd = ["crontab"] if platform.system() == 'FreeBSD': From 2b554e55d7e8d20f73775f1022dfce1fd4aad13e Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 29 Jan 2018 17:43:16 +0530 Subject: [PATCH 04/28] byte concat --- bench/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/utils.py b/bench/utils.py index 0b8d7931..be0b36a4 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -254,7 +254,7 @@ def add_to_crontab(line): cmd = ["crontab", "-"] s = subprocess.Popen(cmd, stdin=subprocess.PIPE) s.stdin.write(current_crontab) - s.stdin.write(line + '\n') + s.stdin.write(line + b'\n') s.stdin.close() def read_crontab(): From 762b02c818a34ca570a858f5612decaee5695228 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 29 Jan 2018 17:54:03 +0530 Subject: [PATCH 05/28] decode get_cmd_output --- bench/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bench/cli.py b/bench/cli.py index 830e144a..8e05c9f0 100755 --- a/bench/cli.py +++ b/bench/cli.py @@ -95,7 +95,9 @@ def get_frappe_commands(bench_path='.'): if not os.path.exists(sites_path): return [] try: - return json.loads(get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-commands".format(python=python), cwd=sites_path)) + output = get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-commands".format(python=python), cwd=sites_path) + output = output.decode('utf-8') + return json.loads(output) except subprocess.CalledProcessError: return [] From 0e6291f108c14a0f81449749dddb043d7a36a031 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Tue, 30 Jan 2018 13:17:17 +0530 Subject: [PATCH 06/28] Fixed version string --- bench/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bench/utils.py b/bench/utils.py index be0b36a4..6b1d40c3 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -347,7 +347,9 @@ def check_cmd(cmd, cwd='.'): def get_git_version(): '''returns git version from `git --version` extracts version number from string `get version 1.9.1` etc''' - version = get_cmd_output("git --version").strip().split()[2] + version = get_cmd_output("git --version") + version = version.decode('utf-8') + version = version.strip().split()[2] version = '.'.join(version.split('.')[0:2]) return float(version) From 26059c06fadfd2a386006ef1cf3f0ac7f76119e9 Mon Sep 17 00:00:00 2001 From: Raghavendra Kamath Date: Wed, 31 Jan 2018 10:39:50 +0530 Subject: [PATCH 07/28] Update readme to add new bench logo (#551) * Add new bench logo to the readme * add spacing to the title * Revert "add spacing to the title" This reverts commit 86880d64562a4e7f4226189582536376079fb93c. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index adcf593c..517a0fc1 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -# Bench +
+ +

Frappe Bench

+
[![Build Status](https://travis-ci.org/frappe/bench.svg?branch=master)](https://travis-ci.org/frappe/bench) From 1b2e7838abab899e3a611f4c9f57baabfdfca335 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Wed, 31 Jan 2018 11:12:59 +0530 Subject: [PATCH 08/28] pip-install-fix --- MANIFEST.in | 2 ++ bench/utils.py | 1 + 2 files changed, 3 insertions(+) diff --git a/MANIFEST.in b/MANIFEST.in index 5e899217..898efefa 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,3 +3,5 @@ include *.py recursive-include bench *.conf recursive-include bench *.py recursive-include bench *.txt +recursive-include bench *.json +recursive-include bench/templates * diff --git a/bench/utils.py b/bench/utils.py index 6b1d40c3..1a2a2f80 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -792,3 +792,4 @@ def run_playbook(playbook_name, extra_vars=None, tag=None): args.extend(['-t', tag]) subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks')) + \ No newline at end of file From e2545c97afd638609d0e4c89e76fa3e6d84d85a0 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Fri, 2 Feb 2018 18:48:58 +0530 Subject: [PATCH 09/28] Migrate from one Python Version to Another --- bench/commands/__init__.py | 100 ++++++++++++++++++++++++++++++++++++- bench/commands/setup.py | 1 - 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index 0907f12d..c9427d4a 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -70,4 +70,102 @@ bench_command.add_command(remote_reset_url) bench_command.add_command(remote_urls) from bench.commands.install import install -bench_command.add_command(install) \ No newline at end of file +bench_command.add_command(install) + +# If you're scared with this code, contact me at +import contextlib +import os, shutil, tempfile + +@contextlib.contextmanager +def tempchdir(dirpath, cleanup): + import os.path as osp + basedir = os.getcwd() + os.chdir(osp.expanduser(dirpath)) + try: + yield + finally: + os.chdir(basedir) + cleanup() + +@contextlib.contextmanager +def tempdir(): + import tempfile + dirpath = tempfile.mkdtemp() + def cleanup(): + shutil.rmtree(dirpath) + with tempchdir(dirpath, cleanup): + yield dirpath + +@click.command('migrate-env') +@click.argument('python', type = click.Choice(['python2', 'python3'])) +@click.option('--from', 'from_', help = 'Path to virtual environment to migrate to') +@click.option('--no-backup', default = False, help = 'Do not backup the existing Virtual Environment') +def migrate_env(python, from_ = None, no_backup = False): + """ + Migrate Virtual Environment to desired Python Version. + """ + import os + import os.path as osp + + from bench.utils import which + python = which(python) + + path = os.getcwd() + # This is with the assumption that a bench is set-up within path. + try: + with tempdir() as dirpath: + virtualenv = which('virtualenv') + + nvenv = 'env' + pvenv = osp.join(dirpath, nvenv) + + from bench.utils import exec_cmd + exec_cmd('{virtualenv} --python {python} {pvenv}'.format( + virtualenv = virtualenv, + python = python, + pvenv = pvenv + ), cwd = dirpath) + + # TODO: Options + + papps = osp.join(path, 'apps') + for app in os.listdir(papps): + papp = osp.join(papps, app) + if osp.isdir(papp) and osp.exists(osp.join(papp, 'setup.py')): + pip = osp.join(pvenv, 'bin', 'pip') + exec_cmd('{pip} install -e {app}'.format( + pip = pip, app = papp + )) + + # I know, bad name for a flag. Thanks, Ameya! :| - + if not no_backup: + # Back, the f*ck up. + parch = osp.join(path, 'archived_envs') + if not osp.exists(parch): + os.mkdir(parch) + + # Simply moving. Thanks, Ameya. + # I'm keen to zip. + source = osp.join(path, 'env') + target = parch + + print('Backing up Virtual Environment') + from datetime import datetime + stamp = datetime.now().strftime('%Y%m%d_%H%M%S') + dest = osp.join(path, str(stamp)) + + os.rename(source, dest) + shutil.move(dest, target) + + print('Setting up a New Virtual Environment') + source = pvenv + target = path + + shutil.move(source, target) + + print('Migration Successful') + except: + print('Migration Error') + raise + +bench_command.add_command(migrate_env) \ No newline at end of file diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 7360a148..d2736553 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -45,7 +45,6 @@ def setup_fonts(): from bench.utils import setup_fonts setup_fonts() - @click.command('production') @click.argument('user') @click.option('--yes', help='Yes to regeneration config', is_flag=True, default=False) From 300c3eea08fdab663fbabf98813a48325aaa1daa Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 5 Feb 2018 11:03:11 +0530 Subject: [PATCH 10/28] Moved imports --- bench/commands/__init__.py | 40 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index c9427d4a..d73aadea 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -1,5 +1,17 @@ import click +import os, shutil, tempfile +import os.path as osp +import contextlib +import logging + +from datetime import datetime + +from bench.utils import which, exec_cmd + +log = logging.getLogger(__name__) +log.setLevel(logging.ERROR) + def print_bench_version(ctx, param, value): """Prints current bench version""" if not value or ctx.resilient_parsing: @@ -72,13 +84,8 @@ bench_command.add_command(remote_urls) from bench.commands.install import install bench_command.add_command(install) -# If you're scared with this code, contact me at -import contextlib -import os, shutil, tempfile - @contextlib.contextmanager def tempchdir(dirpath, cleanup): - import os.path as osp basedir = os.getcwd() os.chdir(osp.expanduser(dirpath)) try: @@ -89,7 +96,6 @@ def tempchdir(dirpath, cleanup): @contextlib.contextmanager def tempdir(): - import tempfile dirpath = tempfile.mkdtemp() def cleanup(): shutil.rmtree(dirpath) @@ -98,16 +104,12 @@ def tempdir(): @click.command('migrate-env') @click.argument('python', type = click.Choice(['python2', 'python3'])) -@click.option('--from', 'from_', help = 'Path to virtual environment to migrate to') @click.option('--no-backup', default = False, help = 'Do not backup the existing Virtual Environment') -def migrate_env(python, from_ = None, no_backup = False): +def migrate_env(python, no_backup = False): """ Migrate Virtual Environment to desired Python Version. """ - import os - import os.path as osp - from bench.utils import which python = which(python) path = os.getcwd() @@ -118,8 +120,7 @@ def migrate_env(python, from_ = None, no_backup = False): nvenv = 'env' pvenv = osp.join(dirpath, nvenv) - - from bench.utils import exec_cmd + exec_cmd('{virtualenv} --python {python} {pvenv}'.format( virtualenv = virtualenv, python = python, @@ -149,23 +150,26 @@ def migrate_env(python, from_ = None, no_backup = False): source = osp.join(path, 'env') target = parch - print('Backing up Virtual Environment') - from datetime import datetime + log.debug('Backing up Virtual Environment') stamp = datetime.now().strftime('%Y%m%d_%H%M%S') dest = osp.join(path, str(stamp)) os.rename(source, dest) shutil.move(dest, target) - print('Setting up a New Virtual Environment') + log.debug('Setting up a New Virtual {python} Environment'.format( + python = python + )) source = pvenv target = path shutil.move(source, target) - print('Migration Successful') + log.debug('Migration Successful to {python}'.format( + python = python + )) except: - print('Migration Error') + log.debug('Migration Error') raise bench_command.add_command(migrate_env) \ No newline at end of file From 12c73a8cf392bf1a946f70fe66c408bfb7d284a8 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 5 Feb 2018 15:32:28 +0530 Subject: [PATCH 11/28] [py3] install frappe first --- bench/commands/__init__.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index d73aadea..bfb11894 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -26,7 +26,6 @@ def print_bench_version(ctx, param, value): def bench_command(bench_path='.'): """Bench manager for Frappe""" import bench - from bench.app import get_current_frappe_version from bench.utils import setup_logging bench.set_frappe_version(bench_path=bench_path) @@ -117,7 +116,7 @@ def migrate_env(python, no_backup = False): try: with tempdir() as dirpath: virtualenv = which('virtualenv') - + nvenv = 'env' pvenv = osp.join(dirpath, nvenv) @@ -129,9 +128,12 @@ def migrate_env(python, no_backup = False): # TODO: Options - papps = osp.join(path, 'apps') - for app in os.listdir(papps): - papp = osp.join(papps, app) + apps_path = osp.join(path, 'apps') + apps = os.listdir(apps_path) + apps = ['frappe'] + [app for app in apps if app!='frappe'] + + for app in apps: + papp = osp.join(apps_path, app) if osp.isdir(papp) and osp.exists(osp.join(papp, 'setup.py')): pip = osp.join(pvenv, 'bin', 'pip') exec_cmd('{pip} install -e {app}'.format( @@ -144,7 +146,7 @@ def migrate_env(python, no_backup = False): parch = osp.join(path, 'archived_envs') if not osp.exists(parch): os.mkdir(parch) - + # Simply moving. Thanks, Ameya. # I'm keen to zip. source = osp.join(path, 'env') @@ -153,10 +155,10 @@ def migrate_env(python, no_backup = False): log.debug('Backing up Virtual Environment') stamp = datetime.now().strftime('%Y%m%d_%H%M%S') dest = osp.join(path, str(stamp)) - + os.rename(source, dest) shutil.move(dest, target) - + log.debug('Setting up a New Virtual {python} Environment'.format( python = python )) @@ -164,7 +166,7 @@ def migrate_env(python, no_backup = False): target = path shutil.move(source, target) - + log.debug('Migration Successful to {python}'.format( python = python )) From 0de8bf0ea7ef0b5265632d8decd0701a77d7d1fa Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 5 Feb 2018 18:42:29 +0530 Subject: [PATCH 12/28] updated migrate-env --- bench/commands/__init__.py | 116 +++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 51 deletions(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index d73aadea..260f8650 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -102,6 +102,17 @@ def tempdir(): with tempchdir(dirpath, cleanup): yield dirpath +def copytree(source, destination, symlinks = False, ignore = None): + for f in os.listdir(source): + + s = os.path.join(source, f) + d = os.path.join(destination, f) + + if os.path.isdir(s): + shutil.copytree(s, d, symlinks, ignore) + else: + shutil.copy2(s, d) + @click.command('migrate-env') @click.argument('python', type = click.Choice(['python2', 'python3'])) @click.option('--no-backup', default = False, help = 'Do not backup the existing Virtual Environment') @@ -109,62 +120,65 @@ def migrate_env(python, no_backup = False): """ Migrate Virtual Environment to desired Python Version. """ - - python = which(python) - - path = os.getcwd() - # This is with the assumption that a bench is set-up within path. try: - with tempdir() as dirpath: - virtualenv = which('virtualenv') + # This is with the assumption that a bench is set-up within path. + path = os.getcwd() + + # I know, bad name for a flag. Thanks, Ameya! :| - + if not no_backup: + # Back, the f*ck up. + parch = osp.join(path, 'archived_envs') + if not osp.exists(parch): + os.mkdir(parch) - nvenv = 'env' - pvenv = osp.join(dirpath, nvenv) + # Simply moving. Thanks, Ameya. + # I'm keen to zip. + source = osp.join(path, 'env') + target = parch - exec_cmd('{virtualenv} --python {python} {pvenv}'.format( - virtualenv = virtualenv, - python = python, - pvenv = pvenv - ), cwd = dirpath) - - # TODO: Options - - papps = osp.join(path, 'apps') - for app in os.listdir(papps): - papp = osp.join(papps, app) - if osp.isdir(papp) and osp.exists(osp.join(papp, 'setup.py')): - pip = osp.join(pvenv, 'bin', 'pip') - exec_cmd('{pip} install -e {app}'.format( - pip = pip, app = papp - )) - - # I know, bad name for a flag. Thanks, Ameya! :| - - if not no_backup: - # Back, the f*ck up. - parch = osp.join(path, 'archived_envs') - if not osp.exists(parch): - os.mkdir(parch) - - # Simply moving. Thanks, Ameya. - # I'm keen to zip. - source = osp.join(path, 'env') - target = parch - - log.debug('Backing up Virtual Environment') - stamp = datetime.now().strftime('%Y%m%d_%H%M%S') - dest = osp.join(path, str(stamp)) - - os.rename(source, dest) - shutil.move(dest, target) + log.debug('Backing up Virtual Environment') + stamp = datetime.now().strftime('%Y%m%d_%H%M%S') + dest = osp.join(path, str(stamp)) - log.debug('Setting up a New Virtual {python} Environment'.format( - python = python - )) - source = pvenv - target = path - - shutil.move(source, target) + # WARNING: This is an archive, you might have to use virtualenv --relocate + # That's because virtualenv creates symlinks with shebangs pointing to executables. + + # ...and shutil.copytree is a f*cking mess. + os.rename(source, dest) + shutil.move(dest, target) + log.debug('Setting up a New Virtual {python} Environment'.format( + python = python + )) + + # Path to Python Executable (Basically $PYTHONPTH) + python = which(python) + + + virtualenv = which('virtualenv') + + nvenv = 'env' + pvenv = osp.join(path, nvenv) + + exec_cmd('{virtualenv} --python {python} {pvenv}'.format( + virtualenv = virtualenv, + python = python, + pvenv = pvenv + ), cwd = path) + + # TODO: Options + + papps = osp.join(path, 'apps') + apps = ['frappe'] + [app for app in os.listdir(papps) if app != 'frappe'] + + for app in apps: + papp = osp.join(papps, app) + if osp.isdir(papp) and osp.exists(osp.join(papp, 'setup.py')): + pip = osp.join(pvenv, 'bin', 'pip') + exec_cmd('{pip} install -e {app}'.format( + pip = pip, app = papp + )) + log.debug('Migration Successful to {python}'.format( python = python )) From a3f6c4b3466cfd4f6b934963f3c3c82439a6a017 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 5 Feb 2018 18:46:41 +0530 Subject: [PATCH 13/28] Removed copytree --- bench/commands/__init__.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index 6d104873..a5be0f43 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -101,17 +101,6 @@ def tempdir(): with tempchdir(dirpath, cleanup): yield dirpath -def copytree(source, destination, symlinks = False, ignore = None): - for f in os.listdir(source): - - s = os.path.join(source, f) - d = os.path.join(destination, f) - - if os.path.isdir(s): - shutil.copytree(s, d, symlinks, ignore) - else: - shutil.copy2(s, d) - @click.command('migrate-env') @click.argument('python', type = click.Choice(['python2', 'python3'])) @click.option('--no-backup', default = False, help = 'Do not backup the existing Virtual Environment') From e446848ae05d69265cf97ca0e665a6ab77cbcb03 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 5 Feb 2018 18:54:44 +0530 Subject: [PATCH 14/28] removed tempdir --- bench/commands/__init__.py | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index a5be0f43..646b7f86 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -1,8 +1,7 @@ import click -import os, shutil, tempfile +import os, shutil import os.path as osp -import contextlib import logging from datetime import datetime @@ -83,24 +82,6 @@ bench_command.add_command(remote_urls) from bench.commands.install import install bench_command.add_command(install) -@contextlib.contextmanager -def tempchdir(dirpath, cleanup): - basedir = os.getcwd() - os.chdir(osp.expanduser(dirpath)) - try: - yield - finally: - os.chdir(basedir) - cleanup() - -@contextlib.contextmanager -def tempdir(): - dirpath = tempfile.mkdtemp() - def cleanup(): - shutil.rmtree(dirpath) - with tempchdir(dirpath, cleanup): - yield dirpath - @click.command('migrate-env') @click.argument('python', type = click.Choice(['python2', 'python3'])) @click.option('--no-backup', default = False, help = 'Do not backup the existing Virtual Environment') From b5839dafebfd88dea22eb214fb1613535ab34b38 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 7 Feb 2018 15:55:28 +0530 Subject: [PATCH 15/28] fix path executable to python3 --- bench/commands/__init__.py | 12 ++++++------ bench/commands/make.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index 646b7f86..4eedad79 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -83,7 +83,7 @@ from bench.commands.install import install bench_command.add_command(install) @click.command('migrate-env') -@click.argument('python', type = click.Choice(['python2', 'python3'])) +@click.argument('python', type = str) @click.option('--no-backup', default = False, help = 'Do not backup the existing Virtual Environment') def migrate_env(python, no_backup = False): """ @@ -99,7 +99,7 @@ def migrate_env(python, no_backup = False): parch = osp.join(path, 'archived_envs') if not osp.exists(parch): os.mkdir(parch) - + # Simply moving. Thanks, Ameya. # I'm keen to zip. source = osp.join(path, 'env') @@ -108,18 +108,18 @@ def migrate_env(python, no_backup = False): log.debug('Backing up Virtual Environment') stamp = datetime.now().strftime('%Y%m%d_%H%M%S') dest = osp.join(path, str(stamp)) - + # WARNING: This is an archive, you might have to use virtualenv --relocate # That's because virtualenv creates symlinks with shebangs pointing to executables. - + # ...and shutil.copytree is a f*cking mess. os.rename(source, dest) shutil.move(dest, target) - + log.debug('Setting up a New Virtual {python} Environment'.format( python = python )) - + # Path to Python Executable (Basically $PYTHONPTH) python = which(python) diff --git a/bench/commands/make.py b/bench/commands/make.py index 7a7d289e..eb0c21ba 100755 --- a/bench/commands/make.py +++ b/bench/commands/make.py @@ -2,7 +2,7 @@ import click @click.command() @click.argument('path') -@click.option('--python', type = click.Choice(['python2', 'python3']), default = 'python2', help = 'Path to Python Executable.') +@click.option('--python', type = str, default = 'python2', help = 'Path to Python Executable.') @click.option('--ignore-exist', is_flag = True, default = False, help = "Ignore if Bench instance exists.") @click.option('--apps_path', default=None, help="path to json files with apps to install after init") @click.option('--frappe-path', default=None, help="path to frappe repo") From 780c1b74886711d87d9408020c2ca6e29d9acd5a Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Wed, 7 Feb 2018 17:12:32 +0530 Subject: [PATCH 16/28] get apps from both, frappe and erpnext --- bench/app.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/bench/app.py b/bench/app.py index 64bac73c..a61bab83 100755 --- a/bench/app.py +++ b/bench/app.py @@ -48,10 +48,40 @@ def write_appstxt(apps, bench_path='.'): with open(os.path.join(bench_path, 'sites', 'apps.txt'), 'w') as f: return f.write('\n'.join(apps)) +def check_url(url, raise_err = True): + try: + from urlparse import urlparse + except ImportError: + from urllib.parse import urlparse + + parsed = urlparse(url) + if not parsed.scheme: + if raise_err: + raise TypeError('{url} Not a valid URL'.format(url = url)) + else: + return False + + return True + def get_app(git_url, branch=None, bench_path='.', build_asset_files=True, verbose=False): - #less verbose app install - if '/' not in git_url: - git_url = 'https://github.com/frappe/' + git_url + # from bench.utils import check_url + try: + from urlparse import urljoin + except ImportError: + from urllib.parse import urljoin + + if not check_url(git_url, raise_err = False): + orgs = ['frappe', 'erpnext'] + for org in orgs: + url = 'https://api.github.com/repos/{org}/{app}'.format(org = org, app = git_url) + res = requests.get(url) + if res.ok: + data = res.json() + if 'name' in data: + if git_url == data['name']: + git_url = 'https://github.com/{org}/{app}'.format(org = org, app = git_url) + break + #Gets repo name from URL repo_name = git_url.rsplit('/', 1)[1].rsplit('.', 1)[0] logger.info('getting app {}'.format(repo_name)) From 8876a401759487baaba0af691aeb7c97f6c1a4b7 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Fri, 9 Feb 2018 10:56:17 +0530 Subject: [PATCH 17/28] [fix] update setuptools and pip before creating virtual env and use system default python --- bench/commands/__init__.py | 4 +++- bench/commands/make.py | 4 ++-- bench/commands/setup.py | 5 +++-- bench/utils.py | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index 4eedad79..e4ecb8c3 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -135,6 +135,9 @@ def migrate_env(python, no_backup = False): pvenv = pvenv ), cwd = path) + pip = osp.join(pvenv, 'bin', 'pip') + exec_cmd('{pip} install --upgrade pip'.format(pip=pip)) + exec_cmd('{pip} install --upgrade setuptools'.format(pip=pip)) # TODO: Options papps = osp.join(path, 'apps') @@ -143,7 +146,6 @@ def migrate_env(python, no_backup = False): for app in apps: papp = osp.join(papps, app) if osp.isdir(papp) and osp.exists(osp.join(papp, 'setup.py')): - pip = osp.join(pvenv, 'bin', 'pip') exec_cmd('{pip} install -e {app}'.format( pip = pip, app = papp )) diff --git a/bench/commands/make.py b/bench/commands/make.py index eb0c21ba..639868ed 100755 --- a/bench/commands/make.py +++ b/bench/commands/make.py @@ -2,7 +2,7 @@ import click @click.command() @click.argument('path') -@click.option('--python', type = str, default = 'python2', help = 'Path to Python Executable.') +@click.option('--python', type = str, default = 'python', help = 'Path to Python Executable.') @click.option('--ignore-exist', is_flag = True, default = False, help = "Ignore if Bench instance exists.") @click.option('--apps_path', default=None, help="path to json files with apps to install after init") @click.option('--frappe-path', default=None, help="path to frappe repo") @@ -16,7 +16,7 @@ import click def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups, no_auto_update, clone_from, verbose, skip_redis_config_generation, ignore_exist = False, - python = 'python2'): # Let's change we're ready. - + python = 'python'): # Let's change we're ready. - ''' Create a New Bench Instance. ''' diff --git a/bench/commands/setup.py b/bench/commands/setup.py index d2736553..053e6357 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -68,10 +68,11 @@ def setup_backups(): setup_backups() @click.command('env') -def setup_env(): +@click.option('--python', type = str, default = 'python', help = 'Path to Python Executable.') +def setup_env(python='python'): "Setup virtualenv for bench" from bench.utils import setup_env - setup_env() + setup_env(python=python) @click.command('firewall') @click.option('--ssh_port') diff --git a/bench/utils.py b/bench/utils.py index 1a2a2f80..aafa29cd 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -29,7 +29,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None, verbose=False, clone_from=None, skip_redis_config_generation=False, ignore_exist = False, - python = 'python2'): # Let's change when we're ready. - + python = 'python'): # Let's change when we're ready. - from .app import get_app, install_apps_from_path from .config.common_site_config import make_config from .config import redis @@ -152,7 +152,7 @@ def which(executable, raise_err = False): return exec_ -def setup_env(bench_path='.', python = 'python2'): +def setup_env(bench_path='.', python = 'python'): python = which(python, raise_err = True) exec_cmd('virtualenv -q {} -p {}'.format('env', python), cwd=bench_path) From 12224b70868cfeaf6d50da790388990421d56caf Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Thu, 15 Feb 2018 12:45:05 +0530 Subject: [PATCH 18/28] bytes to str --- bench/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/app.py b/bench/app.py index a61bab83..87a8681f 100755 --- a/bench/app.py +++ b/bench/app.py @@ -269,7 +269,7 @@ def get_upstream_version(app, branch=None, bench_path='.'): try: contents = subprocess.check_output(['git', 'show', 'upstream/{branch}:{app}/__init__.py'.format(branch=branch, app=app)], cwd=repo_dir, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - if "Invalid object" in e.output: + if b"Invalid object" in e.output: return None else: raise From 5d0a453ccbced78a2edb7dd11e632f8b5ff958c3 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 19 Feb 2018 13:11:21 +0530 Subject: [PATCH 19/28] [fix] update_npm_packages, patch to install yarn (#572) --- bench/package.json | 18 ---------------- bench/patches/patches.txt | 2 +- bench/patches/v4/install_yarn.py | 4 ++++ bench/utils.py | 36 ++++++-------------------------- 4 files changed, 11 insertions(+), 49 deletions(-) delete mode 100644 bench/package.json create mode 100644 bench/patches/v4/install_yarn.py diff --git a/bench/package.json b/bench/package.json deleted file mode 100644 index 31121283..00000000 --- a/bench/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "frappe", - "description": "Default package.json for frappe apps", - "dependencies": { - "babel-core": "^6.24.1", - "babel-preset-babili": "0.0.12", - "babel-preset-es2015": "^6.24.1", - "babel-preset-es2016": "^6.24.1", - "babel-preset-es2017": "^6.24.1", - "chokidar": "^1.7.0", - "cookie": "^0.3.1", - "express": "^4.15.3", - "less": "^2.7.2", - "redis": "^2.7.1", - "socket.io": "^2.0.1", - "superagent": "^3.5.2" - } -} diff --git a/bench/patches/patches.txt b/bench/patches/patches.txt index e979b0d6..f9adc549 100644 --- a/bench/patches/patches.txt +++ b/bench/patches/patches.txt @@ -3,4 +3,4 @@ bench.patches.v3.celery_to_rq bench.patches.v3.redis_bind_ip bench.patches.v4.update_node bench.patches.v4.update_socketio - +bench.patches.v4.install_yarn diff --git a/bench/patches/v4/install_yarn.py b/bench/patches/v4/install_yarn.py new file mode 100644 index 00000000..4ea0c23a --- /dev/null +++ b/bench/patches/v4/install_yarn.py @@ -0,0 +1,4 @@ +import subprocess + +def execute(bench_path): + subprocess.check_output(['npm', 'install', '-g', 'yarn']) \ No newline at end of file diff --git a/bench/utils.py b/bench/utils.py index aafa29cd..3ce3f264 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -144,7 +144,7 @@ def exec_cmd(cmd, cwd='.'): def which(executable, raise_err = False): from distutils.spawn import find_executable exec_ = find_executable(executable) - + if not exec_ and raise_err: raise ValueError('{executable} not found.'.format( executable = executable @@ -430,34 +430,11 @@ def update_requirements(bench_path='.'): def update_npm_packages(bench_path='.'): print('Updating node libraries...') apps_dir = os.path.join(bench_path, 'apps') - package_json = {} for app in os.listdir(apps_dir): - package_json_path = os.path.join(apps_dir, app, 'package.json') + app_path = os.path.join(apps_dir, app) + exec_cmd('yarn install', cwd=app_path) - if os.path.exists(package_json_path): - with open(package_json_path, "r") as f: - app_package_json = json.loads(f.read()) - # package.json is usually a dict in a dict - for key, value in iteritems(app_package_json): - if not key in package_json: - package_json[key] = value - else: - if isinstance(value, dict): - package_json[key].update(value) - elif isinstance(value, list): - package_json[key].extend(value) - else: - package_json[key] = value - - if package_json is {}: - with open(os.path.join(os.path.dirname(__file__), 'package.json'), 'r') as f: - package_json = json.loads(f.read()) - - with open(os.path.join(bench_path, 'package.json'), 'w') as f: - f.write(json.dumps(package_json, indent=1, sort_keys=True)) - - exec_cmd('npm install', cwd=bench_path) def install_requirements(pip, req_file): if os.path.exists(req_file): @@ -784,12 +761,11 @@ def run_playbook(playbook_name, extra_vars=None, tag=None): print("Ansible is needed to run this command, please install it using 'pip install ansible'") sys.exit(1) args = ['ansible-playbook', '-c', 'local', playbook_name] - + if extra_vars: args.extend(['-e', json.dumps(extra_vars)]) - + if tag: args.extend(['-t', tag]) - + subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks')) - \ No newline at end of file From 884c0766d2979131d4b76cd2f55f5f152a9f69d6 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 19 Feb 2018 14:26:25 +0530 Subject: [PATCH 20/28] install yarn using sudo (#574) --- bench/patches/v4/install_yarn.py | 2 +- bench/utils.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bench/patches/v4/install_yarn.py b/bench/patches/v4/install_yarn.py index 4ea0c23a..a9ef438e 100644 --- a/bench/patches/v4/install_yarn.py +++ b/bench/patches/v4/install_yarn.py @@ -1,4 +1,4 @@ import subprocess def execute(bench_path): - subprocess.check_output(['npm', 'install', '-g', 'yarn']) \ No newline at end of file + subprocess.check_output(['sudo', 'npm', 'install', '-g', 'yarn']) \ No newline at end of file diff --git a/bench/utils.py b/bench/utils.py index 3ce3f264..6a2d77df 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -433,7 +433,8 @@ def update_npm_packages(bench_path='.'): for app in os.listdir(apps_dir): app_path = os.path.join(apps_dir, app) - exec_cmd('yarn install', cwd=app_path) + if os.path.exists(os.path.join(app_path, 'package.json')): + exec_cmd('yarn install', cwd=app_path) def install_requirements(pip, req_file): From 72968e6bb5efded0eeca44635694369ec2dc57c1 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 19 Feb 2018 18:03:37 +0530 Subject: [PATCH 21/28] Install yarn locally --- bench/patches/v4/install_yarn.py | 5 +++-- bench/utils.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bench/patches/v4/install_yarn.py b/bench/patches/v4/install_yarn.py index a9ef438e..e29868e9 100644 --- a/bench/patches/v4/install_yarn.py +++ b/bench/patches/v4/install_yarn.py @@ -1,4 +1,5 @@ -import subprocess +import os +from bench.utils import exec_cmd def execute(bench_path): - subprocess.check_output(['sudo', 'npm', 'install', '-g', 'yarn']) \ No newline at end of file + exec_cmd('npm install yarn', os.path.join(bench_path, 'apps/frappe')) diff --git a/bench/utils.py b/bench/utils.py index 6a2d77df..37f27853 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -434,7 +434,7 @@ def update_npm_packages(bench_path='.'): for app in os.listdir(apps_dir): app_path = os.path.join(apps_dir, app) if os.path.exists(os.path.join(app_path, 'package.json')): - exec_cmd('yarn install', cwd=app_path) + exec_cmd('./node_modules/.bin/yarn install', cwd=app_path) def install_requirements(pip, req_file): From 37b2bbd3790c402ad5c4a583453b591124fd0f04 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 19 Feb 2018 18:10:58 +0530 Subject: [PATCH 22/28] trigger yarn patch again --- bench/patches/patches.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/patches/patches.txt b/bench/patches/patches.txt index f9adc549..754068c5 100644 --- a/bench/patches/patches.txt +++ b/bench/patches/patches.txt @@ -3,4 +3,4 @@ bench.patches.v3.celery_to_rq bench.patches.v3.redis_bind_ip bench.patches.v4.update_node bench.patches.v4.update_socketio -bench.patches.v4.install_yarn +bench.patches.v4.install_yarn #2 From b77434bb616e2f02787dc2370c89f26774d7053b Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 19 Feb 2018 20:25:35 +0530 Subject: [PATCH 23/28] Install yarn if not found --- bench/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bench/utils.py b/bench/utils.py index 37f27853..25e58925 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -434,7 +434,10 @@ def update_npm_packages(bench_path='.'): for app in os.listdir(apps_dir): app_path = os.path.join(apps_dir, app) if os.path.exists(os.path.join(app_path, 'package.json')): - exec_cmd('./node_modules/.bin/yarn install', cwd=app_path) + yarn_executable = './node_modules/.bin/yarn' + if not os.path.exists(os.path.join(app_path, yarn_executable)): + exec_cmd('npm install yarn', cwd=app_path) + exec_cmd('{yarn} install'.format(yarn=yarn_executable), cwd=app_path) def install_requirements(pip, req_file): From 6a233a9b5c9e667041079d1ffe47c9e5b73d0b26 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Tue, 20 Feb 2018 11:28:59 +0530 Subject: [PATCH 24/28] [FIX] start node processes right after python and redis --- bench/config/templates/Procfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bench/config/templates/Procfile b/bench/config/templates/Procfile index 9a1e3ce2..5eb9d093 100644 --- a/bench/config/templates/Procfile +++ b/bench/config/templates/Procfile @@ -3,8 +3,6 @@ redis_socketio: redis-server config/redis_socketio.conf redis_queue: redis-server config/redis_queue.conf web: bench serve {% if webserver_port -%} --port {{ webserver_port }} {%- endif %} -socketio: {{ node }} apps/frappe/socketio.js -watch: bench watch {% if use_rq -%} schedule: bench schedule worker_short: bench worker --queue short @@ -16,3 +14,6 @@ worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n longjob_worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n longjobs@%h -Ofair --soft-time-limit 1500 --time-limit 1530' async_worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n async@%h -Ofair --soft-time-limit 1500 --time-limit 1530' {%- endif %} + +socketio: {{ node }} apps/frappe/socketio.js +watch: bench watch \ No newline at end of file From adfc11008a68190f12b2f0d5531a481703187231 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 20 Feb 2018 13:19:42 +0530 Subject: [PATCH 25/28] Disable watch in CI --- bench/config/procfile.py | 3 ++- bench/config/templates/Procfile | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bench/config/procfile.py b/bench/config/procfile.py index 3e4183e9..3dd7cece 100755 --- a/bench/config/procfile.py +++ b/bench/config/procfile.py @@ -13,7 +13,8 @@ def setup_procfile(bench_path, yes=False): procfile = bench.env.get_template('Procfile').render( node=find_executable("node") or find_executable("nodejs"), use_rq=use_rq(bench_path), - webserver_port=config.get('webserver_port')) + webserver_port=config.get('webserver_port'), + CI=os.environ.get('CI')) with open(procfile_path, 'w') as f: f.write(procfile) diff --git a/bench/config/templates/Procfile b/bench/config/templates/Procfile index 9a1e3ce2..c465bbac 100644 --- a/bench/config/templates/Procfile +++ b/bench/config/templates/Procfile @@ -4,7 +4,9 @@ redis_queue: redis-server config/redis_queue.conf web: bench serve {% if webserver_port -%} --port {{ webserver_port }} {%- endif %} socketio: {{ node }} apps/frappe/socketio.js +{% if not CI %} watch: bench watch +{% endif %} {% if use_rq -%} schedule: bench schedule worker_short: bench worker --queue short From 6e73871e55e3be2a2f34aa6fad34a409418d46a8 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 20 Feb 2018 13:21:10 +0530 Subject: [PATCH 26/28] Restore process order --- bench/config/templates/Procfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/bench/config/templates/Procfile b/bench/config/templates/Procfile index 9be36064..c465bbac 100644 --- a/bench/config/templates/Procfile +++ b/bench/config/templates/Procfile @@ -18,6 +18,3 @@ worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n longjob_worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n longjobs@%h -Ofair --soft-time-limit 1500 --time-limit 1530' async_worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n async@%h -Ofair --soft-time-limit 1500 --time-limit 1530' {%- endif %} - -socketio: {{ node }} apps/frappe/socketio.js -watch: bench watch \ No newline at end of file From 4497267269719176dfb64c517af886b0d326f6ad Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 20 Feb 2018 17:12:19 +0530 Subject: [PATCH 27/28] Prompt to install yarn in global --- bench/utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bench/utils.py b/bench/utils.py index 25e58925..db869760 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -431,13 +431,15 @@ def update_npm_packages(bench_path='.'): print('Updating node libraries...') apps_dir = os.path.join(bench_path, 'apps') + if not find_executable('yarn'): + print("Please install yarn using below command and try again.") + print("`npm install -g yarn`") + return + for app in os.listdir(apps_dir): app_path = os.path.join(apps_dir, app) if os.path.exists(os.path.join(app_path, 'package.json')): - yarn_executable = './node_modules/.bin/yarn' - if not os.path.exists(os.path.join(app_path, yarn_executable)): - exec_cmd('npm install yarn', cwd=app_path) - exec_cmd('{yarn} install'.format(yarn=yarn_executable), cwd=app_path) + exec_cmd('yarn install', cwd=app_path) def install_requirements(pip, req_file): From c06307e50de525f2d07b86f6dc5e3e723c1f5c33 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Wed, 21 Feb 2018 16:27:11 +0530 Subject: [PATCH 28/28] installs yarn globally (#580) --- playbooks/prerequisites/roles/nodejs/tasks/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/playbooks/prerequisites/roles/nodejs/tasks/main.yml b/playbooks/prerequisites/roles/nodejs/tasks/main.yml index a72750a3..e521c27d 100644 --- a/playbooks/prerequisites/roles/nodejs/tasks/main.yml +++ b/playbooks/prerequisites/roles/nodejs/tasks/main.yml @@ -37,3 +37,8 @@ update_cache: yes force: yes when: ansible_os_family == 'Debian' or ansible_distribution == 'Ubuntu' + +- name: Install yarn + command: npm install -g yarn + become: yes + become_user: root \ No newline at end of file