Skip to content

Commit

Permalink
STY: Re-format with newer black version
Browse files Browse the repository at this point in the history
  • Loading branch information
sanand0 committed Feb 13, 2024
1 parent cf3ed3c commit 2719e20
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 39 deletions.
1 change: 1 addition & 0 deletions gramex/apps/admin2/gramexadmin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Auth module role settings."""

import gramex
import gramex.handlers
import json
Expand Down
1 change: 1 addition & 0 deletions gramex/apps/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Main UI application'''

import io
import re
import os
Expand Down
1 change: 1 addition & 0 deletions gramex/cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Caching utilities'''

import atexit
import contextlib
import copy
Expand Down
4 changes: 1 addition & 3 deletions gramex/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,7 @@ def setup_secrets(path, max_age_days=1000000, clear=True):
imports = (
list(secrets_import.values())
if isinstance(secrets_import, dict)
else secrets_import
if isinstance(secrets_import, (list, tuple))
else [secrets_import]
else secrets_import if isinstance(secrets_import, (list, tuple)) else [secrets_import]
)
for pattern in imports:
for import_path in path.parent.glob(pattern):
Expand Down
1 change: 1 addition & 0 deletions gramex/data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Query and manipule data from any source.'''

import io
import os
import re
Expand Down
1 change: 1 addition & 0 deletions gramex/debug.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''
Debugging and profiling tools for Gramex
'''

import os
import gc
import sys
Expand Down
1 change: 1 addition & 0 deletions gramex/install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Defines command line services to install, setup and run apps.'''

import contextlib
import io
import os
Expand Down
9 changes: 6 additions & 3 deletions gramex/pptgen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''PPTGen module.'''

import os
import sys
import copy
Expand Down Expand Up @@ -230,9 +231,11 @@ def change_shapes(collection, change, data, handler, **kwargs):
if spec.get('data'):
if not isinstance(spec['data'], (dict,)):
spec['data'] = {
'function': '{}'.format(spec['data'])
if not isinstance(spec['data'], str)
else spec['data']
'function': (
'{}'.format(spec['data'])
if not isinstance(spec['data'], str)
else spec['data']
)
}
shape_data = build_transform(spec['data'], vars={'data': None, 'handler': None})(
data=data, handler=handler
Expand Down
25 changes: 16 additions & 9 deletions gramex/pptgen/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Python-PPTX customized module.'''

import os
import copy
import logging
Expand Down Expand Up @@ -635,9 +636,11 @@ def calendarmap(shape, spec, data):
gradient = matplotlib.cm.get_cmap(spec.get('gradient', 'RdYlGn'))
color = style.get(
'fill',
lambda v: matplotlib.colors.to_hex(gradient((float(v) - lo_data) / range_data))
if not pd.isnull(v)
else default_color,
lambda v: (
matplotlib.colors.to_hex(gradient((float(v) - lo_data) / range_data))
if not pd.isnull(v)
else default_color
),
)

startweekday = (startdate.weekday() - spec.get('weekstart', 0)) % 7
Expand Down Expand Up @@ -674,9 +677,11 @@ def calendarmap(shape, spec, data):
rectstyle = {'fill': fill, 'stroke': stroke(val) if callable(stroke) else stroke}
rect_css(shp, **rectstyle)
text_style = {
'color': style.get('color')(val)
if callable(style.get('color'))
else spec.get('color', _color.contrast(fill)),
'color': (
style.get('color')(val)
if callable(style.get('color'))
else spec.get('color', _color.contrast(fill))
),
'font-size': font_size(val) if callable(font_size) else font_size,
}
for k in ['bold', 'italic', 'underline', 'font-family']:
Expand Down Expand Up @@ -1017,9 +1022,11 @@ def css(shape, spec, data):
if setprop:
if not isinstance(style[prop], (dict,)):
style[prop] = {
'function': '{}'.format(style[prop])
if not isinstance(style[prop], str)
else style[prop]
'function': (
'{}'.format(style[prop])
if not isinstance(style[prop], str)
else style[prop]
)
}
setprop = compile_function(style, prop, data, handler)
setprop = setprop * pxl_to_inch
Expand Down
1 change: 1 addition & 0 deletions gramex/pptgen/fontwidth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module to get fontwidth."""

import os
import json
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions gramex/pptgen/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Utility file.'''

import re
import ast
import copy
Expand Down
14 changes: 6 additions & 8 deletions gramex/pptgen2/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,11 @@ def baseline(run, val, data):
val = (
0.3
if val.startswith('sup')
else -0.25
if val.startswith('sub')
else ST_Percentage._convert_from_percent_literal(val)
else (
-0.25
if val.startswith('sub')
else ST_Percentage._convert_from_percent_literal(val)
)
)
run.font._rPr.set('baseline', ST_Percentage.convert_to_xml(val))

Expand All @@ -409,11 +411,7 @@ def strike(run, val, data):
val = (
'sngStrike'
if val.startswith('s')
else 'dblStrike'
if val.startswith('d')
else 'noStrike'
if val.startswith('n')
else val
else 'dblStrike' if val.startswith('d') else 'noStrike' if val.startswith('n') else val
)
run.font._rPr.set('strike', val)

Expand Down
1 change: 1 addition & 0 deletions gramex/pynode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''
Python Node.js bridge
'''

import os
import re
import json
Expand Down
1 change: 1 addition & 0 deletions gramex/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
... calls [gramex.service.log()][gramex.services.log] as `log({"version": 1})`.
If no such function exists, a warning is raised.
'''

import io
import re
import os
Expand Down
1 change: 1 addition & 0 deletions gramex/services/ttlcache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''
Same as cachetools/ttl.py 3.0.0, but with option to specify an expiry for EACH key.
'''

# Modifications are marked with CHANGE:

from __future__ import absolute_import
Expand Down
1 change: 1 addition & 0 deletions gramex/services/urlcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
See gramex.handlers.BaseHandler for examples on how to use these objects.
'''

# B403:import_public we only pickle Gramex internal objects
import pickle # nosec B403
from diskcache import Cache as DiskCache
Expand Down
4 changes: 1 addition & 3 deletions gramex/topcause.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ def fit(self, X, y, sample_weight=None): # noqa - capital X is a sklearn conven
diff = subseries - submean
vn1 = (diff**2 * sample_weight[subset]).sum() / subn
vn2 = var / n
df = (vn1 + vn2) ** 2 / (
vn1**2 / (subn - 1) + vn2**2 / (n - 1)
)
df = (vn1 + vn2) ** 2 / (vn1**2 / (subn - 1) + vn2**2 / (n - 1))
df = 1 if np.isnan(df) else df
with np.errstate(divide='ignore', invalid='ignore'):
t = gain / (vn1 + vn2) ** 0.5
Expand Down
1 change: 1 addition & 0 deletions gramex/transforms/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Authentication transforms'''

from gramex.config import app_log


Expand Down
8 changes: 5 additions & 3 deletions gramex/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ def transform(_val):
f'\tresult = {expr}\n',
# If the result is a generator object, return it. Else, create a list and
# return that. This ensures that the returned value is always an iterable
'\treturn result if isinstance(result, GeneratorType) else [result,]'
if iter
else '\treturn result',
(
'\treturn result if isinstance(result, GeneratorType) else [result,]'
if iter
else '\treturn result'
),
]

# Compile the function with context variables
Expand Down
1 change: 1 addition & 0 deletions pkg/usage/gramexsize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Saves cyclomatic complexity of Gramex code and corresponding YAML config.'''

import ast
import logging
import mccabe
Expand Down
1 change: 1 addition & 0 deletions pytest/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''
Test utilities to create and drop databases.
'''

import contextlib
import os
import requests
Expand Down
24 changes: 14 additions & 10 deletions testlib/test_pptgen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,19 +1049,23 @@ def test_table(self, slides=9):
eq_(paras[0].alignment, PP_ALIGN.LEFT if i % 2 else PP_ALIGN.RIGHT)
eq_(
cell.vertical_anchor,
MVA.MIDDLE
if column == 'देश'
else (MVA.TOP if i % 2 else MVA.BOTTOM)
if column == 'city'
else None,
(
MVA.MIDDLE
if column == 'देश'
else (MVA.TOP if i % 2 else MVA.BOTTOM) if column == 'city' else None
),
)
eq_(
cell.margin_left,
pptx.util.Inches(0.05)
if column == 'देश'
else pptx.util.Inches(0 if j % 2 else 0.1)
if column == 'city'
else pptx.util.Inches(0.1),
(
pptx.util.Inches(0.05)
if column == 'देश'
else (
pptx.util.Inches(0 if j % 2 else 0.1)
if column == 'city'
else pptx.util.Inches(0.1)
)
),
)
eq_(cell.margin_right, pptx.util.Pt(1))
eq_(cell.margin_top, pptx.util.Inches(0 if j % 2 else 0.1))
Expand Down
1 change: 1 addition & 0 deletions tests/dbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test utilities to create and drop databases.
Used by ../testlib/
'''

import os
import sqlalchemy as sa
from nose.plugins.skip import SkipTest
Expand Down
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Test case utilities'''

import os
import csv
import sys
Expand Down

0 comments on commit 2719e20

Please sign in to comment.