diff --git a/frappe/__init__.py b/frappe/__init__.py index 5680ba86b5..2436692c81 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -10,11 +10,10 @@ be used to build database driven apps. Read the documentation: https://frappeframework.com/docs """ -from __future__ import unicode_literals, print_function -from six import iteritems, binary_type, text_type, string_types, PY2 +from six import iteritems, binary_type, text_type, string_types from werkzeug.local import Local, release_local -import os, sys, importlib, inspect, json +import os, sys, importlib, inspect, json, warnings import typing from past.builtins import cmp import click @@ -27,19 +26,14 @@ from .utils.lazy_loader import lazy_import # Lazy imports faker = lazy_import('faker') - -# Harmless for Python 3 -# For Python 2 set default encoding to utf-8 -if PY2: - reload(sys) - sys.setdefaultencoding("utf-8") - __version__ = '14.0.0-dev' __title__ = "Frappe Framework" local = Local() controllers = {} +warnings.simplefilter('always', DeprecationWarning) +warnings.simplefilter('always', PendingDeprecationWarning) class _dict(dict): """dict like object that exposes keys as attributes""" diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index ecdc5d21ba..b917126696 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -691,12 +691,18 @@ def make_app(destination, app_name): @click.argument('key') @click.argument('value') @click.option('-g', '--global', 'global_', is_flag=True, default=False, help='Set value in bench config') -@click.option('-p', '--parse', '--as-dict', is_flag=True, default=False, help='Evaluate as Python Object') +@click.option('-p', '--parse', is_flag=True, default=False, help='Evaluate as Python Object') +@click.option('--as-dict', is_flag=True, default=False, help='Legacy: Evaluate as Python Object') @pass_context -def set_config(context, key, value, global_=False, parse=False): +def set_config(context, key, value, global_=False, parse=False, as_dict=False): "Insert/Update a value in site_config.json" from frappe.installer import update_site_config + if as_dict: + from frappe.utils.commands import warn + warn("--as-dict will be deprecated in v14. Use --parse instead", category=PendingDeprecationWarning) + parse = as_dict + if parse: import ast value = ast.literal_eval(value) diff --git a/frappe/tests/test_commands.py b/frappe/tests/test_commands.py index cfd428fb77..9ed8ecb054 100644 --- a/frappe/tests/test_commands.py +++ b/frappe/tests/test_commands.py @@ -216,7 +216,7 @@ class TestCommands(BaseTestCommands): # test 7: take a backup with frappe.conf.backup.includes self.execute( - "bench --site {site} set-config backup '{includes}' --as-dict", + "bench --site {site} set-config backup '{includes}' --parse", {"includes": json.dumps(backup["includes"])}, ) self.execute("bench --site {site} backup --verbose") @@ -226,7 +226,7 @@ class TestCommands(BaseTestCommands): # test 8: take a backup with frappe.conf.backup.excludes self.execute( - "bench --site {site} set-config backup '{excludes}' --as-dict", + "bench --site {site} set-config backup '{excludes}' --parse", {"excludes": json.dumps(backup["excludes"])}, ) self.execute("bench --site {site} backup --verbose") @@ -383,7 +383,7 @@ class TestCommands(BaseTestCommands): # test 2: test keys in table text self.execute( - "bench --site {site} set-config test_key '{second_order}' --as-dict", + "bench --site {site} set-config test_key '{second_order}' --parse", {"second_order": json.dumps({"test_key": "test_value"})}, ) self.execute("bench --site {site} show-config") diff --git a/frappe/utils/commands.py b/frappe/utils/commands.py index 113014c135..3cf0d553b6 100644 --- a/frappe/utils/commands.py +++ b/frappe/utils/commands.py @@ -1,11 +1,10 @@ import functools -import requests -from terminaltables import AsciiTable - @functools.lru_cache(maxsize=1024) def get_first_party_apps(): """Get list of all apps under orgs: frappe. erpnext from GitHub""" + import requests + apps = [] for org in ["frappe", "erpnext"]: req = requests.get(f"https://api.github.com/users/{org}/repos", {"type": "sources", "per_page": 200}) @@ -15,6 +14,8 @@ def get_first_party_apps(): def render_table(data): + from terminaltables import AsciiTable + print(AsciiTable(data).table) @@ -49,3 +50,9 @@ def log(message, colour=''): colour = colours.get(colour, "") end_line = '\033[0m' print(colour + message + end_line) + + +def warn(message, category=None): + from warnings import warn + + warn(message=message, category=category, stacklevel=2)