Ver a proveniência

Merge pull request #13243 from gavindsouza/deprecation-warnings

fix: Hide all warnings in frappe commands
version-14
gavin há 4 anos
committed by GitHub
ascendente
cometimento
b9f884ee67
Não foi encontrada uma chave conhecida para esta assinatura, na base de dados ID da chave GPG: 4AEE18F83AFDEB23
5 ficheiros alterados com 24 adições e 12 eliminações
  1. +9
    -4
      frappe/__init__.py
  2. +11
    -3
      frappe/build.py
  3. +0
    -3
      frappe/commands/utils.py
  4. +3
    -1
      frappe/utils/bench_helper.py
  5. +1
    -1
      frappe/utils/safe_exec.py

+ 9
- 4
frappe/__init__.py Ver ficheiro

@@ -10,9 +10,16 @@ be used to build database driven apps.

Read the documentation: https://frappeframework.com/docs
"""
import os, warnings

_dev_server = os.environ.get('DEV_SERVER', False)

if _dev_server:
warnings.simplefilter('always', DeprecationWarning)
warnings.simplefilter('always', PendingDeprecationWarning)

from werkzeug.local import Local, release_local
import os, sys, importlib, inspect, json, warnings
import sys, importlib, inspect, json
import typing
from past.builtins import cmp
import click
@@ -31,8 +38,6 @@ __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"""
@@ -197,7 +202,7 @@ def init(site, sites_path=None, new_site=False):
local.meta_cache = {}
local.form_dict = _dict()
local.session = _dict()
local.dev_server = os.environ.get('DEV_SERVER', False)
local.dev_server = _dev_server

setup_module_map()



+ 11
- 3
frappe/build.py Ver ficheiro

@@ -317,13 +317,20 @@ def clear_broken_symlinks():



def unstrip(message):
def unstrip(message: str) -> str:
"""Pads input string on the right side until the last available column in the terminal
"""
_len = len(message)
try:
max_str = os.get_terminal_size().columns
except Exception:
max_str = 80
_len = len(message)
_rem = max_str - _len

if _len < max_str:
_rem = max_str - _len
else:
_rem = max_str % _len

return f"{message}{' ' * _rem}"


@@ -336,6 +343,7 @@ def make_asset_dirs(hard_link=False):
start_message = unstrip(f"{'Copying assets from' if hard_link else 'Linking'} {source} to {target}")
fail_message = unstrip(f"Cannot {'copy' if hard_link else 'link'} {source} to {target}")

# Used '\r' instead of '\x1b[1K\r' to print entire lines in smaller terminal sizes
try:
print(start_message, end="\r")
link_assets_dir(source, target, hard_link=hard_link)


+ 0
- 3
frappe/commands/utils.py Ver ficheiro

@@ -507,8 +507,6 @@ frappe.db.connect()
@pass_context
def console(context):
"Start ipython console for a site"
import warnings

site = get_site(context)
frappe.init(site=site)
frappe.connect()
@@ -529,7 +527,6 @@ def console(context):
if failed_to_import:
print("\nFailed to import:\n{}".format(", ".join(failed_to_import)))

warnings.simplefilter('ignore')
IPython.embed(display_banner="", header="", colors="neutral")




+ 3
- 1
frappe/utils/bench_helper.py Ver ficheiro

@@ -6,6 +6,7 @@ import json
import importlib
import frappe.utils
import traceback
import warnings

click.disable_unicode_literals_warning = True

@@ -98,5 +99,6 @@ def get_apps():
return frappe.get_all_apps(with_internal_apps=False, sites_path='.')

if __name__ == "__main__":
if not frappe._dev_server:
warnings.simplefilter('ignore')
main()


+ 1
- 1
frappe/utils/safe_exec.py Ver ficheiro

@@ -119,7 +119,7 @@ def get_safe_globals():
scrub=scrub,
guess_mimetype=mimetypes.guess_type,
html2text=html2text,
dev_server=1 if os.environ.get('DEV_SERVER', False) else 0,
dev_server=1 if frappe._dev_server else 0,
run_script=run_script
)



Carregando…
Cancelar
Guardar