- MagicPython
- atom-beautify
- bracket-colorizer
- linter-eslint
- linter-pycodestyle - also requires you to install
pycodestyle
python -m pip install pycodestyle --userI use an 89 character line length and ignore these error codes:
| import csv | |
| import random | |
| import typing | |
| from pathlib import Path | |
| import mimesis | |
| def write_to_file(filename: str, data: list) -> typing.NoReturn: | |
| raw_path = Path(__file__).parent / filename |
| from requests import request | |
| from base64 import b64encode | |
| api_secret = get_decrypted_password("User", "example_username", "api_secret") # this is an internal frappe method | |
| token = frappe.get_value("User", "example_username", "api_key") # this is an internal frappe method | |
| url = "https://" + subdomain + ".some_domain.com" | |
| headers = { | |
| "Content-Type": "application/json", | |
| "Authorization": "Basic " | |
| + b64encode(bytes(token + ":" + api_secret, "ascii")).decode("ascii"), |
| import asyncio | |
| from functools import wraps | |
| def dec(fn): | |
| @wraps(fn) | |
| async def wrapper(*args, **kwargs): | |
| print(fn, args, kwargs) # <function foo at 0x10952d598> () {} | |
| await asyncio.sleep(5) |
pycodestylepython -m pip install pycodestyle --userI use an 89 character line length and ignore these error codes:
| doc_events = { | |
| "Sales Order": { | |
| "on_submit": "my_custom_app.workflows.make_stock_entry_on_so_submit" | |
| }, | |
| "on_cancel": "my_custom_app.workflows.cancel_stock_entry_on_so_cancel" | |
| } | |
| } |
| #this can be done in a either a document hook or | |
| import types | |
| import rounding_error_monkey_patch | |
| doc = frappe.new_doc("Journal Entry") | |
| # monkey patch validate_invoices method to bypass (incorrect) rounding error | |
| doc.validate_invoices = types.MethodType(rounding_error_monkey_patch, doc) | |
| return doc |
| """ | |
| # graphql query to run in the playground | |
| { | |
| hello | |
| } | |
| """ | |
| from ariadne import QueryType, graphql, make_executable_schema | |
| from ariadne.constants import PLAYGROUND_HTML | |
| from quart import Quart, request, jsonify |
| # Overriding Whitelisted Methods (in my_app/hooks.py) | |
| # ------------------------------ | |
| override_whitelisted_methods = { | |
| "frappe.model.workflow.apply_workflow": "my_app.workflows.apply_workflow" | |
| } | |
| # in my_app/workflows.py | |
| import frappe | |
| from frappe.model.workflow import apply_workflow as model_apply_workflow |
| import requests | |
| from base64 import b64encode | |
| import json | |
| def push_po(doc, method): | |
| # additional business logic or other validations | |
| # prune document fields and turn into json | |
| payload = json.loads({"docfield": doc}) | |
| api_key, api_secret = frappe.get_value("User", frappe.session.user, ["api_key", "api_secret"]) |