Skip to content

Commit 7143dcc

Browse files
MaxGhenisclaude
andauthored
Switch code formatter from Black to Ruff (#547)
* Switch code formatter from Black to Ruff Replace black and linecheck with ruff for code formatting: - Remove black[jupyter] and linecheck dependencies, add ruff>=0.9.0 - Update Makefile format target to use ruff format - Replace lgeiger/black-action in CI with ruff format --check - Add [tool.ruff] config with line-length=88 to pyproject.toml - Add towncrier changelog fragment - Reformat all files with ruff Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Reformat .github/bump_version.py with ruff Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent acdc685 commit 7143dcc

111 files changed

Lines changed: 179 additions & 410 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/pr.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v4
10-
- name: Check formatting
11-
uses: "lgeiger/black-action@master"
10+
- name: Set up Python
11+
uses: actions/setup-python@v5
1212
with:
13-
args: ". -l 79 --check"
13+
python-version: "3.14"
14+
allow-prereleases: true
15+
- name: Install ruff
16+
run: pip install "ruff>=0.9.0"
17+
- name: Check formatting
18+
run: ruff format --check .
1419
check-changelog:
1520
name: Check changelog fragment
1621
runs-on: ubuntu-latest

.github/workflows/push.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ jobs:
1010
&& (github.event.head_commit.message == 'Update PolicyEngine Canada')
1111
steps:
1212
- uses: actions/checkout@v4
13-
- name: Check formatting
14-
uses: "lgeiger/black-action@master"
13+
- name: Set up Python
14+
uses: actions/setup-python@v5
1515
with:
16-
args: ". -l 79 --check"
16+
python-version: "3.14"
17+
allow-prereleases: true
18+
- name: Install ruff
19+
run: pip install "ruff>=0.9.0"
20+
- name: Check formatting
21+
run: ruff format --check .
1722
versioning:
1823
name: Update versioning
1924
if: |

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ documentation:
55
jupyter-book build docs
66

77
format:
8-
black . -l 79
9-
linecheck . --fix
8+
ruff format .
109

1110
install:
1211
pip install -e .[dev]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Switch code formatter from Black to Ruff.

policyengine_canada/data/datasets/country_template_dataset.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ class CountryTemplateDataset(Dataset):
1010
label = "Country template dataset"
1111
folder_path = COUNTRY_DIR / "data" / "storage"
1212
data_format = Dataset.TIME_PERIOD_ARRAYS
13-
file_path = (
14-
Path(__file__).parent.parent
15-
/ "storage"
16-
/ "country_template_dataset.h5"
17-
)
13+
file_path = Path(__file__).parent.parent / "storage" / "country_template_dataset.h5"
1814

1915
# The generation function is the most important part: it defines
2016
# how the dataset is generated from the raw data for a given year.

policyengine_canada/variables/gov/cra/benefits/ccb/child_benefit_base_person.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ def formula(person, period, parameters):
1313
age = person("age", period)
1414
p = parameters(period).gov.cra.benefits.ccb
1515
full_custody = person("full_custody", period)
16-
return where(
17-
full_custody, p.base.calc(age), p.base.calc(age) / p.divisor
18-
)
16+
return where(full_custody, p.base.calc(age), p.base.calc(age) / p.divisor)

policyengine_canada/variables/gov/cra/benefits/cwb/disability_supplement/cwb_disability_category.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ def formula(household, period, parameters):
2020
person = household.members
2121
# Compute individual-level eligibility among heads/spouses.
2222
head_or_spouse = person("is_head_or_spouse", period)
23-
disability_eligible = person(
24-
"cwb_disability_supplement_eligible", period
25-
)
23+
disability_eligible = person("cwb_disability_supplement_eligible", period)
2624
cwb_family = household("is_cwb_family", period)
2725
eligible_spouses = household.sum(head_or_spouse * disability_eligible)
2826
return select(

policyengine_canada/variables/gov/cra/benefits/cwb/disability_supplement/cwb_disability_supplement_eligible.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ class cwb_disability_supplement_eligible(Variable):
66
entity = Person
77
label = "Eligible for canada workers benefit supplement"
88
definition_period = YEAR
9-
reference = (
10-
"https://laws-lois.justice.gc.ca/eng/acts/I-3.3/page-89.html#docCont"
11-
)
9+
reference = "https://laws-lois.justice.gc.ca/eng/acts/I-3.3/page-89.html#docCont"
1210

1311
def formula(person, period, parameters):
1412
# For now, apply a person-level logic based on age.

policyengine_canada/variables/gov/cra/benefits/cwb/disability_supplement/cwb_disability_supplement_max_amount.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ class cwb_disability_supplement_max_amount(Variable):
66
entity = Household
77
label = "Eligible for canada workers benefit supplement"
88
definition_period = YEAR
9-
reference = (
10-
"https://laws-lois.justice.gc.ca/eng/acts/I-3.3/page-89.html#docCont"
11-
)
9+
reference = "https://laws-lois.justice.gc.ca/eng/acts/I-3.3/page-89.html#docCont"
1210
unit = CAD
1311

1412
def formula(household, period, parameters):
1513
person = household.members
1614
eligible = person("cwb_disability_supplement_eligible", period)
17-
amount = parameters(
18-
period
19-
).gov.cra.benefits.cwb.amount.disability_supplement
15+
amount = parameters(period).gov.cra.benefits.cwb.amount.disability_supplement
2016
return household.sum(eligible * amount)

0 commit comments

Comments
 (0)