style: Linting fixes (#6809)

* style: Remove unused imports

* style: Remove unused local variables
This commit is contained in:
Aditya Hase 2019-01-23 16:39:55 +05:30 committed by Faris Ansari
parent 1212139117
commit 6b72faf44f
34 changed files with 38 additions and 68 deletions

View file

@ -1,6 +1,6 @@
from __future__ import unicode_literals, absolute_import, print_function
import click
import json, sys
import sys
import frappe
from frappe.utils import cint
from frappe.commands import pass_context, get_site

View file

@ -1,6 +1,5 @@
from __future__ import unicode_literals, absolute_import, print_function
import click
import frappe
from frappe.commands import pass_context, get_site
# translation

View file

@ -2,7 +2,7 @@
# MIT License. See license.txt
import frappe
from frappe import _
def get_parent_doc(doc):
"""Returns document of `reference_doctype`, `reference_doctype`"""

View file

@ -1,5 +1,5 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
@ -78,7 +78,7 @@ def add_match_conditions(q, tl):
q = q[0] + condition_st + '(' + ' OR '.join(sl) + ') ' + condition_end + q[1]
else:
q = q + condition_st + '(' + ' OR '.join(sl) + ')'
return q
def guess_type(m):
@ -178,7 +178,7 @@ def runquery(q='', ret=0, from_export=0):
meta = get_sql_meta(tl)
q = add_match_conditions(q, tl)
# replace special variables
q = q.replace('__user', frappe.session.user)
q = q.replace('__today', frappe.utils.nowdate())
@ -223,9 +223,6 @@ def runquery(q='', ret=0, from_export=0):
def runquery_csv():
global out
# run query
res = runquery(from_export = 1)
q = frappe.form_dict.get('query')
rep_name = frappe.form_dict.get('report_name')
@ -237,9 +234,6 @@ def runquery_csv():
if not rep_name: rep_name = 'DataExport'
# Headings
heads = []
rows = [[rep_name], out['colnames']] + out['values']
from six import StringIO
@ -264,9 +258,9 @@ def add_limit_to_query(query, args):
if args.get('limit_page_length'):
query += """
limit %(limit_start)s, %(limit_page_length)s"""
import frappe.utils
args['limit_start'] = frappe.utils.cint(args.get('limit_start'))
args['limit_page_length'] = frappe.utils.cint(args.get('limit_page_length'))
return query, args

View file

@ -45,7 +45,6 @@ def get_form_params():
else:
data["save_user_settings"] = True
doctype = data["doctype"]
fields = data["fields"]
for field in fields:

View file

@ -6,7 +6,7 @@ import frappe, re, os
from frappe.utils.pdf import get_pdf
from frappe.email.smtp import get_outgoing_email_account
from frappe.utils import (get_url, scrub_urls, strip, expand_relative_urls, cint,
split_emails, to_markdown, markdown, encode, random_string, parse_addr)
split_emails, to_markdown, markdown, random_string, parse_addr)
import email.utils
from six import iteritems, text_type, string_types
from email.mime.multipart import MIMEMultipart

View file

@ -2,7 +2,7 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe, unittest, os, base64
import unittest, os, base64
from frappe.email.email_body import (replace_filename_with_cid,
get_email, inline_style_in_html, get_header)

View file

@ -4,7 +4,6 @@
# model __init__.py
from __future__ import unicode_literals
import frappe
import json
no_value_fields = ('Section Break', 'Column Break', 'HTML', 'Table', 'Button', 'Image',

View file

@ -6,7 +6,7 @@ from six import iteritems, string_types
import datetime
import frappe, sys
from frappe import _
from frappe.utils import (cint, flt, now, cstr, strip_html, getdate, get_datetime, to_timedelta,
from frappe.utils import (cint, flt, now, cstr, strip_html,
sanitize_html, sanitize_email, cast_fieldtype)
from frappe.model import default_fields
from frappe.model.naming import set_new_name

View file

@ -3,7 +3,7 @@
from __future__ import unicode_literals
import frappe, os, json
import frappe, os
import frappe.model
from frappe.modules import scrub, get_module_path, scrub_dt_dn

View file

@ -14,7 +14,7 @@ def insert_test_data(doctype, sort_fn=None):
def get_test_doclist(doctype, name=None):
"""get test doclist, collection of doclists"""
import os, frappe
import os
from frappe import conf
from frappe.modules.utils import peval_doclist
from frappe.modules import scrub
@ -22,17 +22,17 @@ def get_test_doclist(doctype, name=None):
doctype = scrub(doctype)
doctype_path = os.path.join(os.path.dirname(os.path.abspath(conf.__file__)),
conf.test_data_path, doctype)
if name:
with open(os.path.join(doctype_path, scrub(name) + ".json"), 'r') as txtfile:
doclist = peval_doclist(txtfile.read())
return doclist
else:
all_doclists = []
for fname in filter(lambda n: n.endswith(".json"), os.listdir(doctype_path)):
with open(os.path.join(doctype_path, scrub(fname)), 'r') as txtfile:
all_doclists.append(peval_doclist(txtfile.read()))
return all_doclists

View file

@ -3,8 +3,7 @@
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import flt, cstr, fmt_money
from frappe.utils import fmt_money
import unittest
class TestFmtMoney(unittest.TestCase):

View file

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe, unittest
from frappe.desk.form.load import getdoctype, getdoc
from frappe.core.page.permission_manager.permission_manager import update, reset
from frappe.permissions import get_valid_perms
class TestFormLoad(unittest.TestCase):
def test_load(self):

View file

@ -2,7 +2,6 @@
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
import unittest
class TestGeoIP(unittest.TestCase):

View file

@ -7,11 +7,9 @@ from __future__ import unicode_literals
import frappe
import frappe.defaults
import unittest
import json
import frappe.model.meta
from frappe.permissions import (add_user_permission, remove_user_permission,
clear_user_permissions_for_doctype, get_doc_permissions, add_permission,
get_valid_perms)
clear_user_permissions_for_doctype, get_doc_permissions, add_permission)
from frappe.core.page.permission_manager.permission_manager import update, reset
from frappe.test_runner import make_test_records_for_doctype
from frappe.core.doctype.user_permission.user_permission import clear_user_permissions

View file

@ -9,7 +9,7 @@ from frappe.auth import HTTPRequest
from frappe.utils import cint
from frappe.twofactor import (should_run_2fa, authenticate_for_2factor, get_cached_user_pass,
two_factor_is_enabled_for_, confirm_otp_token, get_otpsecret_for_, get_verification_obj,
render_string_template, two_factor_is_enabled)
render_string_template)
import time

View file

@ -58,8 +58,6 @@ class BackupGenerator:
self.backup_path_private_files = last_private_file
def set_backup_file_name(self):
import random
todays_date = now_datetime().strftime('%Y%m%d_%H%M%S')
site = frappe.local.site or frappe.generate_hash(length=8)
site = site.replace('.', '_')

View file

@ -6,7 +6,7 @@ from __future__ import unicode_literals, print_function
from six.moves import input
import frappe, os, re
from frappe.utils import touch_file, encode, cstr
from frappe.utils import touch_file, cstr
def make_boilerplate(dest, app_name):
if not os.path.exists(dest):

View file

@ -11,7 +11,7 @@ import subprocess # nosec
from frappe.utils import cstr
from frappe.utils.gitutils import get_app_branch
from frappe import _, safe_decode
import git
def get_change_log(user=None):
if not user: user = frappe.session.user
@ -123,7 +123,7 @@ def get_app_branch(app):
result = safe_decode(result)
result = result.strip()
return result
except Exception as e:
except Exception:
return ''
def get_app_last_commit_ref(app):
@ -133,7 +133,7 @@ def get_app_last_commit_ref(app):
result = safe_decode(result)
result = result.strip()
return result
except Exception as e:
except Exception:
return ''
def check_for_update():
@ -222,7 +222,6 @@ def show_update_popup():
return
updates = json.loads(update_info)
current_versions = get_versions()
# Check if user is int the set of users to send update message to
update_message = ""

View file

@ -6,7 +6,7 @@ from __future__ import unicode_literals
# IMPORTANT: only import safe functions as this module will be included in jinja environment
import frappe
import operator
import re, urllib, datetime, math, time
import re, datetime, math, time
import babel.dates
from babel.core import UnknownLocaleError
from dateutil import parser

View file

@ -30,7 +30,7 @@ def user_to_str(date, date_format=None):
try:
return datetime.datetime.strptime(date,
dateformats[date_format]).strftime('%Y-%m-%d')
except ValueError as e:
except ValueError:
raise ValueError("Date %s must be in format %s" % (date, date_format))
def parse_date(date):
@ -50,7 +50,7 @@ def parse_date(date):
parsed_date = user_to_str(date, f)
if parsed_date:
break
except ValueError as e:
except ValueError:
pass
if not parsed_date:

View file

@ -13,7 +13,6 @@ import traceback
import linecache
import pydoc
import cgitb
import types
import datetime
import json
import six

View file

@ -28,7 +28,6 @@ def upload():
# get record details
dt = frappe.form_dict.doctype
dn = frappe.form_dict.docname
df = frappe.form_dict.docfield
file_url = frappe.form_dict.file_url
filename = frappe.form_dict.filename
frappe.form_dict.is_private = cint(frappe.form_dict.is_private)

View file

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe import _
from six.moves import xrange
def get_monthly_results(goal_doctype, goal_field, date_col, filter_str, aggregation = 'sum'):
'''Get monthly aggregation values for given field of doctype'''

View file

@ -5,7 +5,7 @@ from __future__ import unicode_literals
try:
from zxcvbn import zxcvbn
except Exception as e:
except Exception:
import zxcvbn
import frappe

View file

@ -6,7 +6,7 @@ import pdfkit, os, frappe
from frappe.utils import scrub_urls
from frappe import _
from bs4 import BeautifulSoup
from PyPDF2 import PdfFileWriter, PdfFileReader
from PyPDF2 import PdfFileReader
import re
def get_pdf(html, options=None, output = None):

View file

@ -1,13 +1,10 @@
from __future__ import unicode_literals
import frappe, os, copy, json, re
import frappe, os
from frappe import _
from frappe.modules import get_doc_path
from jinja2 import TemplateNotFound
from frappe.utils import cint, strip_html
from frappe.utils.pdf import get_pdf,cleanup
from PyPDF2 import PdfFileWriter, PdfFileReader
from PyPDF2 import PdfFileWriter
no_cache = 1
no_sitemap = 1

View file

@ -1,10 +1,9 @@
import frappe
import json, os
from frappe.modules import scrub, get_module_path, load_doctype_module, utils
from frappe.modules import scrub, get_module_path, utils
from frappe.custom.doctype.customize_form.customize_form import doctype_properties, docfield_properties
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
from frappe.modules.import_file import get_file_path, read_doc_from_file
from frappe.core.page.permission_manager.permission_manager import get_standard_permissions
from frappe.permissions import setup_custom_perms
from six.moves.urllib.request import urlopen
@ -89,7 +88,7 @@ def make_custom_fields(doctype, local_doc, original_doc):
custom_docfield_properties, prev = get_custom_docfield_properties(), ""
for field, field_dict in local_fields:
df, doc = {}, {}
df = {}
if field not in original_fields:
for prop in field_dict:
if prop in custom_docfield_properties:

View file

@ -3,13 +3,12 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import encode, cstr, cint, flt, comma_or
import openpyxl
import re
from openpyxl.styles import Font
from openpyxl import load_workbook
from six import StringIO, BytesIO, string_types
from six import BytesIO, string_types
ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')
# return xlsx file object
@ -53,7 +52,7 @@ def handle_html(data):
if '>' not in data:
return data
from html2text import unescape, HTML2Text
from html2text import HTML2Text
h = HTML2Text()
h.unicode_snob = True

View file

@ -43,7 +43,7 @@ def render(path=None, http_status_code=None):
else:
try:
data = render_page_by_language(path)
except frappe.DoesNotExistError as e:
except frappe.DoesNotExistError:
doctype, name = get_doctype_from_path(path)
if doctype and name:
path = "printview"
@ -77,7 +77,7 @@ def render(path=None, http_status_code=None):
data = add_csrf_token(data)
except frappe.Redirect as e:
except frappe.Redirect:
return build_response(path, "", 301, {
"Location": frappe.flags.redirect_location or (frappe.local.response or {}).get('location'),
"Cache-Control": "no-store, no-cache, must-revalidate"

View file

@ -2,10 +2,7 @@
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils.user import get_fullname_and_avatar
import frappe.www.list
no_cache = 1
no_sitemap = 1

View file

@ -3,7 +3,6 @@
from __future__ import unicode_literals
import frappe
import urllib
from frappe.utils import escape_html, get_request_site_address, now, cstr
from six.moves.urllib.parse import quote, urljoin

View file

@ -3,8 +3,6 @@
from __future__ import unicode_literals
import urllib
import frappe
from frappe.utils import get_request_site_address, get_datetime, nowdate
from frappe.website.router import get_pages, get_all_page_context_from_doctypes
from six import iteritems

View file

@ -3,7 +3,6 @@
from __future__ import unicode_literals
import re
import frappe
from frappe.website.utils import get_shade
from frappe.website.doctype.website_theme.website_theme import get_active_theme