2
0
mirror of https://github.com/frappe/bench.git synced 2024-09-28 06:49:06 +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:
Gavin D'souza 2021-05-11 11:55:46 +05:30
parent 5d563f23ab
commit 54d48f61a3
13 changed files with 17 additions and 32 deletions

View File

@ -1,6 +1,3 @@
# imports - compatibility imports
from __future__ import print_function
# imports - standard imports
import json
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):
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
apps_dir = os.path.join(bench_path, 'apps')
version_upgrade = (False,)
switched_apps = []
@ -437,7 +435,7 @@ def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrad
if version_upgrade[0] and upgrade:
update_requirements()
update_node_packages()
reload_module(bench.utils)
importlib.reload(bench.utils)
backup_all_sites()
patch_sites()
build_assets()

View File

@ -39,12 +39,12 @@ def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups, c
except SystemExit:
pass
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
time.sleep(1)
print(e)
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}"')
if os.path.exists(path):
shutil.rmtree(path)

View File

@ -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("--domain", help="Domain on which you want to run bench manager")
def setup_manager(yes=False, port=23624, domain=None):
from six.moves import input
from bench.utils import get_sites
from bench.config.common_site_config import get_config
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
if "bench-manager.local" in os.listdir("sites"):
ans = input("Site already exists. Overwrite existing site? [Y/n]: ").lower()
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
create_new_site = click.confirm("Site already exists. Overwrite existing site?")
if create_new_site:
exec_cmd("bench new-site --force bench-manager.local")

View File

@ -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
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))

View File

@ -106,13 +106,13 @@ def create_dir_if_missing(path):
def get_certbot():
from six.moves.urllib.request import urlretrieve
from urllib.request import urlretrieve
certbot_path = get_certbot_path()
create_dir_if_missing(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)

View File

@ -6,7 +6,6 @@ import string
# imports - third party imports
import click
from six import string_types
# imports - module imports
import bench
@ -218,7 +217,7 @@ def get_sites_with_config(bench_path):
if dns_multitenant and 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'
if isinstance(domain, string_types):
if isinstance(domain, str):
domain = { 'domain': domain }
domain['name'] = site

View File

@ -9,7 +9,7 @@ from bench.config.common_site_config import get_config
def generate_config(bench_path):
from six.moves.urllib.parse import urlparse
from urllib.parse import urlparse
config = get_config(bench_path)

View File

@ -67,8 +67,7 @@ def get_supervisord_conf():
def update_supervisord_config(user=None, yes=False):
"""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
if not user:

View File

@ -8,14 +8,11 @@ import sys
import traceback
import unittest
# imports - third party imports
from six import PY2
# imports - module imports
import bench
import bench.utils
if PY2:
if sys.version_info.major == 2:
FRAPPE_BRANCH = "version-12"
else:
FRAPPE_BRANCH = "develop"

View File

@ -641,11 +641,9 @@ def update_npm_packages(bench_path='.'):
if os.path.exists(package_json_path):
with open(package_json_path, "r") as f:
from six import iteritems
app_package_json = json.loads(f.read())
# 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:
package_json[key] = value
else:
@ -978,7 +976,7 @@ def find_benches(directory=None):
def migrate_env(python, backup=False):
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.app import get_apps

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
from __future__ import print_function
import os
import sys
import subprocess

View File

@ -6,5 +6,4 @@ python-crontab==2.4.0
requests==2.22.0
semantic-version==2.8.2
setuptools
six
virtualenv

View File

@ -11,6 +11,7 @@ setup(
author_email='info@frappe.io',
version=VERSION,
packages=find_packages(),
python_requires='~=3.6',
zip_safe=False,
include_package_data=True,
install_requires=install_requires,