mirror of
https://github.com/frappe/bench.git
synced 2025-01-11 01:32:07 +00:00
fix: Remove PY2 compatibility code
* Set Python requires Python 3.6+ but < Py4 * Remove six from dependencies * Use click.confirm instead of self implemented confirm code * Fix imports for 3.6+ compatibility References for updated imports: * https://docs.python.org/3/library/configparser.html * https://docs.python.org/3/library/urllib.request.html#legacy-interface * https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse * https://docs.python.org/3/library/importlib.html#importlib.reload
This commit is contained in:
parent
5d563f23ab
commit
54d48f61a3
@ -1,6 +1,3 @@
|
|||||||
# imports - compatibility imports
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
# imports - standard imports
|
# imports - standard imports
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@ -390,8 +387,9 @@ def get_repo_dir(app, bench_path='.'):
|
|||||||
|
|
||||||
def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrade=True):
|
def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrade=True):
|
||||||
import git
|
import git
|
||||||
from six.moves import reload_module
|
import importlib
|
||||||
from bench.utils import update_requirements, update_node_packages, backup_all_sites, patch_sites, build_assets, post_upgrade
|
from bench.utils import update_requirements, update_node_packages, backup_all_sites, patch_sites, build_assets, post_upgrade
|
||||||
|
|
||||||
apps_dir = os.path.join(bench_path, 'apps')
|
apps_dir = os.path.join(bench_path, 'apps')
|
||||||
version_upgrade = (False,)
|
version_upgrade = (False,)
|
||||||
switched_apps = []
|
switched_apps = []
|
||||||
@ -437,7 +435,7 @@ def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrad
|
|||||||
if version_upgrade[0] and upgrade:
|
if version_upgrade[0] and upgrade:
|
||||||
update_requirements()
|
update_requirements()
|
||||||
update_node_packages()
|
update_node_packages()
|
||||||
reload_module(bench.utils)
|
importlib.reload(bench.utils)
|
||||||
backup_all_sites()
|
backup_all_sites()
|
||||||
patch_sites()
|
patch_sites()
|
||||||
build_assets()
|
build_assets()
|
||||||
|
@ -39,12 +39,12 @@ def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups, c
|
|||||||
except SystemExit:
|
except SystemExit:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import os, shutil, time, six
|
import os, shutil, time
|
||||||
# add a sleep here so that the traceback of other processes doesnt overlap with the prompts
|
# add a sleep here so that the traceback of other processes doesnt overlap with the prompts
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print(e)
|
print(e)
|
||||||
log(f"There was a problem while creating {path}", level=2)
|
log(f"There was a problem while creating {path}", level=2)
|
||||||
if six.moves.input("Do you want to rollback these changes? [Y/n]: ").lower() == "y":
|
if click.confirm("Do you want to rollback these changes?"):
|
||||||
print(f'Rolling back Bench "{path}"')
|
print(f'Rolling back Bench "{path}"')
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
@ -154,7 +154,6 @@ def setup_requirements(node=False, python=False):
|
|||||||
@click.option("--port", help="Port on which you want to run bench manager", default=23624)
|
@click.option("--port", help="Port on which you want to run bench manager", default=23624)
|
||||||
@click.option("--domain", help="Domain on which you want to run bench manager")
|
@click.option("--domain", help="Domain on which you want to run bench manager")
|
||||||
def setup_manager(yes=False, port=23624, domain=None):
|
def setup_manager(yes=False, port=23624, domain=None):
|
||||||
from six.moves import input
|
|
||||||
from bench.utils import get_sites
|
from bench.utils import get_sites
|
||||||
from bench.config.common_site_config import get_config
|
from bench.config.common_site_config import get_config
|
||||||
from bench.config.nginx import make_bench_manager_nginx_conf
|
from bench.config.nginx import make_bench_manager_nginx_conf
|
||||||
@ -162,11 +161,7 @@ def setup_manager(yes=False, port=23624, domain=None):
|
|||||||
create_new_site = True
|
create_new_site = True
|
||||||
|
|
||||||
if "bench-manager.local" in os.listdir("sites"):
|
if "bench-manager.local" in os.listdir("sites"):
|
||||||
ans = input("Site already exists. Overwrite existing site? [Y/n]: ").lower()
|
create_new_site = click.confirm("Site already exists. Overwrite existing site?")
|
||||||
while ans not in ("y", "n", ""):
|
|
||||||
ans = input("Please enter 'y' or 'n'. Site already exists. Overwrite existing site? [Y/n]: ").lower()
|
|
||||||
if ans == "n":
|
|
||||||
create_new_site = False
|
|
||||||
|
|
||||||
if create_new_site:
|
if create_new_site:
|
||||||
exec_cmd("bench new-site --force bench-manager.local")
|
exec_cmd("bench new-site --force bench-manager.local")
|
||||||
|
@ -71,7 +71,7 @@ def update_config_for_frappe(config, bench_path):
|
|||||||
# TODO Optionally we need to add the host or domain name in case dns_multitenant is false
|
# TODO Optionally we need to add the host or domain name in case dns_multitenant is false
|
||||||
|
|
||||||
def make_ports(bench_path):
|
def make_ports(bench_path):
|
||||||
from six.moves.urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
benches_path = os.path.dirname(os.path.abspath(bench_path))
|
benches_path = os.path.dirname(os.path.abspath(bench_path))
|
||||||
|
|
||||||
|
@ -106,13 +106,13 @@ def create_dir_if_missing(path):
|
|||||||
|
|
||||||
|
|
||||||
def get_certbot():
|
def get_certbot():
|
||||||
from six.moves.urllib.request import urlretrieve
|
from urllib.request import urlretrieve
|
||||||
|
|
||||||
certbot_path = get_certbot_path()
|
certbot_path = get_certbot_path()
|
||||||
create_dir_if_missing(certbot_path)
|
create_dir_if_missing(certbot_path)
|
||||||
|
|
||||||
if not os.path.isfile(certbot_path):
|
if not os.path.isfile(certbot_path):
|
||||||
urlretrieve ("https://dl.eff.org/certbot-auto", certbot_path)
|
urlretrieve("https://dl.eff.org/certbot-auto", certbot_path)
|
||||||
os.chmod(certbot_path, 0o744)
|
os.chmod(certbot_path, 0o744)
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import string
|
|||||||
|
|
||||||
# imports - third party imports
|
# imports - third party imports
|
||||||
import click
|
import click
|
||||||
from six import string_types
|
|
||||||
|
|
||||||
# imports - module imports
|
# imports - module imports
|
||||||
import bench
|
import bench
|
||||||
@ -218,7 +217,7 @@ def get_sites_with_config(bench_path):
|
|||||||
if dns_multitenant and site_config.get('domains'):
|
if dns_multitenant and site_config.get('domains'):
|
||||||
for domain in site_config.get('domains'):
|
for domain in site_config.get('domains'):
|
||||||
# domain can be a string or a dict with 'domain', 'ssl_certificate', 'ssl_certificate_key'
|
# domain can be a string or a dict with 'domain', 'ssl_certificate', 'ssl_certificate_key'
|
||||||
if isinstance(domain, string_types):
|
if isinstance(domain, str):
|
||||||
domain = { 'domain': domain }
|
domain = { 'domain': domain }
|
||||||
|
|
||||||
domain['name'] = site
|
domain['name'] = site
|
||||||
|
@ -9,7 +9,7 @@ from bench.config.common_site_config import get_config
|
|||||||
|
|
||||||
|
|
||||||
def generate_config(bench_path):
|
def generate_config(bench_path):
|
||||||
from six.moves.urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
config = get_config(bench_path)
|
config = get_config(bench_path)
|
||||||
|
|
||||||
|
@ -67,8 +67,7 @@ def get_supervisord_conf():
|
|||||||
|
|
||||||
def update_supervisord_config(user=None, yes=False):
|
def update_supervisord_config(user=None, yes=False):
|
||||||
"""From bench v5.x, we're moving to supervisor running as user"""
|
"""From bench v5.x, we're moving to supervisor running as user"""
|
||||||
from six.moves import configparser
|
import configparser
|
||||||
|
|
||||||
from bench.config.production_setup import service
|
from bench.config.production_setup import service
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
|
@ -8,14 +8,11 @@ import sys
|
|||||||
import traceback
|
import traceback
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
# imports - third party imports
|
|
||||||
from six import PY2
|
|
||||||
|
|
||||||
# imports - module imports
|
# imports - module imports
|
||||||
import bench
|
import bench
|
||||||
import bench.utils
|
import bench.utils
|
||||||
|
|
||||||
if PY2:
|
if sys.version_info.major == 2:
|
||||||
FRAPPE_BRANCH = "version-12"
|
FRAPPE_BRANCH = "version-12"
|
||||||
else:
|
else:
|
||||||
FRAPPE_BRANCH = "develop"
|
FRAPPE_BRANCH = "develop"
|
||||||
|
@ -641,11 +641,9 @@ def update_npm_packages(bench_path='.'):
|
|||||||
|
|
||||||
if os.path.exists(package_json_path):
|
if os.path.exists(package_json_path):
|
||||||
with open(package_json_path, "r") as f:
|
with open(package_json_path, "r") as f:
|
||||||
from six import iteritems
|
|
||||||
|
|
||||||
app_package_json = json.loads(f.read())
|
app_package_json = json.loads(f.read())
|
||||||
# package.json is usually a dict in a dict
|
# package.json is usually a dict in a dict
|
||||||
for key, value in iteritems(app_package_json):
|
for key, value in app_package_json.items():
|
||||||
if not key in package_json:
|
if not key in package_json:
|
||||||
package_json[key] = value
|
package_json[key] = value
|
||||||
else:
|
else:
|
||||||
@ -978,7 +976,7 @@ def find_benches(directory=None):
|
|||||||
|
|
||||||
def migrate_env(python, backup=False):
|
def migrate_env(python, backup=False):
|
||||||
import shutil
|
import shutil
|
||||||
from six.moves.urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from bench.config.common_site_config import get_config
|
from bench.config.common_site_config import get_config
|
||||||
from bench.app import get_apps
|
from bench.app import get_apps
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from __future__ import print_function
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -234,7 +233,7 @@ def install_bench(args):
|
|||||||
# create user if not exists
|
# create user if not exists
|
||||||
extra_vars = vars(args)
|
extra_vars = vars(args)
|
||||||
extra_vars.update(frappe_user=args.user)
|
extra_vars.update(frappe_user=args.user)
|
||||||
|
|
||||||
extra_vars.update(user_directory=get_user_home_directory(args.user))
|
extra_vars.update(user_directory=get_user_home_directory(args.user))
|
||||||
|
|
||||||
if os.path.exists(tmp_bench_repo):
|
if os.path.exists(tmp_bench_repo):
|
||||||
|
@ -6,5 +6,4 @@ python-crontab==2.4.0
|
|||||||
requests==2.22.0
|
requests==2.22.0
|
||||||
semantic-version==2.8.2
|
semantic-version==2.8.2
|
||||||
setuptools
|
setuptools
|
||||||
six
|
|
||||||
virtualenv
|
virtualenv
|
||||||
|
1
setup.py
1
setup.py
@ -11,6 +11,7 @@ setup(
|
|||||||
author_email='info@frappe.io',
|
author_email='info@frappe.io',
|
||||||
version=VERSION,
|
version=VERSION,
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
|
python_requires='~=3.6',
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
install_requires=install_requires,
|
install_requires=install_requires,
|
||||||
|
Loading…
Reference in New Issue
Block a user