Skip to content

Commit a3f367e

Browse files
MaxGhenisclaude
andcommitted
Add ruff linting to Makefile format target
Configure ruff check with E (pycodestyle), F (pyflakes), and I (isort) rule sets. Auto-fixed import sorting; remaining rules that conflict with existing code patterns are ignored for now. This makes ruff check available via `make format` without enforcing it in CI yet. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2b2a727 commit a3f367e

73 files changed

Lines changed: 190 additions & 218 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.

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ documentation:
66
python docs/add_plotly_to_book.py docs/_build
77

88
format:
9+
ruff check . --fix
910
ruff format .
1011

1112
install:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added ruff linting (ruff check) to Makefile format target with E, F, and I rule sets.

docs/usage/country.ipynb

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"outputs": [],
1717
"source": [
1818
"from policyengine_core.country_template import (\n",
19-
" CountryTaxBenefitSystem, # Holds all policy-related data.\n",
20-
" Simulation, # General purpose: enables users to simulate policy on new data.\n",
21-
" Microsimulation, # Specific purpose: enables users to simulate policy on large datasets.\n",
2219
" COUNTRY_DIR, # Path to the country directory.\n",
2320
" DATASETS, # List of datasets available for this country (to use with `Microsimulation`).\n",
21+
" CountryTaxBenefitSystem, # Holds all policy-related data.\n",
22+
" Microsimulation, # Specific purpose: enables users to simulate policy on large datasets.\n",
23+
" Simulation, # General purpose: enables users to simulate policy on new data.\n",
2424
")"
2525
]
2626
},
@@ -52,23 +52,16 @@
5252
"metadata": {},
5353
"outputs": [],
5454
"source": [
55-
"import os\n",
56-
"from typing import Dict, Type\n",
57-
"from policyengine_core.data.dataset import Dataset\n",
58-
"from policyengine_core.populations.population import Population\n",
59-
"from policyengine_core.taxbenefitsystems import TaxBenefitSystem\n",
6055
"from policyengine_core.country_template import entities\n",
61-
"from policyengine_core.country_template.situation_examples import couple\n",
62-
"from policyengine_core.simulations import Simulation as CoreSimulation\n",
63-
"from policyengine_core.simulations import (\n",
64-
" Microsimulation as CoreMicrosimulation,\n",
65-
")\n",
56+
"from policyengine_core.country_template.constants import COUNTRY_DIR\n",
6657
"from policyengine_core.country_template.data.datasets.country_template_dataset import (\n",
6758
" CountryTemplateDataset,\n",
6859
")\n",
69-
"from pathlib import Path\n",
70-
"import logging\n",
71-
"from policyengine_core.country_template.constants import COUNTRY_DIR\n",
60+
"from policyengine_core.simulations import (\n",
61+
" Microsimulation as CoreMicrosimulation,\n",
62+
")\n",
63+
"from policyengine_core.simulations import Simulation as CoreSimulation\n",
64+
"from policyengine_core.taxbenefitsystems import TaxBenefitSystem\n",
7265
"\n",
7366
"DATASETS = [CountryTemplateDataset] # Important: must be instantiated\n",
7467
"\n",

docs/usage/datasets.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"source": [
3333
"from policyengine_core.country_template.constants import COUNTRY_DIR\n",
3434
"from policyengine_core.data import Dataset\n",
35-
"from policyengine_core.periods import ETERNITY, MONTH, period\n",
35+
"from policyengine_core.periods import ETERNITY, period\n",
3636
"\n",
3737
"\n",
3838
"class CountryTemplateDataset(Dataset):\n",

docs/usage/simulation.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,8 @@
10441044
],
10451045
"source": [
10461046
"import plotly.express as px\n",
1047-
"from policyengine_core.charts import format_fig, display_fig, BLUE\n",
1047+
"\n",
1048+
"from policyengine_core.charts import BLUE, format_fig\n",
10481049
"\n",
10491050
"fig = (\n",
10501051
" px.line(\n",
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
from .api import *
2+
from .bar import *
13
from .formatting import (
24
BLUE,
35
BLUE_COLOUR_SCALE,
4-
DARK_GREEN,
5-
LIGHT_GREEN,
66
DARK_GRAY,
7+
DARK_GREEN,
78
GRAY,
89
LIGHT_GRAY,
10+
LIGHT_GREEN,
911
WHITE,
10-
format_fig,
1112
display_fig,
13+
format_fig,
1214
)
13-
14-
from .bar import *
15-
from .api import *

policyengine_core/charts/api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import requests
21
import time
2+
33
import plotly.graph_objects as go
4+
import requests
5+
46
from .formatting import (
7+
BLUE_LIGHT,
8+
BLUE_PRIMARY,
59
DARK_GRAY,
610
MEDIUM_DARK_GRAY,
711
WHITE,
8-
BLUE_LIGHT,
9-
BLUE_PRIMARY,
1012
format_fig,
1113
)
1214

policyengine_core/charts/bar.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from typing import Callable
2+
3+
import numpy as np
14
import pandas as pd
2-
from .formatting import *
35
import plotly.express as px
46
from microdf import MicroSeries
5-
from typing import Callable
6-
import numpy as np
7+
8+
from .formatting import *
79

810

911
def bar_chart(

policyengine_core/commons/formulas.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
import logging
22
from typing import Any, Callable, Dict, List, Sequence, Type, TypeVar, Union
3+
from warnings import warn
34

45
import numpy
56
import numpy as np
67
import pandas as pd
7-
from numpy import logical_not as not_
88
from numpy import maximum as max_
99
from numpy import minimum as min_
10-
from numpy import round as round_
11-
from numpy import select, where
12-
13-
from warnings import warn
10+
from numpy import select
1411

1512
from policyengine_core.parameters.parameter_node import ParameterNode
1613
from policyengine_core.periods.period_ import Period
1714
from policyengine_core.populations.population import Population
1815
from policyengine_core.types import ArrayLike, ArrayType
1916
from policyengine_core.variables.variable import Variable
2017

21-
import json
22-
2318
T = TypeVar("T")
2419

2520

@@ -426,7 +421,7 @@ def sum_of_variables(variables: Union[List[str], str]) -> Callable:
426421
"""
427422

428423
warn(
429-
f"Sum-of-variables formulas are deprecated- please use `adds` or `subtracts` instead."
424+
"Sum-of-variables formulas are deprecated- please use `adds` or `subtracts` instead."
430425
)
431426

432427
def sum_of_variables(entity, period, parameters):

policyengine_core/country_template/data/datasets/country_template_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from policyengine_core.country_template.constants import COUNTRY_DIR
22
from policyengine_core.data import Dataset
3-
from policyengine_core.periods import ETERNITY, MONTH, period
3+
from policyengine_core.periods import ETERNITY, period
44

55

66
class CountryTemplateDataset(Dataset):

0 commit comments

Comments
 (0)