Skip to content

Commit f863d05

Browse files
MaxGhenisclaude
andauthored
Switch from black to ruff format (#1515)
* Switch from black to ruff format Replace black formatter with ruff format across pyproject.toml, Makefile, CI workflows, and CLAUDE.md. Reformat entire codebase with ruff (line-length=88). No lint rules added — ruff is used for formatting only. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Exclude malformed notebook from ruff format check The care-to-learn.ipynb has an invalid notebook schema that causes ruff to exit with code 2, failing CI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8b21661 commit f863d05

256 files changed

Lines changed: 670 additions & 1570 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/bump_version.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ def get_current_version(pyproject_path: Path) -> str:
1919

2020
def infer_bump(changelog_dir: Path) -> str:
2121
fragments = [
22-
f
23-
for f in changelog_dir.iterdir()
24-
if f.is_file() and f.name != ".gitkeep"
22+
f for f in changelog_dir.iterdir() if f.is_file() and f.name != ".gitkeep"
2523
]
2624
if not fragments:
2725
print("No changelog fragments found", file=sys.stderr)

.github/workflows/code_changes.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v4
20+
- name: Install uv
21+
uses: astral-sh/setup-uv@v5
2022
- name: Check formatting
21-
uses: "lgeiger/black-action@master"
22-
with:
23-
args: ". -l 79 --check"
23+
run: uvx ruff format --check .
2424
Test:
2525
runs-on: macos-latest
2626
permissions:

.github/workflows/pr_code_changes.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- uses: actions/checkout@v4
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v5
2224
- name: Check formatting
23-
uses: "lgeiger/black-action@master"
24-
with:
25-
args: ". -l 79 --check"
25+
run: uvx ruff format --check .
2626
Test:
2727
runs-on: macos-latest
2828
permissions:

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
## Build commands
88
- Install: `make install` or `pip install -e ".[dev]" --config-settings editable_mode=compat`
9-
- Format code: `make format` or `black . -l 79`
9+
- Format code: `make format` or `ruff format .`
1010
- Run all tests: `make test`
1111
- Run single test: `pytest policyengine_uk/tests/path/to/test_file.py::test_function -v`
1212
- Generate documentation: `make documentation`
1313
- Update changelog: `make changelog`
1414

1515
## Code Standards
16-
- **Formatting**: Use Black with 79-character line length
16+
- **Formatting**: Use Ruff formatter with 88-character line length
1717
- **Imports**: Group imports by stdlib, third-party, local with each group alphabetized
1818
- **Naming**: Use snake_case for variables/functions, CamelCase for classes
1919
- **Type Hints**: Use Python type hints where possible

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ install:
1111
pip install huggingface_hub
1212

1313
format:
14-
black . -l 79
14+
ruff format .
1515

1616
test:
1717
policyengine-core test policyengine_uk/tests/policy -c policyengine_uk
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Switch from black to ruff format.

docs/book/programs/gov/dcms/bbc/tv-licence.ipynb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,10 @@
128128
"\n",
129129
"df = pd.DataFrame()\n",
130130
"df[\"Date\"] = [\n",
131-
" parameter.instant_str\n",
132-
" for parameter in dcms.bbc.tv_licence.colour.values_list\n",
131+
" parameter.instant_str for parameter in dcms.bbc.tv_licence.colour.values_list\n",
133132
"]\n",
134133
"df[\"Full TV Licence Fee\"] = [\n",
135-
" f\"£{parameter.value:.2f}\"\n",
136-
" for parameter in dcms.bbc.tv_licence.colour.values_list\n",
134+
" f\"£{parameter.value:.2f}\" for parameter in dcms.bbc.tv_licence.colour.values_list\n",
137135
"]\n",
138136
"df[\"Blind TV Licence Fee\"] = [\n",
139137
" f\"£{0.5 * parameter.value:.2f}\"\n",
@@ -334,9 +332,7 @@
334332
" aged_discount[\"Change against current\"] += [\n",
335333
" f\"{aged_discount['Reformed value'][i] - 1:.0%}\"\n",
336334
" ]\n",
337-
" aged_discount[\"Reformed value\"][\n",
338-
" i\n",
339-
" ] = f\"{aged_discount['Reformed value'][i]:.0%}\"\n",
335+
" aged_discount[\"Reformed value\"][i] = f\"{aged_discount['Reformed value'][i]:.0%}\"\n",
340336
" aged_discount[\"Reference\"] += [\n",
341337
" f'<a href=\"{reference_list_ad[i]}\">Budgetary impact of changing aged discount to {aged_discount[\"Reformed value\"][i]}</a>'\n",
342338
" ]\n",

docs/book/programs/gov/dwp/pension-credit.ipynb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,8 @@
167167
"\n",
168168
"parameters = system.parameters\n",
169169
"\n",
170-
"carer_addition = (\n",
171-
" parameters.gov.dwp.pension_credit.guarantee_credit.carer.addition\n",
172-
")\n",
173-
"child_addition = (\n",
174-
" parameters.gov.dwp.pension_credit.guarantee_credit.child.addition\n",
175-
")\n",
170+
"carer_addition = parameters.gov.dwp.pension_credit.guarantee_credit.carer.addition\n",
171+
"child_addition = parameters.gov.dwp.pension_credit.guarantee_credit.child.addition\n",
176172
"disabled_child = (\n",
177173
" parameters.gov.dwp.pension_credit.guarantee_credit.child.disability.addition\n",
178174
")\n",
@@ -1506,12 +1502,8 @@
15061502
"\n",
15071503
"parameters = system.parameters\n",
15081504
"\n",
1509-
"threshold_single = (\n",
1510-
" parameters.gov.dwp.pension_credit.savings_credit.threshold.SINGLE\n",
1511-
")\n",
1512-
"threshold_couple = (\n",
1513-
" parameters.gov.dwp.pension_credit.savings_credit.threshold.COUPLE\n",
1514-
")\n",
1505+
"threshold_single = parameters.gov.dwp.pension_credit.savings_credit.threshold.SINGLE\n",
1506+
"threshold_couple = parameters.gov.dwp.pension_credit.savings_credit.threshold.COUPLE\n",
15151507
"\n",
15161508
"elements = [threshold_single, threshold_couple] # [...]\n",
15171509
"\n",

docs/book/programs/gov/dwp/universal-credit.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@
194194
"disabled_child_amount = (\n",
195195
" parameters.gov.dwp.universal_credit.elements.child.disabled.amount\n",
196196
")\n",
197-
"higher_amount = (\n",
198-
" parameters.gov.dwp.universal_credit.elements.child.first.higher_amount\n",
199-
")\n",
197+
"higher_amount = parameters.gov.dwp.universal_credit.elements.child.first.higher_amount\n",
200198
"\n",
201199
"elements = [\n",
202200
" carer_amount,\n",

docs/book/programs/gov/hmrc/child-benefit.ipynb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@
175175
" data[\"Reference\"] += [\"\"]\n",
176176
"\n",
177177
"\n",
178-
"for (\n",
179-
" parameter\n",
180-
") in parameters.gov.hmrc.child_benefit.amount.additional.values_list:\n",
178+
"for parameter in parameters.gov.hmrc.child_benefit.amount.additional.values_list:\n",
181179
" data[\"Date\"] += [parameter.instant_str]\n",
182180
" data[\"Name\"] += [\"Additional\"]\n",
183181
" data[\"Value\"] += [f\"£{parameter.value:.2f}\"]\n",
@@ -189,9 +187,9 @@
189187
" data[\"Reference\"] += [\"\"]\n",
190188
"\n",
191189
"\n",
192-
"pd.DataFrame(data).sort_values(\"Date\").set_index(\n",
193-
" [\"Date\", \"Name\"]\n",
194-
").style.format(lambda x: x)"
190+
"pd.DataFrame(data).sort_values(\"Date\").set_index([\"Date\", \"Name\"]).style.format(\n",
191+
" lambda x: x\n",
192+
")"
195193
]
196194
},
197195
{
@@ -302,9 +300,7 @@
302300
"pd.DataFrame(\n",
303301
" {\n",
304302
" \"Number of children\": list(range(1, 7)),\n",
305-
" \"Child Benefit (Annual)\": list(\n",
306-
" map(get_cb_for_n_children, range(1, 7))\n",
307-
" ),\n",
303+
" \"Child Benefit (Annual)\": list(map(get_cb_for_n_children, range(1, 7))),\n",
308304
" }\n",
309305
").set_index(\"Number of children\")"
310306
]

0 commit comments

Comments
 (0)