Repository navigation
Release 1.3.0: fix measurement bugs, add stats/async support, trusted publishing - #3
Merged
Merged
Conversation
Fix the bugs that made measurements unreliable and add the features users asked for. Correctness - Support the bare @function_profile decorator (previously TypeError). - Always stop tracemalloc and restore the previous trace hook, so an exception no longer leaves the profiler (and debuggers/coverage) broken for the rest of the process. - Join an existing tracemalloc session instead of stopping it: nested and recursive profiled calls keep the outer peak, and a caller's own tracemalloc session survives. - Return None from the global trace hook for unrelated frames. Line-by- line tracing now costs ~1.2x instead of tracing every line of every frame in the process. - Aggregate recursive line-by-line calls into a single report and keep per-frame timers so recursion is timed correctly. - Build export paths without doubling the extension, create missing directories, and never crash on functions without source. - Escape HTML/Markdown values; emit valid YAML/TOML/XML (quoted keys, proper scalars, legal XML names, XML declaration). - Use the csv module for CSV output; append with a single header and a run timestamp instead of mixing indistinguishable rows. - Validate export_format/log_level at decoration time. - Share one log file per process for shared_log=True. - Sample per-line heap usage instead of reporting the monotonic tracemalloc peak. - Handle empty line-by-line reports without IndexError. Features - profile_block() context manager. - Aggregated stats: get_stats, reset_stats, summary_rows, print_summary, export_summary. - track_memory, sample_every, include_args, include_return_value, max_value_length, append, export_dir, logger, sort_by, top_n. - log_level="silent" and logging.Logger sinks. - Async functions and generators are measured across their real lifetime; async generators warn instead of reporting ~0 s. - Percent column and human-readable units in line reports. - format_duration/format_memory helpers, EXPORT_FORMATS, __version__, py.typed. Packaging and CI - Split the module into core/exporters/stats/_utils. - Require Python 3.8+, add pyproject build metadata and a valid fallback version so pip install . works from a checkout. - Add a test workflow for 3.8-3.13, modernise the publish workflow. - Replace the ad-hoc script with 68 unit tests covering the fixes and the new API. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
- Replace the PYPI_API_TOKEN secret with PyPI trusted publishing (OIDC): the publish job gets id-token: write and declares the `pypi` environment, matching the environment name configured on PyPI. - Split the release into a build job (tests, tag validation, version stamping, sdist/wheel, twine check) and a minimal publish job that only downloads the artifacts and uploads them, so build-time code cannot reach the OIDC token. - Fail fast on non-version tags (e.g. a manual dispatch on a branch) before anything is built or uploaded. - Enable PEP 740 attestations explicitly (on by default with trusted publishing). - Add a concurrency guard and artifact retention. - Bump actions: checkout v7.0.1, setup-python v7.1.0, upload-artifact v7.0.2, download-artifact v8.0.2, gh-action-pypi-publish v1.14.3; build on Python 3.13. - Document the PyPI publisher fields and release steps in the README. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
The PyPI trusted publisher is configured with a blank environment name, so the OIDC token must not carry an environment claim. Remove the `environment:` block from the publish job and document that PyPI and the workflow must agree if an environment is added later. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR is the v1.3.0 update: it fixes the defects that made measurements unreliable, adds the features that were missing (block profiling, aggregated statistics, async/generator support), and moves releases to PyPI trusted publishing.
Bugs fixed (each reproduced before fixing)
@function_profilewithout parenthesesTypeError: decorator() missing 1 required positional argumenttracemallocleft tracing forever; every later measurement wrongfinally, state always restored0.0 MB); caller's owntracemallocsession killedn/ainstead of a fake zerotrack_memory=False)sys.settrace(None)filename="report.json"report.json.json'''blocks, illegal XML names)csvmodule, header once,Timestampcolumnexport_format/log_levellog_level="silent"addedshared_log=Truetracemallocpeak (only ever increases)exec, REPL)OSError: could not get source code???IndexErrorFeatures added
profile_block(...)context manager.get_stats,reset_stats,summary_rows,print_summary,export_summary.track_memory,sample_every,include_args,include_return_value,max_value_length,append,export_dir,logger,sort_by,top_n.log_level="silent"andlogging.Loggersinks.Percentcolumn and human-readable units in line reports.format_duration,format_memory,EXPORT_FORMATS,__version__,py.typed.Behaviour changes
csv/htmlexports now overwrite by default; useappend=Trueto accumulate runs.PercentandTimestampcolumns.Report exported to: ….Migration notes are in the README changelog.
Release engineering
id-token: writeandpypa/gh-action-pypi-publish@v1.14.3; no API token secret.buildandpublishjobs with artifacts, so only the minimal publish job holds an OIDC token.v1.3.0→1.3.0), version stamping insetup.pyandfuncprofiler/__init__.py,twine check --strict.v7.0.1, setup-pythonv7.1.0, upload-artifactv7.0.2, download-artifactv8.0.2, gh-action-pypi-publishv1.14.3.tests.ymlworkflow (Python 3.8 – 3.13 + build check).environment:block.Testing
python -m unittest test -v) — all pass.ruff check --select E,W,Fclean; Python 3.8 syntax verified.py.typed;twine check --strictpasses.v1.3.0→funcprofiler-1.3.0-*.whl,2.0.0-rc1→2.0.0rc1; branch-like tags fail fast.Checklist