Skip to content

Commit b79d4f9

Browse files
committed
lint python scripts in dev-tools
These scripts are important, but have zero static analysis, type-checking, or formatting. Add simple make-based build with CI hook for this. Format check is not yet enabled, we should "make reformat" and commit the changes separately. Any failing violations are disabled, we can iteratively enable them.
1 parent 90eaf14 commit b79d4f9

File tree

5 files changed

+157
-2
lines changed

5 files changed

+157
-2
lines changed

.github/actions/prepare-for-build/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# for java, gradle, caches, etc.
33

44
name: Prepare Lucene build
5+
description: Creates a shared setup for other workflows
56

67
inputs:
78
java-version:
89
required: false
9-
default: 23
10+
default: "23"
1011
description: "The default JDK version to set up."
1112

1213
java-distribution:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "Run checks: dev-tools/scripts (python)"
2+
3+
on:
4+
workflow_dispatch:
5+
6+
pull_request:
7+
branches:
8+
- 'main'
9+
- 'branch_10x'
10+
paths:
11+
- '.github/workflows/run-checks-python.yml'
12+
- 'dev-tools/scripts/**'
13+
14+
push:
15+
branches:
16+
- 'main'
17+
- 'branch_10x'
18+
paths:
19+
- '.github/workflows/run-checks-python.yml'
20+
- 'dev-tools/scripts/**'
21+
22+
jobs:
23+
lint:
24+
timeout-minutes: 15
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Setup Python
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version: "3.12.6"
34+
35+
- name: Lint Python
36+
run: "cd dev-tools/scripts && make"

dev-tools/scripts/Makefile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# basic make safety: if error happens, delete output
2+
.DELETE_ON_ERROR:
3+
4+
# explicitly declare shell used
5+
SHELL := /bin/bash
6+
7+
# enforce that shell is picky
8+
.SHELLFLAGS := -norc -euo pipefail -c
9+
10+
# don't litter up repo with bytecode
11+
export PYTHONDONTWRITEBYTECODE=true
12+
13+
# don't self-check, don't ask questions
14+
PIP_INSTALL_ARGS=--disable-pip-version-check --no-input --upgrade
15+
16+
# venv with dependencies in the standard location
17+
VENV=${PWD}/.venv
18+
19+
# don't behave strangely if these files exist
20+
.PHONY: lint format reformat ruff pyright env clean
21+
22+
# list of directories we check
23+
SOURCES=$(wildcard *.py)
24+
25+
# check formatting, linting, and types
26+
# TODO: enable this when we're ready to reformat all code
27+
# lint: format ruff pyright
28+
lint: ruff pyright
29+
30+
# check all formatting
31+
format: env
32+
# validate imports: if this fails, please run "make reformat" and commit changes.
33+
$(VENV)/bin/ruff check --select I $(SOURCES)
34+
# validate formatting: if this fails, please run "make reformat" and commit changes.
35+
$(VENV)/bin/ruff format --diff $(SOURCES)
36+
37+
# reformat code to conventions
38+
reformat: env
39+
# organize imports
40+
$(VENV)/bin/ruff check --select I --fix $(SOURCES)
41+
# reformat sources
42+
$(VENV)/bin/ruff format $(SOURCES)
43+
44+
# lints sources
45+
ruff: env
46+
# validate sources with ruff linter
47+
$(VENV)/bin/ruff check $(SOURCES)
48+
49+
# checks types
50+
pyright: env
51+
# type-check sources with basedpyright
52+
$(VENV)/bin/basedpyright $(SOURCES)
53+
54+
# rebuild venv if dependencies change
55+
env: $(VENV)/bin/activate
56+
$(VENV)/bin/activate: requirements.txt
57+
# remove any existing venv
58+
rm -rf $(VENV)
59+
# create new venv
60+
python3 -m venv $(VENV)
61+
# install dependencies into venv
62+
$(VENV)/bin/pip install $(PIP_INSTALL_ARGS) -r requirements.txt
63+
# adjust timestamp for safety
64+
touch $(VENV)/bin/activate
65+
66+
# nuke venv
67+
clean:
68+
rm -rf $(VENV)

dev-tools/scripts/pyproject.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[tool.pyright]
2+
venvPath = "."
3+
venv = ".venv"
4+
# TODO: improve!
5+
# typeCheckingMode = "strict"
6+
typeCheckingMode = "basic"
7+
# TODO: we should fix these
8+
reportArgumentType = "none"
9+
reportAttributeAccessIssue = "none"
10+
reportCallIssue = "none"
11+
reportInvalidStringEscapeSequence = "none"
12+
reportOperatorIssue = "none"
13+
reportOptionalIterable = "none"
14+
reportOptionalMemberAccess = "none"
15+
reportOptionalSubscript = "none"
16+
reportUndefinedVariable = "none"
17+
18+
[tool.ruff]
19+
line-length = 200
20+
indent-width = 2
21+
22+
[tool.ruff.lint]
23+
# TODO: improve!
24+
# select = ["ALL"]
25+
26+
# disabling/enabling of rules
27+
ignore = [
28+
# we should fix these
29+
"E401", # multiple imports on one line
30+
"E701", # multiple statements on one line
31+
"E711", # comparison should be "is not None"
32+
"E703", # unnecessary semicolon
33+
"E713", # test for membership should be "not in"
34+
"E714", # test for object identity should be "is not"
35+
"E722", # do not use bare except
36+
"E741", # ambiguous variable name
37+
"F401", # unused import
38+
"F403", # unable to detect undefined names due to star imports
39+
"F405", # undefined name or defined from star imports
40+
"F811", # redefinition of unused
41+
"F821", # undefined name
42+
"F841", # local variable assigned but never used
43+
44+
# These rules are always disabled: conflict with the formatter
45+
# don't enable! https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
46+
"W191", "E111", "E114", "E117", "D206", "D300", "Q000", "Q001",
47+
"Q002", "Q003", "COM812", "COM819", "ISC001", "ISC002", "E501",
48+
]

dev-tools/scripts/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ holidays~=0.16
55
ics~=0.7.2
66
console-menu~=0.7.1
77
PyGithub~=1.56
8-
jira~=3.4.1
8+
jira~=3.4.1
9+
basedpyright~=1.28.1
10+
ruff~=0.9.9

0 commit comments

Comments
 (0)