Skip to content

Commit e1afaa7

Browse files
committed
Fix pyflake warnings and make it mandatory
1 parent 121ee8d commit e1afaa7

16 files changed

Lines changed: 50 additions & 67 deletions

File tree

.github/workflows/lint-pyflakes.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
name: Lint (pyflakes)
22

3-
# Informational only: runs pyflakes over the Python sources and prints the
4-
# findings, but never fails the build. The codebase has known pre-existing
5-
# findings, plus false positives from intentional __init__.py re-exports and
6-
# `from rcdb.model import *`. Use this report to spot newly introduced unused
7-
# imports / undefined names in a pull request diff.
3+
# Mandatory gate: runs pyflakes over the Python sources and FAILS the build on
4+
# any finding (unused imports, undefined names, dead locals, format bugs, ...).
5+
# The codebase is pyflakes-clean; intentional re-exports use explicit imports
6+
# plus `__all__`, so there are no false positives to suppress.
87

98
on:
109
push:
@@ -31,10 +30,7 @@ jobs:
3130
python -m pip install --upgrade pip
3231
pip install "$GITHUB_WORKSPACE/python[dev]"
3332
34-
- name: Run pyflakes (informational, never fails)
33+
- name: Run pyflakes (fails on any finding)
34+
working-directory: python
3535
run: |
36-
# This is a report, not a gate: always exit 0.
37-
pyflakes python/rcdb python/daq > pyflakes.txt 2>&1 || true
38-
cat pyflakes.txt
39-
echo "--------------------------------------------------"
40-
echo "pyflakes findings: $(wc -l < pyflakes.txt)"
36+
pyflakes rcdb daq halld_rcdb tests utilities examples

docs/development/development.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@ Both suites run on GitHub CI (`.github/workflows/python-tests.yml` and
3131
for more detail.
3232

3333

34+
## Linting (pyflakes)
35+
36+
The Python sources are kept **pyflakes-clean**. Pyflakes catches unused imports,
37+
undefined names, dead local variables and `str.format`/f-string mistakes.
38+
39+
`pyflakes` ships in the project's `dev` optional-dependency group. From the
40+
`python/` directory:
41+
42+
```bash
43+
# one-off, without installing the dev group into your environment:
44+
uv run --extra dev pyflakes rcdb daq halld_rcdb tests utilities examples
45+
46+
# or, if you installed the project with the dev extra (pip install -e ".[dev]"):
47+
pyflakes rcdb daq halld_rcdb tests utilities examples
48+
```
49+
50+
The command must print nothing and exit `0`. This is a **mandatory CI gate**
51+
(`.github/workflows/lint-pyflakes.yml`): any finding fails the build, so run it
52+
before pushing.
53+
54+
A couple of conventions keep it clean without `# noqa` suppressions:
55+
56+
- **Intentional re-exports** (e.g. `rcdb/__init__.py`,
57+
`rcdb/web/modules/__init__.py`) use explicit imports plus an `__all__` list
58+
instead of relying on `import *`.
59+
- Prefer explicit imports over `from module import *` so undefined-name checks
60+
keep working.
61+
62+
3463
## Multi-Database Selector
3564

3665
The web interface supports switching between multiple databases from the browser.

python/daq/update_epics.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ def setup_run_conds(run):
433433
def update_rcdb_conds(db, run, reason):
434434
log.debug(Lf("Running 'update_rcdb_conds(db={}, run={})'", db, run))
435435

436-
TOLERANCE = 1.e-5 # constant used for comparisons
437436
# Run can be a rcdb.Run object or a run number
438437
if not isinstance(run, Run):
439438
log.debug(Lf("Getting run by number={}", run))

python/halld_rcdb/run_config_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _process_parse_result(parse_result, file_name=""):
8181
if 'FADC125_MODE' in cdc_section.entities:
8282
try:
8383
result.cdc_fadc125_mode = int(cdc_section.entities['FADC125_MODE'])
84-
except ValueError as ex:
84+
except ValueError:
8585
log.warning(F("Cant convert CDC:FADC125_MODE value '{}' to int", cdc_section.entities['FADC125_MODE']))
8686
else:
8787
log.warning(F("CDC section is not found in '{}'", file_name))

python/rcdb/cli/add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def add_type(context, name, value_type, description):
4848

4949
# Create or verify
5050
click.echo(f"Creating condition type '{name}' of type '{value_type}'")
51-
ct = db.create_condition_type(name, actual_type, description)
51+
db.create_condition_type(name, actual_type, description)
5252
click.echo("Done.")
5353

5454

python/rcdb/cli/db.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _print_sqlite_table_sizes(engine):
8080
size_mb = round(total_bytes / 1024 / 1024, 2)
8181
click.echo(f" {table_name:30} {size_mb} MB")
8282

83-
except Exception as ex:
83+
except Exception:
8484
click.echo("\n No table size info: sqlite dbstat extension is not installed. Use sqlite3_analyzer to get table sizes")
8585

8686

@@ -116,8 +116,6 @@ def update(context):
116116
if not click.confirm('Do you really want to continue?'):
117117
return
118118

119-
# That we will need for DB
120-
metadata = rcdb.model.Base.metadata
121119
provider = RCDBProvider(context.connection_str, check_version=False)
122120

123121
# Create alias table

python/rcdb/cli/info.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,5 @@ def info_command(context):
5454
click.echo(f" End Date: {last_rp.end_date}")
5555

5656
# Finally, show all possible commands (help):
57-
ctx = click.get_current_context()
5857
click.echo("\nrun 'rcdb --help' for the list of available commands")
5958

python/rcdb/cli/repair/evio_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def read_run_directories(mask, run_min, run_max):
2929
run_dir_name = path.basename(run_dir)
3030
try:
3131
run_num = int(run_dir_name[3:])
32-
except Exception as ex:
32+
except Exception:
3333
click.echo(f"Error extracting run from directory '{run_dir_name}'")
3434
continue
3535

python/rcdb/condition_query_builder.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

python/rcdb/stopwatch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def restart(self):
2727
result = self.elapsed
2828
self.reset()
2929
self.start()
30+
return result
3031

3132
def reset(self):
3233
self._start = None

0 commit comments

Comments
 (0)