Skip to content

Commit

Permalink
Merge branch 'develop' into fix-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza authored Jun 10, 2020
2 parents 52ee67f + e26a0a9 commit 70cb41f
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 210 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,19 @@ In case the setup fails, the log file is saved under `/tmp/logs/install_bench.lo
- Create an Issue in this repository with the log file attached.
- Search for an existing issue or post the log file on the [Frappe/ERPNext Discuss Forum](https://discuss.erpnext.com/c/bench) with the tag `installation_problem` under "Install/Update" category.

For more information and advanced setup instructions, check out the [Easy Install Documentation](https://github.com/frappe/bench/blob/master/docs/easy_install.md).
For more information and advanced setup instructions, check out the [Easy Install Documentation](https://github.com/frappe/bench/blob/develop/docs/easy_install.md).


### Manual Installation

Although not recommended, some might want to manually setup a bench instance locally for development. To quickly get started on installing bench the hard way, you can follow [Installing Bench and Frappe](https://frappe.io/docs/user/en/installation).
Some might want to manually setup a bench instance locally for development. To quickly get started on installing bench the hard way, you can follow the guide on [Installing Bench and the Frappe Framework](https://frappe.io/docs/user/en/installation).

You'll have to set up the system dependencies required for setting up a Frappe Environment. Checkout [docs/installation](https://github.com/frappe/bench/blob/develop/docs/installation.md) for more information on this. If you've already set up, install bench via pip:


```sh
$ pip install frappe-bench
```

For more extensive distribution-dependent documentation, check out the following guides:

Expand Down Expand Up @@ -200,12 +207,12 @@ For more extensive distribution-dependent documentation, check out the following
```


For more in-depth information on commands and their usage, follow [Commands and Usage](https://github.com/frappe/bench/blob/master/docs/commands_and_usage.md). As for a consolidated list of bench commands, check out [Bench Usage](https://github.com/frappe/bench/blob/master/docs/bench_usage.md).
For more in-depth information on commands and their usage, follow [Commands and Usage](https://github.com/frappe/bench/blob/develop/docs/commands_and_usage.md). As for a consolidated list of bench commands, check out [Bench Usage](https://github.com/frappe/bench/blob/develop/docs/bench_usage.md).


## Custom Bench Commands

If you wish to extend the capabilities of bench with your own custom Frappe Application, you may follow [Adding Custom Bench Commands](https://github.com/frappe/bench/blob/master/docs/bench_custom_cmd.md).
If you wish to extend the capabilities of bench with your own custom Frappe Application, you may follow [Adding Custom Bench Commands](https://github.com/frappe/bench/blob/develop/docs/bench_custom_cmd.md).


## Bench Manager
Expand Down
2 changes: 1 addition & 1 deletion bench/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "5.0.0"
VERSION = "5.1.0"
PROJECT_NAME = "frappe-bench"
FRAPPE_VERSION = None

Expand Down
51 changes: 21 additions & 30 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
# imports - module imports
import bench
from bench.config.common_site_config import get_config
from bench.utils import CommandFailedError, build_assets, check_git_for_shallow_clone, exec_cmd, get_cmd_output, get_frappe, restart_supervisor_processes, restart_systemd_processes, run_frappe_cmd
from bench.utils import color, CommandFailedError, build_assets, check_git_for_shallow_clone, exec_cmd, get_cmd_output, get_frappe, restart_supervisor_processes, restart_systemd_processes, run_frappe_cmd


logging.basicConfig(level="INFO")
logger = logging.getLogger(__name__)
logger = logging.getLogger(bench.PROJECT_NAME)


class InvalidBranchException(Exception): pass
Expand Down Expand Up @@ -59,17 +58,10 @@ 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):
from six.moves.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 is_git_url(url):
# modified to allow without the tailing .git from https://github.com/jonschlinkert/is-git-url.git
pattern = r"(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)?(\/?|\#[-\d\w._]+?)$"
return bool(re.match(pattern, url))

def get_excluded_apps(bench_path='.'):
try:
Expand Down Expand Up @@ -98,9 +90,9 @@ def remove_from_excluded_apps_txt(app, bench_path='.'):
apps.remove(app)
return write_excluded_apps_txt(apps, bench_path=bench_path)

def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=False, postprocess=True, overwrite=False):
def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=False, restart_bench=True, overwrite=False):
if not os.path.exists(git_url):
if not check_url(git_url, raise_err=False):
if not is_git_url(git_url):
orgs = ['frappe', 'erpnext']
for org in orgs:
url = 'https://api.github.com/repos/{org}/{app}'.format(org=org, app=git_url)
Expand Down Expand Up @@ -135,7 +127,8 @@ def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=Fal
install_app(app=app_name, bench_path=bench_path, verbose=verbose, skip_assets=skip_assets)
sys.exit()

logger.info('Getting app {0}'.format(repo_name))
print('\n{0}Getting {1}{2}'.format(color.yellow, repo_name, color.nc))
logger.log('Getting app {0}'.format(repo_name))
exec_cmd("git clone {git_url} {branch} {shallow_clone} --origin upstream".format(
git_url=git_url,
shallow_clone=shallow_clone,
Expand All @@ -160,7 +153,7 @@ def get_app_name(bench_path, repo_name):
def new_app(app, bench_path='.'):
# For backwards compatibility
app = app.lower().replace(" ", "_").replace("-", "_")
logger.info('creating new app {}'.format(app))
logger.log('creating new app {}'.format(app))
apps = os.path.abspath(os.path.join(bench_path, 'apps'))
bench.set_frappe_version(bench_path=bench_path)

Expand All @@ -172,8 +165,9 @@ def new_app(app, bench_path='.'):
install_app(app, bench_path=bench_path)


def install_app(app, bench_path=".", verbose=False, no_cache=False, postprocess=True, skip_assets=False):
logger.info("installing {}".format(app))
def install_app(app, bench_path=".", verbose=False, no_cache=False, restart_bench=True, skip_assets=False):
print('\n{0}Installing {1}{2}'.format(color.yellow, app, color.nc))
logger.log("installing {}".format(app))

pip_path = os.path.join(bench_path, "env", "bin", "pip")
quiet_flag = "-q" if not verbose else ""
Expand All @@ -187,9 +181,10 @@ def install_app(app, bench_path=".", verbose=False, no_cache=False, postprocess=

add_to_appstxt(app, bench_path=bench_path)

if postprocess:
if not skip_assets:
build_assets(bench_path=bench_path, app=app)
if not skip_assets:
build_assets(bench_path=bench_path, app=app)

if restart_bench:
conf = get_config(bench_path=bench_path)

if conf.get('restart_supervisor_on_update'):
Expand Down Expand Up @@ -267,7 +262,7 @@ def pull_apps(apps=None, bench_path='.', reset=False):
add_to_excluded_apps_txt(app, bench_path=bench_path)
print("Skipping pull for app {}, since remote doesn't exist, and adding it to excluded apps".format(app))
continue
logger.info('pulling {0}'.format(app))
logger.log('pulling {0}'.format(app))
if reset:
exec_cmd("git fetch --all", cwd=app_dir)
exec_cmd("git reset --hard {remote}/{branch}".format(
Expand Down Expand Up @@ -359,10 +354,6 @@ def get_upstream_version(app, branch=None, bench_path='.'):
raise
return get_version_from_string(contents)

def get_upstream_url(app, bench_path='.'):
repo_dir = get_repo_dir(app, bench_path=bench_path)
return subprocess.check_output(['git', 'config', '--get', 'remote.upstream.url'], cwd=repo_dir).strip()

def get_repo_dir(app, bench_path='.'):
return os.path.join(bench_path, 'apps', app)

Expand Down Expand Up @@ -390,7 +381,7 @@ def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrad
bench.utils.log("Fetching upstream {0}for {1}".format("unshallow " if unshallow_flag else "", app))

bench.utils.exec_cmd("git remote set-branches upstream '*'", cwd=app_dir)
bench.utils.exec_cmd("git fetch --all{0}".format(" --unshallow" if unshallow_flag else ""), cwd=app_dir)
bench.utils.exec_cmd("git fetch --all{0} --quiet".format(" --unshallow" if unshallow_flag else ""), cwd=app_dir)

if check_upgrade:
version_upgrade = is_version_upgrade(app=app, bench_path=bench_path, branch=branch)
Expand All @@ -399,7 +390,7 @@ def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrad
sys.exit(1)

print("Switching for "+app)
bench.utils.exec_cmd("git checkout {0}".format(branch), cwd=app_dir)
bench.utils.exec_cmd("git checkout -f {0}".format(branch), cwd=app_dir)

if str(repo.active_branch) == branch:
switched_apps.append(app)
Expand Down
13 changes: 9 additions & 4 deletions bench/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
from bench.app import get_apps
from bench.commands import bench_command
from bench.config.common_site_config import get_config
from bench.utils import PatchError, bench_cache_file, check_latest_version, drop_privileges, find_parent_bench, generate_command_cache, get_cmd_output, get_env_cmd, get_frappe, is_bench_directory, is_dist_editable, is_root, log
from bench.utils import PatchError, bench_cache_file, check_latest_version, drop_privileges, find_parent_bench, generate_command_cache, get_cmd_output, get_env_cmd, get_frappe, is_bench_directory, is_dist_editable, is_root, log, setup_logging

logger = logging.getLogger(bench.PROJECT_NAME)
from_command_line = False
change_uid_msg = "You should not run this command as root"


def cli():
global from_command_line
from_command_line = True
command = " ".join(sys.argv)

change_working_directory()
logger = setup_logging() or logging.getLogger(bench.PROJECT_NAME)
logger.info(command)
check_uid()
change_dir()
change_uid()
Expand Down Expand Up @@ -56,8 +58,11 @@ def cli():

try:
bench_command()
except PatchError:
sys.exit(1)
except BaseException as e:
return_code = getattr(e, "code", 0)
if return_code:
logger.warning("{0} executed with exit code {1}".format(command, return_code))
sys.exit(return_code)


def check_uid():
Expand Down
3 changes: 0 additions & 3 deletions bench/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def print_bench_version(ctx, param, value):
@click.option('--version', is_flag=True, is_eager=True, callback=print_bench_version, expose_value=False)
def bench_command(bench_path='.'):
import bench
from bench.utils import setup_logging

bench.set_frappe_version(bench_path=bench_path)
setup_logging(bench_path=bench_path)


from bench.commands.make import init, get_app, new_app, remove_app, exclude_app_for_update, include_app_for_update, pip
Expand Down
1 change: 1 addition & 0 deletions bench/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def remove_common_config(keys):
config.add_command(config_restart_supervisor_on_update)
config.add_command(config_restart_systemd_on_update)
config.add_command(config_dns_multitenant)
config.add_command(config_rebase_on_pull)
config.add_command(config_serve_default_site)
config.add_command(config_http_timeout)
config.add_command(set_common_config)
Expand Down
17 changes: 10 additions & 7 deletions bench/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

# imports - third party imports
import click
from six import PY3

# imports - module imports
import bench.config.lets_encrypt
Expand Down Expand Up @@ -128,13 +127,17 @@ def setup_socketio():
@click.option("--node", help="Update only Node packages", default=False, is_flag=True)
@click.option("--python", help="Update only Python packages", default=False, is_flag=True)
def setup_requirements(node=False, python=False):
if not node:
from bench.utils import update_requirements as setup_python_packages
setup_python_packages()
if not (node or python):
from bench.utils import update_requirements
update_requirements()

if not python:
from bench.utils import update_node_packages as setup_node_packages
setup_node_packages()
elif not node:
from bench.utils import update_python_packages
update_python_packages()

elif not python:
from bench.utils import update_node_packages
update_node_packages()


@click.command("manager", help="Setup bench-manager.local site with the bench_manager app installed on it")
Expand Down
2 changes: 0 additions & 2 deletions bench/config/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ def prepare_sites(config, bench_path):

if not dns_multitenant:
message = "Port configuration list:"
port_config_index = 0
for site in sites_configs:
port_config_index += 1
message += "\n\nSite {0} assigned port: {1}".format(site["name"], site["port"])

print(message)
Expand Down
6 changes: 3 additions & 3 deletions bench/config/templates/Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ watch: bench watch
{% endif %}
{% if use_rq -%}
schedule: bench schedule
worker_short: bench worker --queue short --quiet
worker_long: bench worker --queue long --quiet
worker_default: bench worker --queue default --quiet
worker_short: bench worker --queue short 1>> logs/worker.log 2>> logs/worker.error.log
worker_long: bench worker --queue long 1>> logs/worker.log 2>> logs/worker.error.log
worker_default: bench worker --queue default 1>> logs/worker.log 2>> logs/worker.error.log
{% else %}
workerbeat: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app beat -s scheduler.schedule'
worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n jobs@%h -Ofair --soft-time-limit 360 --time-limit 390'
Expand Down
2 changes: 1 addition & 1 deletion bench/playbooks/roles/common/tasks/redhat_family.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
become: yes
become_user: root
yum:
name: https://centos7.iuscommunity.org/ius-release.rpm
name: https://repo.ius.io/ius-release-el7.rpm
state: present

- name: "Setup prerequisites using yum"
Expand Down
10 changes: 6 additions & 4 deletions bench/tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ def test_switch_to_branch(self):
bench_path = os.path.join(self.benches_path, "test-bench")
app_path = os.path.join(bench_path, "apps", "frappe")

bench.utils.exec_cmd("bench switch-to-branch version-12 frappe --upgrade", cwd=bench_path)
successful_switch = not bench.utils.exec_cmd("bench switch-to-branch version-12 frappe --upgrade", cwd=bench_path)
app_branch_after_switch = str(git.Repo(path=app_path).active_branch)
self.assertEqual("version-12", app_branch_after_switch)
if successful_switch:
self.assertEqual("version-12", app_branch_after_switch)

bench.utils.exec_cmd("bench switch-to-branch develop frappe --upgrade", cwd=bench_path)
successful_switch = not bench.utils.exec_cmd("bench switch-to-branch develop frappe --upgrade", cwd=bench_path)
app_branch_after_second_switch = str(git.Repo(path=app_path).active_branch)
self.assertEqual("develop", app_branch_after_second_switch)
if successful_switch:
self.assertEqual("develop", app_branch_after_second_switch)


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 70cb41f

Please sign in to comment.