Skip to content

Navigation Menu

Sign in
Sign up

On older versions of Python, skip benchmarks that use features introduced in newer Python versions - #283

Merged
AlexWaygood merged 5 commits into
python:main from
AlexWaygood:new-feature-benchmarks
Apr 27, 2023
Merged

On older versions of Python, skip benchmarks that use features introduced in newer Python versions #283
AlexWaygood merged 5 commits into
python:main from
AlexWaygood:new-feature-benchmarks

Conversation

@AlexWaygood

@AlexWaygood AlexWaygood commented Apr 26, 2023
edited
Loading

Copy link
Copy Markdown
Member

All our benchmarks have a requires-python field in their pyproject.toml files, e.g.:

The requires-python field is added to the metadata of each benchmark as a python field here:

'requires-python': 'python',
for field, target in PEP_621_FIELDS.items():
if target is None:
target = field
if field == 'url':
repo = project.get('urls', {}).get('repository')
raise NotImplementedError
elif not resolved.get(target):
value = project.get(field)
if value is not None:
resolved[target] = value

We can use that metadata to create a new python property on Benchmark objects, which returns a packaging.specifiers.SpecifierSet instance. This property can then be easily used to filter out benchmarks that require a higher version of Python than the version of Python pyperformance is running on.

Fixes #281. Unblocks #280 and #268.

I haven't added a test for this -- I was unsure if it was necessary, and if it was necessary, where that test should go. I'm happy to add one if that would be helpful and there's an obvious place it could go, however!

I manually tested adding a benchmark that used new-in-Python-3.8 features in 1734919, and the CI passed fine (adding the same benchmark to main currently causes the CI to fail — see #280). Passing CI run on my GitHub fork: https://github.com/AlexWaygood/pyperformance/actions/runs/4813903519

@brandtbucher brandtbucher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm impressed how simple this is! Great job.

One opportunity to remove some branching:

AlexWaygood reacted with heart emoji
Comment thread pyperformance/_benchmark.py Outdated
Comment thread pyperformance/cli.py Outdated
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
AlexWaygood merged commit 708265b into python:main Apr 27, 2023
AlexWaygood deleted the new-feature-benchmarks branch April 27, 2023 02:28

Copy link
Copy Markdown
Member

This is a great improvement. Thanks, @AlexWaygood!

AlexWaygood reacted with heart emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@brandtbucher brandtbucher brandtbucher approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Impossible to add a benchmark that exercises newer Python features

AltStyle によって変換されたページ (->オリジナル) /