From 3005e66e45dbadca854e6c080d7bcb67f9542152 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 10 Jun 2023 18:29:00 +0530 Subject: [PATCH] refactor!: Drop previously deprecated code --- frappe/__init__.py | 19 +----- frappe/build.py | 2 - frappe/commands/utils.py | 67 +------------------ frappe/database/database.py | 17 ----- frappe/model/document.py | 3 +- frappe/model/rename_doc.py | 36 ---------- frappe/permissions.py | 2 - frappe/public/js/frappe/desk.js | 52 -------------- frappe/public/js/frappe/form/form.js | 16 ----- frappe/public/js/frappe/ui/messages.js | 10 --- frappe/public/js/frappe/utils/datetime.js | 31 --------- frappe/public/js/frappe/utils/utils.js | 4 -- .../js/frappe/views/reports/query_report.js | 9 --- frappe/test_runner.py | 24 ++----- frappe/tests/test_rename_doc.py | 12 ---- frappe/utils/data.py | 1 - frappe/utils/safe_exec.py | 3 +- frappe/website/utils.py | 5 -- 18 files changed, 8 insertions(+), 305 deletions(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index 5e87785e2d..0f85c8a11b 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -925,7 +925,6 @@ def has_permission( ptype="read", doc=None, user=None, - verbose=False, throw=False, *, parent_doctype=None, @@ -938,7 +937,6 @@ def has_permission( :param ptype: Permission type (`read`, `write`, `create`, `submit`, `cancel`, `amend`). Default: `read`. :param doc: [optional] Checks User permissions for given doc. :param user: [optional] Check for given user. Default: current user. - :param verbose: DEPRECATED, will be removed in a future release. :param parent_doctype: Required when checking permission for a child DocType (unless doc is specified). """ import frappe.permissions @@ -1428,7 +1426,7 @@ def get_all_apps(with_internal_apps=True, sites_path=None): @request_cache -def get_installed_apps(sort=False, frappe_last=False, *, _ensure_on_bench=False): +def get_installed_apps(*, _ensure_on_bench=False): """ Get list of installed apps in current site. @@ -1436,8 +1434,6 @@ def get_installed_apps(sort=False, frappe_last=False, *, _ensure_on_bench=False) :param frappe_last: [DEPRECATED] Keep frappe last. Do not use this, reverse the app list instead. :param ensure_on_bench: Only return apps that are present on bench. """ - from frappe.utils.deprecations import deprecation_warning - if getattr(flags, "in_install_db", True): return [] @@ -1446,23 +1442,10 @@ def get_installed_apps(sort=False, frappe_last=False, *, _ensure_on_bench=False) installed = json.loads(db.get_global("installed_apps") or "[]") - if sort: - if not local.all_apps: - local.all_apps = cache.get_value("all_apps", get_all_apps) - - deprecation_warning("`sort` argument is deprecated and will be removed in v15.") - installed = [app for app in local.all_apps if app in installed] - if _ensure_on_bench: all_apps = cache.get_value("all_apps", get_all_apps) installed = [app for app in installed if app in all_apps] - if frappe_last: - deprecation_warning("`frappe_last` argument is deprecated and will be removed in v15.") - if "frappe" in installed: - installed.remove("frappe") - installed.append("frappe") - return installed diff --git a/frappe/build.py b/frappe/build.py index b74afa5d06..46301dadaf 100644 --- a/frappe/build.py +++ b/frappe/build.py @@ -227,8 +227,6 @@ def bundle( mode, apps=None, hard_link=False, - make_copy=False, - restore=False, verbose=False, skip_frappe=False, files=None, diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index e44009a886..869fd93a80 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -13,10 +13,6 @@ from frappe.exceptions import SiteNotSpecifiedError from frappe.utils import cint, update_progress_bar find_executable = which # backwards compatibility -DATA_IMPORT_DEPRECATION = ( - "[DEPRECATED] The `import-csv` command used 'Data Import Legacy' which has been deprecated.\n" - "Use `data-import` command instead to import data via 'Data Import'." -) EXTRA_ARGS_CTX = {"ignore_unknown_options": True, "allow_extra_args": True} @@ -30,18 +26,6 @@ EXTRA_ARGS_CTX = {"ignore_unknown_options": True, "allow_extra_args": True} help="Copy the files instead of symlinking", envvar="FRAPPE_HARD_LINK_ASSETS", ) -@click.option( - "--make-copy", - is_flag=True, - default=False, - help="[DEPRECATED] Copy the files instead of symlinking", -) -@click.option( - "--restore", - is_flag=True, - default=False, - help="[DEPRECATED] Copy the files instead of symlinking with force", -) @click.option("--production", is_flag=True, default=False, help="Build assets in production mode") @click.option("--verbose", is_flag=True, default=False, help="Verbose") @click.option( @@ -51,8 +35,6 @@ def build( app=None, apps=None, hard_link=False, - make_copy=False, - restore=False, production=False, verbose=False, force=False, @@ -80,13 +62,6 @@ def build( if production: mode = "production" - if make_copy or restore: - hard_link = make_copy or restore - click.secho( - "bench build: --make-copy and --restore options are deprecated in favour of --hard-link", - fg="yellow", - ) - bundle(mode, apps=apps, hard_link=hard_link, verbose=verbose, skip_frappe=skip_frappe) @@ -409,34 +384,6 @@ def import_doc(context, path, force=False): raise SiteNotSpecifiedError -@click.command("import-csv", help=DATA_IMPORT_DEPRECATION) -@click.argument("path") -@click.option( - "--only-insert", default=False, is_flag=True, help="Do not overwrite existing records" -) -@click.option( - "--submit-after-import", default=False, is_flag=True, help="Submit document after importing it" -) -@click.option( - "--ignore-encoding-errors", - default=False, - is_flag=True, - help="Ignore encoding errors while coverting to unicode", -) -@click.option("--no-email", default=True, is_flag=True, help="Send email if applicable") -@pass_context -def import_csv( - context, - path, - only_insert=False, - submit_after_import=False, - ignore_encoding_errors=False, - no_email=True, -): - click.secho(DATA_IMPORT_DEPRECATION, fg="yellow") - sys.exit(1) - - @click.command("data-import") @click.option( "--file", "file_path", type=click.Path(), required=True, help="Path to import file (.csv, .xlsx)" @@ -788,7 +735,6 @@ def run_tests( profile=False, coverage=False, junit_xml_output=False, - ui_tests=False, doctype_list_path=None, skip_test_records=False, skip_before_tests=False, @@ -827,7 +773,6 @@ def run_tests( force=context.force, profile=profile, junit_xml_output=junit_xml_output, - ui_tests=ui_tests, doctype_list_path=doctype_list_path, failfast=failfast, case=case, @@ -1063,20 +1008,11 @@ def create_patch(): "-g", "--global", "global_", is_flag=True, default=False, help="Set value in bench config" ) @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, as_dict=False): +def set_config(context, key, value, global_=False, parse=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 @@ -1200,7 +1136,6 @@ commands = [ export_fixtures, export_json, get_version, - import_csv, data_import, import_doc, make_app, diff --git a/frappe/database/database.py b/frappe/database/database.py index e4c735c595..6616592fd7 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -33,7 +33,6 @@ from frappe.query_builder.functions import Count from frappe.utils import CallbackManager from frappe.utils import cast as cast_fieldtype from frappe.utils import cint, get_datetime, get_table_name, getdate, now, sbool -from frappe.utils.deprecations import deprecated, deprecation_warning IFNULL_PATTERN = re.compile(r"ifnull\(", flags=re.IGNORECASE) INDEX_PATTERN = re.compile(r"\s*\([^)]+\)\s*") @@ -874,7 +873,6 @@ class Database: modified_by=None, update_modified=True, debug=False, - for_update=True, ): """Set a single value in the database, do not call the ORM triggers but update the modified timestamp (unless specified not to). @@ -891,21 +889,6 @@ class Database: :param debug: Print the query in the developer / js console. """ - if _is_single_doctype := not (dn and dt != dn): - deprecation_warning( - "Calling db.set_value on single doctype is deprecated. This behaviour will be removed in version 15. Use db.set_single_value instead." - ) - self.set_single_value( - doctype=dt, - fieldname=field, - value=val, - debug=debug, - update_modified=update_modified, - modified=modified, - modified_by=modified_by, - ) - return - to_update = self._get_update_dict( field, val, modified=modified, modified_by=modified_by, update_modified=update_modified ) diff --git a/frappe/model/document.py b/frappe/model/document.py index 6ef81314f1..9496c09077 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -204,12 +204,11 @@ class Document(BaseDocument): if not self.has_permission(permtype): self.raise_no_permission_to(permlevel or permtype) - def has_permission(self, permtype="read", verbose=False) -> bool: + def has_permission(self, permtype="read") -> bool: """ Call `frappe.permissions.has_permission` if `ignore_permissions` flag isn't truthy :param permtype: `read`, `write`, `submit`, `cancel`, `delete`, etc. - :param verbose: DEPRECATED, will be removed in a future release. """ if self.flags.ignore_permissions: diff --git a/frappe/model/rename_doc.py b/frappe/model/rename_doc.py index 3908365291..e3ca6de739 100644 --- a/frappe/model/rename_doc.py +++ b/frappe/model/rename_doc.py @@ -685,39 +685,3 @@ def bulk_rename( if not via_console: return rename_log - - -def update_linked_doctypes( - doctype: str, docname: str, linked_to: str, value: str, ignore_doctypes: list | None = None -) -> None: - from frappe.model.utils.rename_doc import update_linked_doctypes - - show_deprecation_warning("update_linked_doctypes") - - return update_linked_doctypes( - doctype=doctype, - docname=docname, - linked_to=linked_to, - value=value, - ignore_doctypes=ignore_doctypes, - ) - - -def get_fetch_fields( - doctype: str, linked_to: str, ignore_doctypes: list | None = None -) -> list[dict]: - from frappe.model.utils.rename_doc import get_fetch_fields - - show_deprecation_warning("get_fetch_fields") - - return get_fetch_fields(doctype=doctype, linked_to=linked_to, ignore_doctypes=ignore_doctypes) - - -def show_deprecation_warning(funct: str) -> None: - from click import secho - - message = ( - f"Function frappe.model.rename_doc.{funct} has been deprecated and " - "moved to the frappe.model.utils.rename_doc" - ) - secho(message, fg="yellow") diff --git a/frappe/permissions.py b/frappe/permissions.py index b3380dacc0..4cd0d369e2 100644 --- a/frappe/permissions.py +++ b/frappe/permissions.py @@ -48,7 +48,6 @@ def has_permission( doctype, ptype="read", doc=None, - verbose=False, user=None, raise_exception=True, *, @@ -60,7 +59,6 @@ def has_permission( :param doctype: DocType to check permission for :param ptype: Permission Type to check :param doc: Check User Permissions for specified document. - :param verbose: DEPRECATED, will be removed in a future release. :param user: User to check permission for. Defaults to current user. :param raise_exception: DOES NOT raise an exception. diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index fba4678cbb..a797c6302f 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -330,58 +330,6 @@ frappe.Application = class Application { .replace("mm", "%m") .replace("yyyy", "%Y"); frappe.boot.user.last_selected_values = {}; - - // Proxy for user globals - Object.defineProperties(window, { - user: { - get: function () { - console.warn( - "Please use `frappe.session.user` instead of `user`. It will be deprecated soon." - ); - return frappe.session.user; - }, - }, - user_fullname: { - get: function () { - console.warn( - "Please use `frappe.session.user_fullname` instead of `user_fullname`. It will be deprecated soon." - ); - return frappe.session.user; - }, - }, - user_email: { - get: function () { - console.warn( - "Please use `frappe.session.user_email` instead of `user_email`. It will be deprecated soon." - ); - return frappe.session.user_email; - }, - }, - user_defaults: { - get: function () { - console.warn( - "Please use `frappe.user_defaults` instead of `user_defaults`. It will be deprecated soon." - ); - return frappe.user_defaults; - }, - }, - roles: { - get: function () { - console.warn( - "Please use `frappe.user_roles` instead of `roles`. It will be deprecated soon." - ); - return frappe.user_roles; - }, - }, - sys_defaults: { - get: function () { - console.warn( - "Please use `frappe.sys_defaults` instead of `sys_defaults`. It will be deprecated soon." - ); - return frappe.user_roles; - }, - }, - }); } sync_pages() { // clear cached pages if timestamp is not found diff --git a/frappe/public/js/frappe/form/form.js b/frappe/public/js/frappe/form/form.js index 3d0b1bbc6f..0a60b00af2 100644 --- a/frappe/public/js/frappe/form/form.js +++ b/frappe/public/js/frappe/form/form.js @@ -2114,19 +2114,3 @@ frappe.ui.form.Form = class FrappeForm { }; frappe.validated = 0; -// Proxy for frappe.validated -Object.defineProperty(window, "validated", { - get: function () { - console.warn( - "Please use `frappe.validated` instead of `validated`. It will be deprecated soon." - ); // eslint-disable-line - return frappe.validated; - }, - set: function (value) { - console.warn( - "Please use `frappe.validated` instead of `validated`. It will be deprecated soon." - ); // eslint-disable-line - frappe.validated = value; - return frappe.validated; - }, -}); diff --git a/frappe/public/js/frappe/ui/messages.js b/frappe/public/js/frappe/ui/messages.js index bbd74dba4a..c2d74ee7a3 100644 --- a/frappe/public/js/frappe/ui/messages.js +++ b/frappe/public/js/frappe/ui/messages.js @@ -458,13 +458,3 @@ frappe.show_alert = frappe.toast = function (message, seconds = 7, actions = {}) return div; }; - -// Proxy for frappe.show_alert -Object.defineProperty(window, "show_alert", { - get: function () { - console.warn( - "Please use `frappe.show_alert` instead of `show_alert`. It will be deprecated soon." - ); - return frappe.show_alert; - }, -}); diff --git a/frappe/public/js/frappe/utils/datetime.js b/frappe/public/js/frappe/utils/datetime.js index 44ce1bb44d..0746b794f0 100644 --- a/frappe/public/js/frappe/utils/datetime.js +++ b/frappe/public/js/frappe/utils/datetime.js @@ -270,34 +270,3 @@ $.extend(frappe.datetime, { return moment.weekdays().indexOf(first_day_of_the_week); }, }); - -// Proxy for dateutil and get_today -Object.defineProperties(window, { - dateutil: { - get: function () { - console.warn( - "Please use `frappe.datetime` instead of `dateutil`. It will be deprecated soon." - ); - return frappe.datetime; - }, - configurable: true, - }, - date: { - get: function () { - console.warn( - "Please use `frappe.datetime` instead of `date`. It will be deprecated soon." - ); - return frappe.datetime; - }, - configurable: true, - }, - get_today: { - get: function () { - console.warn( - "Please use `frappe.datetime.get_today` instead of `get_today`. It will be deprecated soon." - ); - return frappe.datetime.get_today; - }, - configurable: true, - }, -}); diff --git a/frappe/public/js/frappe/utils/utils.js b/frappe/public/js/frappe/utils/utils.js index f9b6114539..b75d2981a5 100644 --- a/frappe/public/js/frappe/utils/utils.js +++ b/frappe/public/js/frappe/utils/utils.js @@ -792,10 +792,6 @@ Object.assign(frappe.utils, { frappe.msgprint(__("Note: Changing the Page Name will break previous URL to this page.")); }, - notify: function (subject, body, route, onclick) { - console.log("push notifications are evil and deprecated"); - }, - set_title: function (title) { frappe._original_title = title; if (frappe._title_prefix) { diff --git a/frappe/public/js/frappe/views/reports/query_report.js b/frappe/public/js/frappe/views/reports/query_report.js index 46c407cba1..a7a86a981f 100644 --- a/frappe/public/js/frappe/views/reports/query_report.js +++ b/frappe/public/js/frappe/views/reports/query_report.js @@ -1960,12 +1960,3 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList { return this.get_filter_values; } }; - -Object.defineProperty(frappe, "query_report_filters_by_name", { - get() { - console.warn( - "[Query Report] frappe.query_report_filters_by_name is deprecated. Please use the new api: frappe.query_report.get_filter_value(fieldname) and frappe.query_report.set_filter_value(fieldname, value)" - ); - return null; - }, -}); diff --git a/frappe/test_runner.py b/frappe/test_runner.py index 3876d065b1..92b63b15f1 100644 --- a/frappe/test_runner.py +++ b/frappe/test_runner.py @@ -47,9 +47,7 @@ def main( force=False, profile=False, junit_xml_output=None, - ui_tests=False, doctype_list_path=None, - skip_test_records=False, failfast=False, case=None, ): @@ -60,11 +58,6 @@ def main( with open(frappe.get_app_path(app, doctype_list_path)) as f: doctype = f.read().strip().splitlines() - if ui_tests: - print( - "Selenium testing has been deprecated\nUse bench --site {site_name} run-ui-tests for Cypress tests" - ) - xmloutput_fh = None if junit_xml_output: xmloutput_fh = open(junit_xml_output, "wb") @@ -115,9 +108,7 @@ def main( case=case, ) else: - ret = run_all_tests( - app, verbose, profile, ui_tests, failfast=failfast, junit_xml_output=junit_xml_output - ) + ret = run_all_tests(app, verbose, profile, failfast=failfast, junit_xml_output=junit_xml_output) if not scheduler_disabled_by_user: frappe.utils.scheduler.enable_scheduler() @@ -159,9 +150,7 @@ class TimeLoggingTestResult(unittest.TextTestResult): super().addSuccess(test) -def run_all_tests( - app=None, verbose=False, profile=False, ui_tests=False, failfast=False, junit_xml_output=False -): +def run_all_tests(app=None, verbose=False, profile=False, failfast=False, junit_xml_output=False): import os apps = [app] if app else frappe.get_installed_apps() @@ -181,7 +170,7 @@ def run_all_tests( for filename in files: if filename.startswith("test_") and filename.endswith(".py") and filename != "test_runner.py": # print filename[:-3] - _add_test(app, path, filename, verbose, test_suite, ui_tests) + _add_test(app, path, filename, verbose, test_suite) if junit_xml_output: runner = unittest_runner(verbosity=1 + cint(verbose), failfast=failfast) @@ -316,7 +305,7 @@ def _run_unittest( return out -def _add_test(app, path, filename, verbose, test_suite=None, ui_tests=False): +def _add_test(app, path, filename, verbose, test_suite=None): import os if os.path.sep.join(["doctype", "doctype", "boilerplate"]) in path: @@ -338,11 +327,6 @@ def _add_test(app, path, filename, verbose, test_suite=None, ui_tests=False): for doctype in module.test_dependencies: make_test_records(doctype, verbose=verbose, commit=True) - is_ui_test = True if hasattr(module, "TestDriver") else False - - if is_ui_test != ui_tests: - return - if not test_suite: test_suite = unittest.TestSuite() diff --git a/frappe/tests/test_rename_doc.py b/frappe/tests/test_rename_doc.py index 3f67bc4a1f..c831e832fb 100644 --- a/frappe/tests/test_rename_doc.py +++ b/frappe/tests/test_rename_doc.py @@ -249,18 +249,6 @@ class TestRenameDoc(FrappeTestCase): doctype=self.test_doctype, ) - def test_deprecated_utils(self): - from frappe.model.rename_doc import get_fetch_fields, update_linked_doctypes - - stdout = StringIO() - - with redirect_stdout(stdout), patch_db(["set_value"]): - get_fetch_fields("User", "ToDo", ["Activity Log"]) - self.assertIn("Function frappe.model.rename_doc.get_fetch_fields", stdout.getvalue()) - - update_linked_doctypes("User", "ToDo", "str", "str") - self.assertIn("Function frappe.model.rename_doc.update_linked_doctypes", stdout.getvalue()) - def test_doc_rename_method(self): name = choice(self.available_documents) new_name = f"{name}-{frappe.generate_hash(length=4)}" diff --git a/frappe/utils/data.py b/frappe/utils/data.py index deb5ea486f..d59a6c16e6 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -18,7 +18,6 @@ from click import secho import frappe from frappe.desk.utils import slug -from frappe.utils.deprecations import deprecation_warning DateTimeLikeObject = Union[str, datetime.date, datetime.datetime] NumericType = Union[int, float] diff --git a/frappe/utils/safe_exec.py b/frappe/utils/safe_exec.py index 8f73efd17c..f5ee095309 100644 --- a/frappe/utils/safe_exec.py +++ b/frappe/utils/safe_exec.py @@ -24,7 +24,7 @@ from frappe.model.mapper import get_mapped_doc from frappe.model.rename_doc import rename_doc from frappe.modules import scrub from frappe.utils.background_jobs import enqueue, get_jobs -from frappe.website.utils import get_next_link, get_shade, get_toc +from frappe.website.utils import get_next_link, get_toc from frappe.www.printview import get_visible_columns @@ -197,7 +197,6 @@ def get_safe_globals(): get_toc=get_toc, get_next_link=get_next_link, _=frappe._, - get_shade=get_shade, scrub=scrub, guess_mimetype=mimetypes.guess_type, html2text=html2text, diff --git a/frappe/website/utils.py b/frappe/website/utils.py index de639d1709..f5215e9440 100644 --- a/frappe/website/utils.py +++ b/frappe/website/utils.py @@ -191,11 +191,6 @@ def cleanup_page_name(title: str) -> str: return name[:140] -def get_shade(color, percent=None): - frappe.msgprint(_("get_shade method has been deprecated.")) - return color - - def abs_url(path): """Deconstructs and Reconstructs a URL into an absolute URL or a URL relative from root '/'""" if not path: