refactor!: Drop previously deprecated code

This commit is contained in:
Ankush Menat 2023-06-10 18:29:00 +05:30 committed by Ankush Menat
parent bd60c60d4e
commit 3005e66e45
18 changed files with 8 additions and 305 deletions

View file

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

View file

@ -227,8 +227,6 @@ def bundle(
mode,
apps=None,
hard_link=False,
make_copy=False,
restore=False,
verbose=False,
skip_frappe=False,
files=None,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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;
},
});

View file

@ -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;
},
});

View file

@ -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,
},
});

View file

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

View file

@ -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;
},
});

View file

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

View file

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

View file

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

View file

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

View file

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