Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Lint

on: [push, pull_request, workflow_dispatch]

permissions: {}

jobs:
lint:
name: Check code with ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: tox-dev/action-pre-commit-uv@v1
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.11
hooks:
- id: ruff-check
name: Run Ruff (lint)
args: [--exit-non-zero-on-fix]
exclude: ^pyperformance/data-files/

- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.6.0
hooks:
- id: pyproject-fmt
exclude: ^pyperformance/data-files/

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.24.1
hooks:
- id: validate-pyproject
exclude: ^pyperformance/data-files/

2 changes: 1 addition & 1 deletion pyperformance/_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _run_perf_script(python, runscript, runid, *,
'--output', tmp,
]
if pyperf_opts and '--copy-env' in pyperf_opts:
argv, env = _prep_cmd(python, runscript, opts, runid, NOOP)
argv, env = _prep_cmd(python, runscript, opts, runid, lambda name: None)
else:
opts, inherit_envvar = _resolve_restricted_opts(opts)
argv, env = _prep_cmd(python, runscript, opts, runid, inherit_envvar)
Expand Down
1 change: 0 additions & 1 deletion pyperformance/_benchmark_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ def _resolve(project, tool, filename):
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)
Expand Down
4 changes: 1 addition & 3 deletions pyperformance/_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,12 @@ def _parse_metafile(metafile, name):


def _parse_groups_section(lines):
for name in seclines:
for name in lines:
_utils.check_name(name)
yield name


def _parse_group_section(lines):
yielded = False
for line in lines:
if line.startswith('-'):
# Exclude a benchmark or group.
Expand All @@ -363,7 +362,6 @@ def _parse_group_section(lines):
name = line
_benchmark.check_name(name)
yield op, name
yielded = True


def _get_tags(benchmarks):
Expand Down
7 changes: 2 additions & 5 deletions pyperformance/_pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def load_pyproject_toml(filename, *, name=None, tools=None, requirefiles=True):

def _check_relfile(relname, rootdir, kind):
if os.path.isabs(relname):
raise ValuError(f'{relname!r} is absolute, expected relative')
raise ValueError(f'{relname!r} is absolute, expected relative')
actual = os.path.join(rootdir, relname)
if kind == 'dir':
if not os.path.isdir(actual):
Expand All @@ -122,12 +122,9 @@ def _check_file_or_text(table, rootdir, requirefiles, extra=None):

if 'file' in table:
if 'text' in table:
raise ValueError(f'"file" and "text" are mutually exclusive')
raise ValueError('"file" and "text" are mutually exclusive')
kind = 'file' if requirefiles else None
_check_relfile(table['file'], rootdir, kind)
else:
text = table['text']
# XXX Validate it?


def _normalize_project(data, rootdir, name, requirefiles, **_ignored):
Expand Down
1 change: 0 additions & 1 deletion pyperformance/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
'check_dir',
# platform
'MS_WINDOWS',
'run_command',
# misc
'check_name',
'parse_name_pattern',
Expand Down
1 change: 1 addition & 0 deletions pyperformance/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import namedtuple
import hashlib
import json
import os
import sys
import time
import traceback
Expand Down
19 changes: 15 additions & 4 deletions pyperformance/tests/data/bm_local_wheel/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
[project]
name = "pyperformance_bm_local_wheel"
requires-python = ">=3.7"
dependencies = ["pyperf"]
urls = {repository = "https://github.com/python/pyperformance"}
name = "pyperformance-bm-local-wheel"
version = "1.0"

requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = [ "pyperf" ]
urls = { repository = "https://github.com/python/pyperformance" }

[tool.pyperformance]
name = "local_wheel"
6 changes: 3 additions & 3 deletions pyperformance/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ def div():
print()

def expect_success(*args):
text = self.run_pyperformance(
self.run_pyperformance(
*args,
capture=None,
)

def expect_failure(*args):
text = self.run_pyperformance(
self.run_pyperformance(
*args,
capture=None,
exitcode=1,
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_run_and_show(self):
# --debug-single-value: benchmark results don't matter, we only
# check that running benchmarks don't fail.
# XXX Capture and check the output.
text = self.run_pyperformance(
self.run_pyperformance(
'run',
'-b', 'all',
'--debug-single-value',
Expand Down
87 changes: 58 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,51 +38,80 @@
# - git push

[build-system]
requires = ["setuptools >= 61"]
build-backend = "setuptools.build_meta"

requires = [ "setuptools>=61" ]

[project]
name = "pyperformance"
dynamic = ["version"]
license = {text = "MIT"}
description = "Python benchmark suite"
readme = "README.rst"
urls = {Homepage = "https://github.com/python/pyperformance"}
authors= [{name = "Collin Winter"}, {name= "Jeffrey Yasskin"}]
license = { text = "MIT" }
authors = [ { name = "Collin Winter" }, { name = "Jeffrey Yasskin" } ]
requires-python = ">=3.9"
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python',
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]
requires-python = ">=3.9"
dynamic = [ "version" ]
dependencies = [
"pyperf",
"tomli; python_version < '3.11'",
"packaging",
"packaging",
"pyperf",
"tomli; python_version<'3.11'",
]

[project.optional-dependencies]
dev = [
'tox',
'mypy==1.2.0',
'tomli', # Needed even on 3.11+ for typechecking with mypy
optional-dependencies.dev = [
"mypy==1.2",
"tomli", # Needed even on 3.11+ for typechecking with mypy
"tox",
]

[project.scripts]
pyperformance = "pyperformance.cli:main"
urls = { Homepage = "https://github.com/python/pyperformance" }
scripts.pyperformance = "pyperformance.cli:main"

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages]
find = {} # Scanning implicit namespaces is active by default
find = {} # Scanning implicit namespaces is active by default

[tool.setuptools.dynamic]
version = {attr = "pyperformance.__version__"}
version = { attr = "pyperformance.__version__" }

[tool.ruff]
target-version = "py310"

exclude = [
"pyperformance/data-files/",
]

fix = true

lint.select = [
"E", # pycodestyle errors
"F", # pyflakes errors
]
lint.ignore = [
"E402", # module level import not at top of file
"E501", # line too long
"E701", # multiple statements on one line (colon)
"E722", # do not use bare 'except'
"E741", # ambiguous variable name
"F405", # name may be undefined, or defined from star imports
]

[tool.pyproject-fmt]
max_supported_python = "3.14"

[tool.mypy]
python_version = "3.9"
Expand All @@ -94,11 +123,11 @@ warn_redundant_casts = true
warn_unused_ignores = true
warn_unused_configs = true
files = [
'pyperformance/',
'pyperformance/',
]
exclude = [
'pyperformance/data-files/',
'pyperformance/tests/'
'pyperformance/data-files/',
'pyperformance/tests/',
]

[[tool.mypy.overrides]]
Expand Down
Loading