From e24ca16c9021e74138c1894987e78791c71b2bd5 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Fri, 21 Jun 2019 08:40:13 +0530 Subject: [PATCH] fix: Initialize bench with Python 3 --- bench/commands/make.py | 4 +- bench/commands/setup.py | 4 +- bench/utils.py | 4 +- playbooks/install.py | 46 ++++--------------- playbooks/roles/bench/tasks/main.yml | 4 +- .../roles/common/tasks/debian_family.yml | 7 ++- playbooks/roles/common/tasks/main.yml | 2 +- playbooks/roles/mariadb/tasks/debian.yml | 1 - .../tasks/mysql_secure_installation.yml | 2 +- .../roles/mariadb/tasks/ubuntu-trusty.yml | 2 +- .../mariadb/tasks/ubuntu-xenial_bionic.yml | 2 +- 11 files changed, 24 insertions(+), 54 deletions(-) diff --git a/bench/commands/make.py b/bench/commands/make.py index 744f961c..e30f23d5 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 = 'python', help = 'Path to Python Executable.') +@click.option('--python', type = str, default = 'python3', 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") @@ -17,7 +17,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, clone_without_update, ignore_exist = False, - python = 'python'): # Let's change we're ready. - + python = 'python3'): ''' Create a New Bench Instance. ''' diff --git a/bench/commands/setup.py b/bench/commands/setup.py index d789aa3a..bb59a857 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -81,8 +81,8 @@ def setup_backups(): setup_backups() @click.command('env') -@click.option('--python', type = str, default = 'python', help = 'Path to Python Executable.') -def setup_env(python='python'): +@click.option('--python', type = str, default = 'python3', help = 'Path to Python Executable.') +def setup_env(python='python3'): "Setup virtualenv for bench" from bench.utils import setup_env setup_env(python=python) diff --git a/bench/utils.py b/bench/utils.py index c531eb8f..cee84833 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -38,7 +38,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, verbose=False, clone_from=None, skip_redis_config_generation=False, clone_without_update=False, ignore_exist = False, - python = 'python'): # Let's change when we're ready. - + python = 'python3'): # 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 @@ -169,7 +169,7 @@ def which(executable, raise_err = False): return exec_ -def setup_env(bench_path='.', python = 'python'): +def setup_env(bench_path='.', python = 'python3'): python = which(python, raise_err = True) pip = os.path.join('env', 'bin', 'pip') diff --git a/playbooks/install.py b/playbooks/install.py index db50160c..355e03a0 100644 --- a/playbooks/install.py +++ b/playbooks/install.py @@ -1,4 +1,4 @@ -# wget setup_frappe.py | python +# wget setup_frappe.py | python3 import os, sys, subprocess, getpass, json, multiprocessing, shutil, platform from distutils.spawn import find_executable @@ -14,7 +14,7 @@ def install_bench(args): success = run_os_command({ 'apt-get': [ 'sudo apt-get update', - 'sudo apt-get install -y git build-essential python-setuptools python-dev libffi-dev libssl-dev' + 'sudo apt-get install -y git build-essential python3-setuptools python3-dev libffi-dev libssl-dev' ], 'yum': [ 'sudo yum groupinstall -y "Development tools"', @@ -46,7 +46,7 @@ def install_bench(args): }) success = run_os_command({ - 'python': 'sudo python get-pip.py --force-reinstall' + 'python3': 'sudo python3 get-pip.py --force-reinstall' }) if success: @@ -85,12 +85,11 @@ def install_bench(args): raise Exception('Please run this script as a non-root user with sudo privileges, but without using sudo or pass --user=USER') # Python executable - if not args.production: - dist_name, dist_version = get_distribution_info() - if dist_name=='centos': - args.python = 'python3.6' - else: - args.python = 'python3' + dist_name, dist_version = get_distribution_info() + if dist_name=='centos': + args.python = 'python3.6' + else: + args.python = 'python3' # create user if not exists extra_vars = vars(args) @@ -157,27 +156,6 @@ def get_distribution_info(): current_dist = platform.mac_ver() return "macos", current_dist[0].rsplit('.', 1)[0] -def install_python27(): - version = (sys.version_info[0], sys.version_info[1]) - - if version == (2, 7): - return - - print('Installing Python 2.7') - - # install python 2.7 - success = run_os_command({ - 'apt-get': 'sudo apt-get install -y python-dev', - 'yum': 'sudo yum install -y python27', - 'brew': 'brew install python' - }) - - if not success: - could_not_install('Python 2.7') - - # replace current python with python2.7 - os.execvp('python2.7', ([] if is_sudo_user() else ['sudo']) + ['python2.7', __file__] + sys.argv[1:]) - def install_package(package): package_exec = find_executable(package) @@ -407,7 +385,7 @@ def parse_commandline_args(): parser.add_argument('--bench-name', dest='bench_name', help='Create bench with specified name. Default name is frappe-bench') # Python interpreter to be used - parser.add_argument('--python', dest='python', default='python', + parser.add_argument('--python', dest='python', default='python3', help=argparse.SUPPRESS ) @@ -421,12 +399,6 @@ def parse_commandline_args(): return args if __name__ == '__main__': - try: - import argparse - except ImportError: - # install python2.7 - install_python27() - args = parse_commandline_args() install_bench(args) diff --git a/playbooks/roles/bench/tasks/main.yml b/playbooks/roles/bench/tasks/main.yml index 0a9afa6e..1294d054 100644 --- a/playbooks/roles/bench/tasks/main.yml +++ b/playbooks/roles/bench/tasks/main.yml @@ -34,8 +34,8 @@ creates: "{{ bench_path }}" when: not bench_stat.stat.exists and not production - - name: python2 bench init for production - command: bench init {{ bench_path }} --frappe-path {{ frappe_repo_url }} --frappe-branch {{ frappe_branch }} + - name: python3 bench init for production + command: bench init {{ bench_path }} --frappe-path {{ frappe_repo_url }} --frappe-branch {{ frappe_branch }} --python {{ python }} args: creates: "{{ bench_path }}" when: not bench_stat.stat.exists and production diff --git a/playbooks/roles/common/tasks/debian_family.yml b/playbooks/roles/common/tasks/debian_family.yml index c7639264..893b0632 100644 --- a/playbooks/roles/common/tasks/debian_family.yml +++ b/playbooks/roles/common/tasks/debian_family.yml @@ -21,10 +21,9 @@ - libffi-dev - ntp # Clock synchronization - postfix # Mail Server - - python-dev # Installing python developer suite - - python3-dev # For python3 compatibility + - python3-dev # Installing python developer suite - python-tk - - screen # To aid ssh sessions with connectivity problems + - screen # To aid ssh sessions with connectivity problems - vim # Is that supposed to be a question!? - xfonts-75dpi - xfonts-base @@ -34,7 +33,7 @@ - libldap2-dev - libcups2-dev - pv # Show progress during database restore - + - include_tasks: debian.yml when: ansible_distribution == 'Debian' diff --git a/playbooks/roles/common/tasks/main.yml b/playbooks/roles/common/tasks/main.yml index e5f6ac0d..b6b2be29 100644 --- a/playbooks/roles/common/tasks/main.yml +++ b/playbooks/roles/common/tasks/main.yml @@ -1,5 +1,5 @@ --- -# Install's prerequisites, like fonts, image libraries, vim, screen, python-dev +# Install's prerequisites, like fonts, image libraries, vim, screen, python3-dev - include_tasks: debian_family.yml when: ansible_os_family == 'Debian' diff --git a/playbooks/roles/mariadb/tasks/debian.yml b/playbooks/roles/mariadb/tasks/debian.yml index 906576d9..8e9596c5 100644 --- a/playbooks/roles/mariadb/tasks/debian.yml +++ b/playbooks/roles/mariadb/tasks/debian.yml @@ -27,6 +27,5 @@ - mariadb-client - mariadb-common - libmariadbclient18 - - python-mysqldb - python3-mysqldb ... \ No newline at end of file diff --git a/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml b/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml index 27d1ca80..4265375e 100644 --- a/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml +++ b/playbooks/roles/mariadb/tasks/mysql_secure_installation.yml @@ -12,7 +12,7 @@ # FLUSH PRIVILEGES; - name: Set root Password - mysql_user: login_password={{ mysql_root_password }} check_implicit_admin=yes name=root host={{ item }} password={{ mysql_root_password }} state=present + mysql_user: login_password={{ mysql_root_password }} check_implicit_admin=yes name=root host={{ item }} password={{ mysql_root_password }} state=present with_items: - localhost - 127.0.0.1 diff --git a/playbooks/roles/mariadb/tasks/ubuntu-trusty.yml b/playbooks/roles/mariadb/tasks/ubuntu-trusty.yml index 56cd0b66..6493b985 100644 --- a/playbooks/roles/mariadb/tasks/ubuntu-trusty.yml +++ b/playbooks/roles/mariadb/tasks/ubuntu-trusty.yml @@ -23,5 +23,5 @@ - libmariadbclient18 - name: Install MySQLdb Python package for secure installations. - apt: pkg=python-mysqldb state=present + apt: pkg=python3-mysqldb state=present when: mysql_secure_installation and mysql_root_password is defined diff --git a/playbooks/roles/mariadb/tasks/ubuntu-xenial_bionic.yml b/playbooks/roles/mariadb/tasks/ubuntu-xenial_bionic.yml index 8e834ee8..2163cc00 100644 --- a/playbooks/roles/mariadb/tasks/ubuntu-xenial_bionic.yml +++ b/playbooks/roles/mariadb/tasks/ubuntu-xenial_bionic.yml @@ -23,5 +23,5 @@ - libmariadbclient18 - name: Install MySQLdb Python package for secure installations. - apt: pkg=python-mysqldb state=present + apt: pkg=python3-mysqldb state=present when: mysql_secure_installation and mysql_root_password is defined