Skip to content

Lint Doc/ with Ruff #111192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.2
hooks:
- id: ruff
name: Run Ruff on Doc/
args: [--exit-non-zero-on-fix]
files: ^Doc/
- id: ruff
name: Run Ruff on Lib/test/
args: [--exit-non-zero-on-fix]
Expand Down
6 changes: 6 additions & 0 deletions Doc/.ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fix = true
extend-exclude = [
# Incomplete/unparseable example files
"includes/email-mime.py",
"includes/email-simple.py",
]
8 changes: 5 additions & 3 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# The contents of this file are pickled, so don't put values in the namespace
# that aren't pickleable (module imports are okay, they're removed automatically).

import sys, os, time
import os
import sys
import time
sys.path.append(os.path.abspath('tools/extensions'))
sys.path.append(os.path.abspath('includes'))

Expand All @@ -26,7 +28,7 @@

# Skip if downstream redistributors haven't installed it
try:
import sphinxext.opengraph
import sphinxext.opengraph # noqa: F401
except ImportError:
pass
else:
Expand All @@ -53,7 +55,7 @@

# We look for the Include/patchlevel.h file in the current Python source tree
# and replace the values accordingly.
import patchlevel
import patchlevel # noqa: E402
version, release = patchlevel.get_version_info()

# There are two options for replacing |today|: either, you set today to some
Expand Down
5 changes: 4 additions & 1 deletion Doc/includes/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

"""

import sys, os, difflib, argparse
import argparse
import difflib
import os
import sys
from datetime import datetime, timezone

def file_mtime(path):
Expand Down
9 changes: 6 additions & 3 deletions Doc/includes/ndiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

__version__ = 1, 7, 0

import difflib, sys
import difflib
import sys

def fail(msg):
out = sys.stderr.write
Expand All @@ -58,8 +59,10 @@ def fcompare(f1name, f2name):
if not f1 or not f2:
return 0

a = f1.readlines(); f1.close()
b = f2.readlines(); f2.close()
a = f1.readlines()
b = f2.readlines()
f1.close()
f2.close()
for line in difflib.ndiff(a, b):
print(line, end=' ')

Expand Down
3 changes: 2 additions & 1 deletion Doc/includes/newtypes/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,6 @@
"""

if __name__ == "__main__":
import doctest, __main__
import doctest
import __main__
doctest.testmod(__main__)
8 changes: 4 additions & 4 deletions Doc/includes/tzinfo_examples.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from datetime import tzinfo, timedelta, datetime

ZERO = timedelta(0)
HOUR = timedelta(hours=1)
SECOND = timedelta(seconds=1)

# A class capturing the platform's idea of local time.
# (May result in wrong values on historical times in
# timezones where UTC offset and/or the DST rules had
# changed in the past.)
import time as _time

ZERO = timedelta(0)
HOUR = timedelta(hours=1)
SECOND = timedelta(seconds=1)

STDOFFSET = timedelta(seconds = -_time.timezone)
if _time.daylight:
DSTOFFSET = timedelta(seconds = -_time.altzone)
Expand Down
11 changes: 6 additions & 5 deletions Doc/tools/extensions/asdl_highlight.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import sys
from pathlib import Path

CPYTHON_ROOT = Path(__file__).resolve().parent.parent.parent.parent
sys.path.append(str(CPYTHON_ROOT / "Parser"))

from pygments.lexer import RegexLexer, bygroups, include, words
from pygments.token import (Comment, Keyword, Name, Operator,
Punctuation, Text)

from asdl import builtin_types
from sphinx.highlighting import lexers

CPYTHON_ROOT = Path(__file__).resolve().parent.parent.parent.parent
sys.path.append(str(CPYTHON_ROOT / "Parser"))

from asdl import builtin_types # noqa: E402


class ASDLLexer(RegexLexer):
name = "ASDL"
aliases = ["asdl"]
Expand Down
2 changes: 0 additions & 2 deletions Doc/tools/extensions/c_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
'var': 'data',
'type': 'type',
'macro': 'macro',
'type': 'type',
'member': 'member',
}

Expand Down Expand Up @@ -93,7 +92,6 @@ def __init__(self, refcount_filename, stable_abi_file):
self.stable_abi_data = {}
with open(stable_abi_file, 'r') as fp:
for record in csv.DictReader(fp):
role = record['role']
name = record['name']
self.stable_abi_data[name] = record

Expand Down
2 changes: 1 addition & 1 deletion Doc/tools/extensions/pyspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from docutils import nodes, utils
from docutils.io import StringOutput
from docutils.parsers.rst import Directive
from docutils.parsers.rst.states import Body
from docutils.utils import new_document
from sphinx import addnodes
from sphinx.builders import Builder
Expand All @@ -42,7 +43,6 @@
SOURCE_URI = 'https://github.com/python/cpython/tree/main/%s'

# monkey-patch reST parser to disable alphabetic and roman enumerated lists
from docutils.parsers.rst.states import Body
Body.enum.converters['loweralpha'] = \
Body.enum.converters['upperalpha'] = \
Body.enum.converters['lowerroman'] = \
Expand Down