Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
16 changes: 16 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: ruff

on: [push, pull_request, workflow_dispatch]

permissions:
contents: read

jobs:
ruff:
name: Check code with ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: astral-sh/ruff-action@v3
with:
args: "check"
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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/
20 changes: 20 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
target-version = "py310"

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

[lint]
select = [
"E",
"F",
]

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
]
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
2 changes: 1 addition & 1 deletion pyperformance/_benchmark_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _resolve(project, tool, filename):
if target is None:
target = field
if field == 'url':
repo = project.get('urls', {}).get('repository')
_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
6 changes: 3 additions & 3 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,11 +122,11 @@ 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']
_text = table['text']
# XXX Validate it?


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
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(
_text = self.run_pyperformance(
*args,
capture=None,
)

def expect_failure(*args):
text = self.run_pyperformance(
_text = 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(
_text = self.run_pyperformance(
'run',
'-b', 'all',
'--debug-single-value',
Expand Down
Loading