Skip to content

Commit

Permalink
Merge branch 'version-14' of https://github.com/frappe/frappe into ve…
Browse files Browse the repository at this point in the history
…rsion-14
  • Loading branch information
aliriocastro committed Feb 24, 2024
2 parents 8abb8d9 + b26f55c commit 5339410
Show file tree
Hide file tree
Showing 373 changed files with 2,067 additions and 2,816 deletions.
3 changes: 2 additions & 1 deletion .github/helper/consumer_db/mariadb.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"allow_tests": true,
"db_type": "mariadb",
"auto_email_id": "[email protected]",
"mail_server": "smtp.example.com",
"mail_server": "localhost",
"mail_port": 2525,
"mail_login": "[email protected]",
"mail_password": "test",
"admin_password": "admin",
Expand Down
3 changes: 2 additions & 1 deletion .github/helper/consumer_db/postgres.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"db_type": "postgres",
"allow_tests": true,
"auto_email_id": "[email protected]",
"mail_server": "smtp.example.com",
"mail_server": "localhost",
"mail_port": 2525,
"mail_login": "[email protected]",
"mail_password": "test",
"admin_password": "admin",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
- name: Setup dependencies
run: |
npm install @semantic-release/git @semantic-release/exec --no-save
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,4 @@ jobs:
- run: |
pip install pip-audit
cd ${GITHUB_WORKSPACE}
sed -i '/dropbox/d' pyproject.toml # Remove dropbox temporarily https://github.com/dropbox/dropbox-sdk-python/pull/456
pip-audit --desc on --ignore-vuln GHSA-4xqq-73wg-5mjp .
6 changes: 6 additions & 0 deletions .github/workflows/server-mariadb-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3

smtp_server:
image: rnwood/smtp4dev
ports:
- 2525:25
- 3000:80

steps:
- name: Clone
uses: actions/checkout@v3
Expand Down
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ repos:
- id: pyupgrade
args: ['--py310-plus']

- repo: https://github.com/frappe/black
rev: 951ccf4d5bb0d692b457a5ebc4215d755618eb68
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.0
hooks:
- id: black
- id: ruff
name: "Sort Python imports"
args: ["--select", "I", "--fix"]

- id: ruff-format
name: "Format Python code"

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
Expand All @@ -49,11 +54,6 @@ repos:
)$
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
Expand Down
55 changes: 15 additions & 40 deletions frappe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
)
from .utils.lazy_loader import lazy_import

__version__ = "14.62.2"
__version__ = "14.66.2"
__title__ = "Frappe Framework"

controllers = {}
Expand All @@ -53,9 +53,7 @@

_dev_server = int(sbool(os.environ.get("DEV_SERVER", False)))
_qb_patched = {}
re._MAXCACHE = (
50 # reduced from default 512 given we are already maintaining this on parent worker
)
re._MAXCACHE = 50 # reduced from default 512 given we are already maintaining this on parent worker

_tune_gc = bool(sbool(os.environ.get("FRAPPE_TUNE_GC", True)))

Expand Down Expand Up @@ -258,9 +256,7 @@ def init(site: str, sites_path: str = ".", new_site: bool = False, force=False)
local.initialised = True


def connect(
site: str | None = None, db_name: str | None = None, set_admin_as_user: bool = True
) -> None:
def connect(site: str | None = None, db_name: str | None = None, set_admin_as_user: bool = True) -> None:
"""Connect to site database instance.
:param site: If site is given, calls `frappe.init`.
Expand Down Expand Up @@ -780,9 +776,7 @@ def is_whitelisted(method):
is_guest = session["user"] == "Guest"
if method not in whitelisted or is_guest and method not in guest_methods:
summary = _("You are not permitted to access this resource.")
detail = _("Function {0} is not whitelisted.").format(
bold(f"{method.__module__}.{method.__name__}")
)
detail = _("Function {0} is not whitelisted.").format(bold(f"{method.__module__}.{method.__name__}"))
msg = f"<details><summary>{summary}</summary>{detail}</details>"
throw(msg, PermissionError, title="Method Not Allowed")

Expand All @@ -797,7 +791,6 @@ def is_whitelisted(method):
def read_only():
def innfn(fn):
def wrapper_fn(*args, **kwargs):

# frappe.read_only could be called from nested functions, in such cases don't swap the
# connection again.
switched_connection = False
Expand Down Expand Up @@ -973,9 +966,7 @@ def has_permission(
)

if throw and not out:
document_label = (
f"{_(doctype)} {doc if isinstance(doc, str) else doc.name}" if doc else _(doctype)
)
document_label = f"{_(doctype)} {doc if isinstance(doc, str) else doc.name}" if doc else _(doctype)
frappe.flags.error_message = _("No permission for {0}").format(document_label)
raise frappe.PermissionError

Expand Down Expand Up @@ -1156,9 +1147,7 @@ def clear_document_cache(doctype, name):
delattr(local, "website_settings")


def get_cached_value(
doctype: str, name: str, fieldname: str = "name", as_dict: bool = False
) -> Any:
def get_cached_value(doctype: str, name: str, fieldname: str = "name", as_dict: bool = False) -> Any:
try:
doc = get_cached_doc(doctype, name)
except DoesNotExistError:
Expand Down Expand Up @@ -1493,9 +1482,7 @@ def _is_valid_hook(obj):
return hooks


def get_hooks(
hook: str = None, default: Any | None = "_KEEP_DEFAULT_LIST", app_name: str = None
) -> _dict:
def get_hooks(hook: str = None, default: Any | None = "_KEEP_DEFAULT_LIST", app_name: str = None) -> _dict:
"""Get hooks via `app/hooks.py`
:param hook: Name of the hook. Will gather all hooks for this name and return as a list.
Expand Down Expand Up @@ -1598,11 +1585,7 @@ def read_file(path, raise_not_found=False):
def get_attr(method_string: str) -> Any:
"""Get python method object from its name."""
app_name = method_string.split(".", 1)[0]
if (
not local.flags.in_uninstall
and not local.flags.in_install
and app_name not in get_installed_apps()
):
if not local.flags.in_uninstall and not local.flags.in_install and app_name not in get_installed_apps():
throw(_("App {0} is not installed").format(app_name), AppNotInstalledError)

modulename = ".".join(method_string.split(".")[:-1])
Expand All @@ -1624,7 +1607,8 @@ def get_newargs(fn: Callable, kwargs: dict[str, Any]) -> dict[str, Any]:
"""Remove any kwargs that are not supported by the function.
Example:
>>> def fn(a=1, b=2): pass
>>> def fn(a=1, b=2):
... pass
>>> get_newargs(fn, {"a": 2, "c": 1})
{"a": 2}
Expand Down Expand Up @@ -1960,9 +1944,7 @@ def as_json(obj: dict | list, indent=1, separators=None) -> str:
separators = (",", ": ")

try:
return json.dumps(
obj, indent=indent, sort_keys=True, default=json_handler, separators=separators
)
return json.dumps(obj, indent=indent, sort_keys=True, default=json_handler, separators=separators)
except TypeError:
# this would break in case the keys are not all os "str" type - as defined in the JSON
# adding this to ensure keys are sorted (expected behaviour)
Expand Down Expand Up @@ -2048,10 +2030,7 @@ def get_print(
if not html:
html = get_response_content("printview")

if as_pdf:
return get_pdf(html, options=pdf_options, output=output)
else:
return html
return get_pdf(html, options=pdf_options, output=output) if as_pdf else html


def attach_print(
Expand Down Expand Up @@ -2212,9 +2191,7 @@ def _get_doctype_app():
log_level = None


def logger(
module=None, with_more_info=False, allow_site=True, filter=None, max_size=100_000, file_count=20
):
def logger(module=None, with_more_info=False, allow_site=True, filter=None, max_size=100_000, file_count=20):
"""Returns a python logger that uses StreamHandler"""
from frappe.utils.logger import get_logger

Expand Down Expand Up @@ -2260,9 +2237,7 @@ def log_error(title=None, message=None, reference_doctype=None, reference_name=N


def get_desk_link(doctype, name):
html = (
'<a href="/app/Form/{doctype}/{name}" style="font-weight: bold;">{doctype_local} {name}</a>'
)
html = '<a href="/app/Form/{doctype}/{name}" style="font-weight: bold;">{doctype_local} {name}</a>'
return html.format(doctype=doctype, name=name, doctype_local=_(doctype))


Expand Down Expand Up @@ -2313,7 +2288,7 @@ def get_version(doctype, name, limit=None, head=False, raise_err=True):
Note: Applicable only if DocType has changes tracked.
Example
>>> frappe.get_version('User', '[email protected]')
>>> frappe.get_version("User", "[email protected]")
>>>
[
{
Expand Down
4 changes: 1 addition & 3 deletions frappe/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ def validate_oauth(authorization_header):
req = frappe.request
parsed_url = urlparse(req.url)
access_token = {"access_token": token}
uri = (
parsed_url.scheme + "://" + parsed_url.netloc + parsed_url.path + "?" + urlencode(access_token)
)
uri = parsed_url.scheme + "://" + parsed_url.netloc + parsed_url.path + "?" + urlencode(access_token)
http_method = req.method
headers = req.headers
body = req.get_data()
Expand Down
12 changes: 3 additions & 9 deletions frappe/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ def set_cors_headers(response):

# only required for preflight requests
if request.method == "OPTIONS":
cors_headers["Access-Control-Allow-Methods"] = request.headers.get(
"Access-Control-Request-Method"
)
cors_headers["Access-Control-Allow-Methods"] = request.headers.get("Access-Control-Request-Method")

if allowed_headers := request.headers.get("Access-Control-Request-Headers"):
cors_headers["Access-Control-Allow-Headers"] = allowed_headers
Expand Down Expand Up @@ -399,9 +397,7 @@ def sync_database(rollback: bool) -> bool:
return rollback


def serve(
port=8000, profile=False, no_reload=False, no_threading=False, site=None, sites_path="."
):
def serve(port=8000, profile=False, no_reload=False, no_threading=False, site=None, sites_path="."):
global application, _site, _sites_path
_site = site
_sites_path = sites_path
Expand All @@ -412,9 +408,7 @@ def serve(
application = ProfilerMiddleware(application, sort_by=("cumtime", "calls"))

if not os.environ.get("NO_STATICS"):
application = SharedDataMiddleware(
application, {"/assets": str(os.path.join(sites_path, "assets"))}
)
application = SharedDataMiddleware(application, {"/assets": str(os.path.join(sites_path, "assets"))})

application = StaticDataMiddleware(application, {"/files": str(os.path.abspath(sites_path))})

Expand Down
Loading

0 comments on commit 5339410

Please sign in to comment.