Skip to content

Commit

Permalink
Merge #929
Browse files Browse the repository at this point in the history
929: black, flake8, and isort (part 1) r=hgrecco a=crusaderky

I'd like to introduce black, flake8, and isort to pint - exactly in the same way they're already used (very successfully) in xarray.

I'm breaking the PR in two to make it easier to review it and to merge it into other branches:

1) (this PR): I just run ``black -t py36 .``. No manual changes whatsoever. After it's merged, everybody who has branches open will need to run the same command on their own branch before merging - or face a lot of merge conflicts.

2) (#931, to be reviewed after this one is merged) manual changes: configure flake8 and isort; integrate flake8, isort, and black in CI; fix flake8 failures. Reviewing and merging into other branches should be uncomplicated.

Co-authored-by: Guido Imperiale <[email protected]>
  • Loading branch information
bors[bot] and crusaderky authored Dec 16, 2019
2 parents ef0cbad + e3e0255 commit 89b5bd1
Show file tree
Hide file tree
Showing 40 changed files with 4,793 additions and 3,824 deletions.
36 changes: 18 additions & 18 deletions bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import yaml


def time_stmt(stmt='pass', setup='pass', number=0, repeat=3):
def time_stmt(stmt="pass", setup="pass", number=0, repeat=3):
"""Timer function with the same behaviour as running `python -m timeit `
in the command line.
Expand All @@ -25,7 +25,7 @@ def time_stmt(stmt='pass', setup='pass', number=0, repeat=3):
x = t.timeit(number)
except Exception:
print(t.print_exc())
return float('NaN')
return float("NaN")

if x >= 0.2:
break
Expand All @@ -34,34 +34,34 @@ def time_stmt(stmt='pass', setup='pass', number=0, repeat=3):
r = t.repeat(repeat, number)
except Exception:
print(t.print_exc())
return float('NaN')
return float("NaN")

best = min(r)

return best / number


def build_task(task, name='', setup='', number=0, repeat=3):
def build_task(task, name="", setup="", number=0, repeat=3):
nt = copy.copy(task)

nt['name'] = (name + ' ' + task.get('name', '')).strip()
nt['setup'] = (setup + '\n' + task.get('setup', '')).strip('\n')
nt['stmt'] = task.get('stmt', '')
nt['number'] = task.get('number', number)
nt['repeat'] = task.get('repeat', repeat)
nt["name"] = (name + " " + task.get("name", "")).strip()
nt["setup"] = (setup + "\n" + task.get("setup", "")).strip("\n")
nt["stmt"] = task.get("stmt", "")
nt["number"] = task.get("number", number)
nt["repeat"] = task.get("repeat", repeat)

return nt


def time_task(name, stmt='pass', setup='pass', number=0, repeat=3, stmts='', base=''):
def time_task(name, stmt="pass", setup="pass", number=0, repeat=3, stmts="", base=""):

if base:
nvalue = time_stmt(stmt=base, setup=setup, number=number, repeat=repeat)
yield name + ' (base)', nvalue
suffix = ' (normalized)'
yield name + " (base)", nvalue
suffix = " (normalized)"
else:
nvalue = 1.
suffix = ''
nvalue = 1.0
suffix = ""

if stmt:
value = time_stmt(stmt=stmt, setup=setup, number=number, repeat=repeat)
Expand All @@ -73,12 +73,12 @@ def time_task(name, stmt='pass', setup='pass', number=0, repeat=3, stmts='', bas
yield task_name + suffix, value / nvalue


def time_file(filename, name='', setup='', number=0, repeat=3):
def time_file(filename, name="", setup="", number=0, repeat=3):
"""Open a yaml benchmark file an time each statement,
yields a tuple with filename, task name, time in seconds.
"""
with open(filename, 'r') as fp:
with open(filename, "r") as fp:
tasks = yaml.load(fp)

for task in tasks:
Expand All @@ -87,7 +87,7 @@ def time_file(filename, name='', setup='', number=0, repeat=3):
yield task_name, value


def recursive_glob(rootdir='.', pattern='*'):
def recursive_glob(rootdir=".", pattern="*"):
return [
os.path.join(looproot, filename)
for looproot, _, filenames in os.walk(rootdir)
Expand All @@ -104,7 +104,7 @@ def main(filenames=None):

for filename in filenames:
print(filename)
print('-' * len(filename))
print("-" * len(filename))
print()
for task_name, value in time_file(filename):
print(f"{value:.2e} {task_name}")
Expand Down
147 changes: 75 additions & 72 deletions docs/_themes/flask_theme_support.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# flasky extensions. flasky pygments style based on tango style
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic, Whitespace, Punctuation, Other, Literal
from pygments.token import (
Keyword,
Name,
Comment,
String,
Error,
Number,
Operator,
Generic,
Whitespace,
Punctuation,
Other,
Literal,
)


class FlaskyStyle(Style):
Expand All @@ -10,77 +22,68 @@ class FlaskyStyle(Style):

styles = {
# No corresponding class for the following:
#Text: "", # class: ''
Whitespace: "underline #f8f8f8", # class: 'w'
Error: "#a40000 border:#ef2929", # class: 'err'
Other: "#000000", # class 'x'

Comment: "italic #8f5902", # class: 'c'
Comment.Preproc: "noitalic", # class: 'cp'

Keyword: "bold #004461", # class: 'k'
Keyword.Constant: "bold #004461", # class: 'kc'
Keyword.Declaration: "bold #004461", # class: 'kd'
Keyword.Namespace: "bold #004461", # class: 'kn'
Keyword.Pseudo: "bold #004461", # class: 'kp'
Keyword.Reserved: "bold #004461", # class: 'kr'
Keyword.Type: "bold #004461", # class: 'kt'

Operator: "#582800", # class: 'o'
Operator.Word: "bold #004461", # class: 'ow' - like keywords

Punctuation: "bold #000000", # class: 'p'

# Text: "", # class: ''
Whitespace: "underline #f8f8f8", # class: 'w'
Error: "#a40000 border:#ef2929", # class: 'err'
Other: "#000000", # class 'x'
Comment: "italic #8f5902", # class: 'c'
Comment.Preproc: "noitalic", # class: 'cp'
Keyword: "bold #004461", # class: 'k'
Keyword.Constant: "bold #004461", # class: 'kc'
Keyword.Declaration: "bold #004461", # class: 'kd'
Keyword.Namespace: "bold #004461", # class: 'kn'
Keyword.Pseudo: "bold #004461", # class: 'kp'
Keyword.Reserved: "bold #004461", # class: 'kr'
Keyword.Type: "bold #004461", # class: 'kt'
Operator: "#582800", # class: 'o'
Operator.Word: "bold #004461", # class: 'ow' - like keywords
Punctuation: "bold #000000", # class: 'p'
# because special names such as Name.Class, Name.Function, etc.
# are not recognized as such later in the parsing, we choose them
# to look the same as ordinary variables.
Name: "#000000", # class: 'n'
Name.Attribute: "#c4a000", # class: 'na' - to be revised
Name.Builtin: "#004461", # class: 'nb'
Name.Builtin.Pseudo: "#3465a4", # class: 'bp'
Name.Class: "#000000", # class: 'nc' - to be revised
Name.Constant: "#000000", # class: 'no' - to be revised
Name.Decorator: "#888", # class: 'nd' - to be revised
Name.Entity: "#ce5c00", # class: 'ni'
Name.Exception: "bold #cc0000", # class: 'ne'
Name.Function: "#000000", # class: 'nf'
Name.Property: "#000000", # class: 'py'
Name.Label: "#f57900", # class: 'nl'
Name.Namespace: "#000000", # class: 'nn' - to be revised
Name.Other: "#000000", # class: 'nx'
Name.Tag: "bold #004461", # class: 'nt' - like a keyword
Name.Variable: "#000000", # class: 'nv' - to be revised
Name.Variable.Class: "#000000", # class: 'vc' - to be revised
Name.Variable.Global: "#000000", # class: 'vg' - to be revised
Name.Variable.Instance: "#000000", # class: 'vi' - to be revised

Number: "#990000", # class: 'm'

Literal: "#000000", # class: 'l'
Literal.Date: "#000000", # class: 'ld'

String: "#4e9a06", # class: 's'
String.Backtick: "#4e9a06", # class: 'sb'
String.Char: "#4e9a06", # class: 'sc'
String.Doc: "italic #8f5902", # class: 'sd' - like a comment
String.Double: "#4e9a06", # class: 's2'
String.Escape: "#4e9a06", # class: 'se'
String.Heredoc: "#4e9a06", # class: 'sh'
String.Interpol: "#4e9a06", # class: 'si'
String.Other: "#4e9a06", # class: 'sx'
String.Regex: "#4e9a06", # class: 'sr'
String.Single: "#4e9a06", # class: 's1'
String.Symbol: "#4e9a06", # class: 'ss'

Generic: "#000000", # class: 'g'
Generic.Deleted: "#a40000", # class: 'gd'
Generic.Emph: "italic #000000", # class: 'ge'
Generic.Error: "#ef2929", # class: 'gr'
Generic.Heading: "bold #000080", # class: 'gh'
Generic.Inserted: "#00A000", # class: 'gi'
Generic.Output: "#888", # class: 'go'
Generic.Prompt: "#745334", # class: 'gp'
Generic.Strong: "bold #000000", # class: 'gs'
Generic.Subheading: "bold #800080", # class: 'gu'
Generic.Traceback: "bold #a40000", # class: 'gt'
Name: "#000000", # class: 'n'
Name.Attribute: "#c4a000", # class: 'na' - to be revised
Name.Builtin: "#004461", # class: 'nb'
Name.Builtin.Pseudo: "#3465a4", # class: 'bp'
Name.Class: "#000000", # class: 'nc' - to be revised
Name.Constant: "#000000", # class: 'no' - to be revised
Name.Decorator: "#888", # class: 'nd' - to be revised
Name.Entity: "#ce5c00", # class: 'ni'
Name.Exception: "bold #cc0000", # class: 'ne'
Name.Function: "#000000", # class: 'nf'
Name.Property: "#000000", # class: 'py'
Name.Label: "#f57900", # class: 'nl'
Name.Namespace: "#000000", # class: 'nn' - to be revised
Name.Other: "#000000", # class: 'nx'
Name.Tag: "bold #004461", # class: 'nt' - like a keyword
Name.Variable: "#000000", # class: 'nv' - to be revised
Name.Variable.Class: "#000000", # class: 'vc' - to be revised
Name.Variable.Global: "#000000", # class: 'vg' - to be revised
Name.Variable.Instance: "#000000", # class: 'vi' - to be revised
Number: "#990000", # class: 'm'
Literal: "#000000", # class: 'l'
Literal.Date: "#000000", # class: 'ld'
String: "#4e9a06", # class: 's'
String.Backtick: "#4e9a06", # class: 'sb'
String.Char: "#4e9a06", # class: 'sc'
String.Doc: "italic #8f5902", # class: 'sd' - like a comment
String.Double: "#4e9a06", # class: 's2'
String.Escape: "#4e9a06", # class: 'se'
String.Heredoc: "#4e9a06", # class: 'sh'
String.Interpol: "#4e9a06", # class: 'si'
String.Other: "#4e9a06", # class: 'sx'
String.Regex: "#4e9a06", # class: 'sr'
String.Single: "#4e9a06", # class: 's1'
String.Symbol: "#4e9a06", # class: 'ss'
Generic: "#000000", # class: 'g'
Generic.Deleted: "#a40000", # class: 'gd'
Generic.Emph: "italic #000000", # class: 'ge'
Generic.Error: "#ef2929", # class: 'gr'
Generic.Heading: "bold #000080", # class: 'gh'
Generic.Inserted: "#00A000", # class: 'gi'
Generic.Output: "#888", # class: 'go'
Generic.Prompt: "#745334", # class: 'gp'
Generic.Strong: "bold #000000", # class: 'gs'
Generic.Subheading: "bold #800080", # class: 'gu'
Generic.Traceback: "bold #a40000", # class: 'gt'
}
Loading

0 comments on commit 89b5bd1

Please sign in to comment.