Skip to content

Commit 2c39423

Browse files
committed
Apply black.
1 parent bad7763 commit 2c39423

34 files changed

Lines changed: 1811 additions & 1299 deletions

.cookiecutterrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ default_context:
2727
linter: flake8
2828
package_name: hunter
2929
pre_commit: 'yes'
30-
pre_commit_formatter: black
30+
pre_commit_formatter: blue
3131
project_name: Hunter
3232
project_short_description: Hunter is a flexible code tracing toolkit, not for measuring coverage, but for debugging, logging, inspection and other nefarious purposes. It has a simple Python API and a convenient terminal API (see `Environment variable activation <env-var-activation_>`_).
3333
pypi_badge: 'yes'

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,29 @@ repos:
1212
rev: v4.3.0
1313
hooks:
1414
- id: trailing-whitespace
15+
exclude_types:
16+
- c
1517
- id: end-of-file-fixer
18+
exclude_types:
19+
- c
1620
- id: double-quote-string-fixer
1721
exclude: '^tests/'
1822
- id: mixed-line-ending
1923
args: [--fix=lf]
24+
- id: debug-statements
25+
exclude: '^tests/sample*|src/hunter/actions.py'
2026
- repo: https://github.com/timothycrosley/isort
2127
rev: 5.10.1
2228
hooks:
2329
- id: isort
2430
types: [python]
2531
- id: isort
2632
types: [cython]
33+
- repo: https://github.com/psf/black
34+
rev: 22.8.0
35+
hooks:
36+
- id: black
37+
types: [python]
2738
- repo: https://gitlab.com/pycqa/flake8
2839
rev: 3.9.2
2940
hooks:

ci/bootstrap.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ def main():
6969
# This uses sys.executable the same way that the call in
7070
# cookiecutter-pylibrary/hooks/post_gen_project.py
7171
# invokes this bootstrap.py itself.
72-
for line in subprocess.check_output([sys.executable, '-m', 'tox', '--listenvs'], universal_newlines=True).splitlines()
72+
for line in subprocess.check_output(
73+
[sys.executable, '-m', 'tox', '--listenvs'],
74+
universal_newlines=True,
75+
).splitlines()
7376
]
7477
tox_environments = [line for line in tox_environments if line.startswith('py')]
7578

docs/conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
copyright = '{0}, {1}'.format(year, author)
2929
try:
3030
from pkg_resources import get_distribution
31+
3132
version = release = get_distribution('hunter').version
3233
except Exception:
3334
traceback.print_exc()
@@ -41,9 +42,7 @@
4142
}
4243
html_theme = 'sphinx_py3doc_enhanced_theme'
4344
html_theme_path = [sphinx_py3doc_enhanced_theme.get_html_theme_path()]
44-
html_theme_options = {
45-
'githuburl': 'https://github.com/ionelmc/python-hunter/'
46-
}
45+
html_theme_options = {'githuburl': 'https://github.com/ionelmc/python-hunter/'}
4746

4847
html_use_smartypants = True
4948
html_last_updated_fmt = '%b %d, %Y'

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ requires = [
55
"setuptools_scm>=3.3.1,!=4.0.0",
66
]
77

8+
[tool.black]
9+
line-length = 140
10+
target-version = ['py37']
11+
skip-string-normalization = true
12+
813
[tool.ipdb]
914

1015
[tool.tbump]

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[flake8]
22
max-line-length = 140
33
exclude = .tox,.eggs,ci/templates,build,dist,tests,src/hunter/vendor
4+
ignore = E203,W503
45

56
[tool:isort]
67
force_single_line = True

setup.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
def read(*names, **kwargs):
3737
with io.open(
3838
join(dirname(__file__), *names),
39-
encoding=kwargs.get('encoding', 'utf8')
39+
encoding=kwargs.get('encoding', 'utf8'),
4040
) as fh:
4141
return fh.read()
4242

@@ -79,6 +79,7 @@ def run(self):
7979

8080
class OptionalBuildExt(build_ext):
8181
"""Allow the building of C extensions to fail."""
82+
8283
def run(self):
8384
try:
8485
if os.environ.get('SETUPPY_FORCE_PURE'):
@@ -90,12 +91,14 @@ def run(self):
9091

9192
def _unavailable(self, e):
9293
print('*' * 80)
93-
print('''WARNING:
94+
print(
95+
"""WARNING:
9496
9597
An optional code optimization (C extension) could not be compiled.
9698
9799
Optimizations for this package will not be available!
98-
''')
100+
"""
101+
)
99102

100103
print('CAUSE:')
101104
print('')
@@ -105,6 +108,7 @@ def _unavailable(self, e):
105108

106109
class BinaryDistribution(Distribution):
107110
"""Distribution which almost always forces a binary package with platform name"""
111+
108112
def has_ext_modules(self):
109113
return super().has_ext_modules() or not os.environ.get('SETUPPY_ALLOW_PURE')
110114

@@ -118,9 +122,10 @@ def has_ext_modules(self):
118122
},
119123
license='BSD-2-Clause',
120124
description='Hunter is a flexible code tracing toolkit.',
121-
long_description='%s\n%s' % (
125+
long_description='%s\n%s'
126+
% (
122127
re.compile('^.. start-badges.*^.. end-badges', re.M | re.S).sub('', read('README.rst')),
123-
re.sub(':[a-z]+:`~?(.*?)`', r'``\1``', read('CHANGELOG.rst'))
128+
re.sub(':[a-z]+:`~?(.*?)`', r'``\1``', read('CHANGELOG.rst')),
124129
),
125130
author='Ionel Cristian Mărieș',
126131
author_email='contact@ionelmc.ro',
@@ -155,18 +160,25 @@ def has_ext_modules(self):
155160
'Issue Tracker': 'https://github.com/ionelmc/python-hunter/issues',
156161
},
157162
keywords=[
158-
'trace', 'tracer', 'settrace', 'debugger', 'debugging', 'code', 'source'
163+
'trace',
164+
'tracer',
165+
'settrace',
166+
'debugger',
167+
'debugging',
168+
'code',
169+
'source',
159170
],
160171
python_requires='>=3.7',
161-
install_requires=[
162-
],
172+
install_requires=[],
163173
extras_require={
164174
':platform_system != "Windows"': ['manhole >= 1.5'],
165175
},
166176
setup_requires=[
167177
'setuptools_scm>=3.3.1,!=4.0.0',
168178
'cython',
169-
] if Cython else [
179+
]
180+
if Cython
181+
else [
170182
'setuptools_scm>=3.3.1,!=4.0.0',
171183
],
172184
entry_points={
@@ -181,12 +193,14 @@ def has_ext_modules(self):
181193
'develop': DevelopWithPTH,
182194
'build_ext': OptionalBuildExt,
183195
},
184-
ext_modules=[] if hasattr(sys, 'pypy_version_info') else [
196+
ext_modules=[]
197+
if hasattr(sys, 'pypy_version_info')
198+
else [
185199
Extension(
186200
splitext(relpath(path, 'src').replace(os.sep, '.'))[0],
187201
sources=[path],
188202
extra_compile_args=os.environ.get('SETUPPY_CFLAGS', '').split(),
189-
include_dirs=[dirname(path)]
203+
include_dirs=[dirname(path)],
190204
)
191205
for root, _, _ in os.walk('src')
192206
for path in glob(join(root, '*.pyx' if Cython else '*.c'))

src/hunter/__init__.py

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,19 @@
6464
'VarsPrinter',
6565
'VarsSnooper',
6666
'When',
67-
6867
'stop',
6968
'trace',
7069
)
7170
THREADING_SUPPORT_ALIASES = (
72-
'threading_support', 'threads_support', 'thread_support',
73-
'threadingsupport', 'threadssupport', 'threadsupport',
74-
'threading', 'threads', 'thread',
71+
'threading_support',
72+
'threads_support',
73+
'thread_support',
74+
'threadingsupport',
75+
'threadssupport',
76+
'threadsupport',
77+
'threading',
78+
'threads',
79+
'thread',
7580
)
7681
TRACER_OPTION_NAMES = THREADING_SUPPORT_ALIASES + (
7782
'clear_env_var',
@@ -86,25 +91,28 @@
8691
def _embed_via_environment():
8792
if 'PYTHONHUNTER' in os.environ:
8893
try:
89-
eval('trace({[PYTHONHUNTER]})'.format(os.environ), {
90-
'And': And,
91-
'Backlog': Backlog,
92-
'CallPrinter': CallPrinter,
93-
'CodePrinter': CodePrinter,
94-
'Debugger': Debugger,
95-
'ErrorSnooper': ErrorSnooper,
96-
'From': From,
97-
'Manhole': Manhole,
98-
'Not': Not,
99-
'Or': Or,
100-
'Q': Q,
101-
'Query': Query,
102-
'StackPrinter': StackPrinter,
103-
'VarsPrinter': VarsPrinter,
104-
'VarsSnooper': VarsSnooper,
105-
'When': When,
106-
'trace': trace,
107-
})
94+
eval(
95+
'trace({[PYTHONHUNTER]})'.format(os.environ),
96+
{
97+
'And': And,
98+
'Backlog': Backlog,
99+
'CallPrinter': CallPrinter,
100+
'CodePrinter': CodePrinter,
101+
'Debugger': Debugger,
102+
'ErrorSnooper': ErrorSnooper,
103+
'From': From,
104+
'Manhole': Manhole,
105+
'Not': Not,
106+
'Or': Or,
107+
'Q': Q,
108+
'Query': Query,
109+
'StackPrinter': StackPrinter,
110+
'VarsPrinter': VarsPrinter,
111+
'VarsSnooper': VarsSnooper,
112+
'When': When,
113+
'trace': trace,
114+
},
115+
)
108116
except Exception as exc:
109117
sys.stderr.write('Failed to load hunter from PYTHONHUNTER environ variable {[PYTHONHUNTER]!r}: {!r}\n'.format(os.environ, exc))
110118

@@ -142,14 +150,12 @@ def _prepare_config(*args, **kwargs):
142150
continue
143151

144152
_default_config.pop(key)
145-
sys.stderr.write('Discarded config from PYTHONHUNTERCONFIG {}={!r}: Unknown option\n'.format(
146-
key, value))
153+
sys.stderr.write('Discarded config from PYTHONHUNTERCONFIG {}={!r}: Unknown option\n'.format(key, value))
147154
for position, predicate in enumerate(args):
148155
if callable(predicate):
149156
predicates.append(predicate)
150157
else:
151-
sys.stderr.write('Discarded config from PYTHONHUNTERCONFIG {} (position {}): Not a callable\n'.format(
152-
predicate, position))
158+
sys.stderr.write('Discarded config from PYTHONHUNTERCONFIG {} (position {}): Not a callable\n'.format(predicate, position))
153159

154160
return predicates, options
155161

@@ -176,17 +182,14 @@ def Q(*predicates, **query):
176182
raise TypeError('Action {0!r} is not callable.'.format(a))
177183

178184
if predicates:
179-
predicates = tuple(
180-
p() if inspect.isclass(p) and issubclass(p, Action) else p
181-
for p in predicates
182-
)
185+
predicates = tuple(p() if inspect.isclass(p) and issubclass(p, Action) else p for p in predicates)
183186
if any(isinstance(p, (CallPrinter, CodePrinter)) for p in predicates):
184187
# the user provided an action as a filter, remove the action then to prevent double output
185188
for action in optional_actions:
186189
if action in (CallPrinter, CodePrinter) or isinstance(action, (CallPrinter, CodePrinter)):
187190
optional_actions.remove(action)
188191
if query:
189-
predicates += Query(**query),
192+
predicates += (Query(**query),)
190193

191194
result = And(*predicates)
192195
else:
@@ -201,7 +204,7 @@ def Q(*predicates, **query):
201204
def _merge(*predicates, **query):
202205
if predicates:
203206
if query:
204-
predicates += Query(**query),
207+
predicates += (Query(**query),)
205208
return And(*predicates)
206209
else:
207210
return Query(**query)
@@ -240,7 +243,7 @@ def And(*predicates, **kwargs):
240243
:class:`hunter.predicates.And`
241244
"""
242245
if kwargs:
243-
predicates += Query(**kwargs),
246+
predicates += (Query(**kwargs),)
244247
return _flatten(_And, *predicates)
245248

246249

@@ -278,7 +281,7 @@ def Not(*predicates, **kwargs):
278281
:class:`hunter.predicates.Not`
279282
"""
280283
if kwargs:
281-
predicates += Query(**kwargs),
284+
predicates += (Query(**kwargs),)
282285
if len(predicates) > 1:
283286
return _Not(_flatten(_And, *predicates))
284287
else:
@@ -310,8 +313,7 @@ def From(condition=None, predicate=None, watermark=0, **kwargs):
310313
return _From(Q(**condition_kwargs), Q(**predicate_kwargs), watermark)
311314
else:
312315
if kwargs:
313-
raise TypeError("Unexpected arguments {}. Don't combine positional with keyword arguments.".format(
314-
kwargs.keys()))
316+
raise TypeError("Unexpected arguments {}. Don't combine positional with keyword arguments.".format(kwargs.keys()))
315317
return _From(condition, predicate, watermark)
316318

317319

@@ -343,9 +345,18 @@ def Backlog(*conditions, **kwargs):
343345
strip = kwargs.pop('strip', True)
344346
vars = kwargs.pop('vars', False)
345347
if not conditions and not kwargs:
346-
raise TypeError('Backlog needs at least 1 condition '
347-
"(it doesn't have any effect without one besides making everything incredibly slow).")
348-
return _Backlog(_merge(*conditions, **kwargs), size=size, stack=stack, vars=vars, strip=strip, action=action, filter=filter)
348+
raise TypeError(
349+
'Backlog needs at least 1 condition ' "(it doesn't have any effect without one besides making everything incredibly slow)."
350+
)
351+
return _Backlog(
352+
_merge(*conditions, **kwargs),
353+
size=size,
354+
stack=stack,
355+
vars=vars,
356+
strip=strip,
357+
action=action,
358+
filter=filter,
359+
)
349360

350361

351362
def stop():
@@ -467,11 +478,13 @@ def tracing_wrapper(*args, **kwargs):
467478
predicates.append(
468479
From(
469480
Query(kind='call'),
470-
Not(When(
471-
Query(calls_gt=0, depth=0) & Not(Query(kind='return')),
472-
Stop
473-
)),
474-
watermark=-1
481+
Not(
482+
When(
483+
Query(calls_gt=0, depth=0) & Not(Query(kind='return')),
484+
Stop,
485+
)
486+
),
487+
watermark=-1,
475488
)
476489
)
477490
local_tracer = trace(*predicates, **trace_options)
@@ -496,8 +509,7 @@ def load_config(*args, **kwargs):
496509
else:
497510
_default_trace_args = eval('_prepare_config({})'.format(os.environ.get('PYTHONHUNTERCONFIG', '')))
498511
except Exception as exc:
499-
sys.stderr.write('Failed to load hunter config from PYTHONHUNTERCONFIG {[PYTHONHUNTERCONFIG]!r}: {!r}\n'.format(
500-
os.environ, exc))
512+
sys.stderr.write('Failed to load hunter config from PYTHONHUNTERCONFIG {[PYTHONHUNTERCONFIG]!r}: {!r}\n'.format(os.environ, exc))
501513
_default_trace_args = (), ()
502514

503515

0 commit comments

Comments
 (0)