Skip to content

Commit

Permalink
Merge pull request #237 from joerick/precommit-update
Browse files Browse the repository at this point in the history
Update precommit and fix issues
  • Loading branch information
joerick committed Apr 24, 2023
2 parents 21f3fb8 + bd4f6e7 commit 24b0bd4
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ on:

pull_request:
branches: [ main ]
# only run on pull requests that change a C file or build system
paths:
- '**.c'
- setup.py
- setup.cfg
- pyproject.toml

jobs:
build_wheels:
Expand Down
37 changes: 25 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/pycqa/isort
rev: 5.8.0
rev: 5.12.0
hooks:
- id: isort
name: isort (python)

- repo: https://github.com/psf/black
rev: 22.6.0
rev: 23.3.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.2.4
hooks:
- id: codespell
exclude: "\\.(json)$"
args:
- --ignore-words-list=vas

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.304
hooks:
- id: pyright
additional_dependencies:
- pytest
- ipython
- django
- flask
- trio
- flaky
- numpy
- nox
- ascii_graph
- requests
- greenlet
- types-click
- types-requests


- repo: local
hooks:
- id: pyright
name: pyright
entry: pyright --venv-path .
language: node
pass_filenames: false
types: [python]
additional_dependencies: ['pyright@1.1.260']
- id: build
name: build js bundle
entry: bin/build_js_bundle.py --force
Expand All @@ -44,7 +57,7 @@ repos:
pass_filenames: false

- repo: https://github.com/asottile/pyupgrade
rev: v2.37.1
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py37-plus]
Expand Down
2 changes: 1 addition & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Renderers transform a tree of {class}`Frame` objects into some form of output.
Rendering has two steps:

1. First, the renderer will 'preprocess' the Frame tree, applying each processor in the ``processor`` property, in turn.
2. The resulting tree is renderered into the desired format.
2. The resulting tree is rendered into the desired format.

Therefore, rendering can be customised by changing the ``processors`` property. For example, you can disable time-aggregation (making the profile into a timeline) by removing {func}`aggregate_repeated_calls`.

Expand Down
4 changes: 3 additions & 1 deletion examples/async_experiment_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ async def say(what, when, profile=False):
if profile:
p = pyinstrument.Profiler()
p.start()
else:
p = None

busy_wait(0.1)
sleep_start = time.time()
Expand All @@ -27,7 +29,7 @@ async def say(what, when, profile=False):
busy_wait(0.1)

print(what)
if profile:
if p:
p.stop()
p.print(show_all=True)

Expand Down
4 changes: 3 additions & 1 deletion examples/async_experiment_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ async def say(what, when, profile=False):
if profile:
p = pyinstrument.Profiler()
p.start()
else:
p = None

busy_wait(0.1)
sleep_start = time.time()
Expand All @@ -29,7 +31,7 @@ async def say(what, when, profile=False):
busy_wait(0.1)

print(what)
if profile:
if p:
p.stop()
p.print(show_all=True)

Expand Down
2 changes: 1 addition & 1 deletion examples/wikipedia_article_word_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
from urllib2 import urlopen # type: ignore

import collections
import operator
Expand Down
2 changes: 1 addition & 1 deletion metrics/overflow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pyinstrument import Profiler

p = Profiler(use_signal=False)
p = Profiler()

p.start()

Expand Down
4 changes: 2 additions & 2 deletions pyinstrument/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def guess_renderer_from_outfile(outfile: str) -> str | None:


def report_dir() -> str:
data_dir: str = appdirs.user_data_dir("pyinstrument", "com.github.joerick") # type: ignore
data_dir = appdirs.user_data_dir("pyinstrument", "com.github.joerick") # type: ignore
report_dir = os.path.join(data_dir, "reports")
if not os.path.exists(report_dir):
os.makedirs(report_dir)
Expand Down Expand Up @@ -549,7 +549,7 @@ class CommandLineOptions:

unicode: bool | None
color: bool | None
renderer: str
renderer: str | None
timeline: bool
interval: float

Expand Down
1 change: 0 additions & 1 deletion pyinstrument/magic/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def __init__(self, pre: str | ast.Module, post: str | ast.Module):
self.active = True

def reset(self):

self.core = parse(
dedent(
"""
Expand Down
3 changes: 1 addition & 2 deletions pyinstrument/renderers/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def render_preamble(self, session: Session):
)
lines[2] += f" Duration: {session.duration:<9.3f}"
lines[1] += f" Samples: {session.sample_count}"
if session.cpu_time is not None:
lines[2] += f" CPU time: {session.cpu_time:.3f}"
lines[2] += f" CPU time: {session.cpu_time:.3f}"

lines.append("")
lines.append("Program: %s" % session.program)
Expand Down
5 changes: 1 addition & 4 deletions pyinstrument/renderers/jsonrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ def render(self, session: Session):
property_decls.append('"duration": %f' % session.duration)
property_decls.append('"sample_count": %d' % session.sample_count)
property_decls.append('"program": %s' % encode_str(session.program))
if session.cpu_time is None:
property_decls.append('"cpu_time": null')
else:
property_decls.append('"cpu_time": %f' % session.cpu_time)
property_decls.append('"cpu_time": %f' % session.cpu_time)
property_decls.append('"root_frame": %s' % self.render_frame(frame))

return "{%s}\n" % ",".join(property_decls)
Expand Down
4 changes: 2 additions & 2 deletions pyinstrument/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def from_json(json_dict: dict[str, Any]):
sample_count=json_dict["sample_count"],
start_call_stack=json_dict["start_call_stack"],
program=json_dict["program"],
cpu_time=json_dict["cpu_time"],
cpu_time=json_dict["cpu_time"] or 0,
)

@staticmethod
Expand Down Expand Up @@ -114,7 +114,7 @@ def combine(session1: Session, session2: Session) -> Session:
def root_frame(self, trim_stem: bool = True) -> Frame | None:
"""
Parses the internal frame records and returns a tree of :class:`Frame`
objects. This object can be renderered using a :class:`Renderer`
objects. This object can be rendered using a :class:`Renderer`
object.
:rtype: A :class:`Frame` object, or None if the session is empty.
Expand Down
2 changes: 1 addition & 1 deletion pyinstrument/vendor/appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@



def user_data_dir(appname=None, appauthor=None, version=None, roaming=False):
def user_data_dir(appname=None, appauthor=None, version=None, roaming=False) -> str:
r"""Return full path to the user-specific data dir for this application.
"appname" is the name of application.
Expand Down
2 changes: 1 addition & 1 deletion test/test_ipython_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def function_e():

@pytest.mark.ipythonmagic
def test_magics(ip):
from IPython.utils.io import capture_output as capture_ipython_output
from IPython.utils.capture import capture_output as capture_ipython_output

with fake_time():
with capture_ipython_output() as captured:
Expand Down
4 changes: 2 additions & 2 deletions test/test_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_speedscope_output():
}
assert len(speedscope_frame_list) == len(distinct_functions_called)
speedscope_frame_fields = tuple(field.name for field in dataclasses.fields(SpeedscopeFrame))
for (function_name, frame_index) in distinct_functions_called.items():
for function_name, frame_index in distinct_functions_called.items():
for frame_field in speedscope_frame_fields:
assert frame_field in speedscope_frame_list[frame_index]
assert speedscope_frame_list[frame_index]["name"] == function_name
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_speedscope_output():
speedscope_event_list = speedscope_profile["events"]
assert len(speedscope_event_list) == len(output_event_tuple)
speedscope_event_fields = tuple(field.name for field in dataclasses.fields(SpeedscopeEvent))
for (event_index, speedscope_event) in enumerate(speedscope_event_list):
for event_index, speedscope_event in enumerate(speedscope_event_list):
for event_field in speedscope_event_fields:
assert event_field in speedscope_event

Expand Down

0 comments on commit 24b0bd4

Please sign in to comment.