Skip to content

Commit 3b3a980

Browse files
authored
build: normalize pyproject (#156)
* Minor change. * Impacted areas: `**/*` * Details: - Normalize `pyproject.toml` - Update OpenFisca-Core to 43.0.0
2 parents db249b7 + 17f94ad commit 3b3a980

22 files changed

+318
-303
lines changed

.flake8

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

.github/lint-files.sh

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

.github/workflows/validate.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ jobs:
3030

3131
- run: make check-syntax-errors
3232

33-
- run: make check-style
34-
3533
- name: Lint Python files
36-
run: "${GITHUB_WORKSPACE}/.github/lint-files.sh '*.py' 'flake8'"
34+
run: make check-style
3735

3836
- name: Lint YAML tests
39-
run: "${GITHUB_WORKSPACE}/.github/lint-files.sh 'tests/*.yaml' 'yamllint'"
37+
run: make check-yaml
4038

4139
test-yaml:
4240
runs-on: ubuntu-22.04

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
### 7.1.6 [#156](https://github.com/openfisca/country-template/pull/156)
4+
5+
* Minor change.
6+
* Impacted areas: `**/*`
7+
* Details:
8+
- Normalize `pyproject.toml`
9+
- Update OpenFisca-Core to 43.0.0
10+
311
### 7.1.5 [#154](https://github.com/openfisca/country-template/pull/154)
412

513
* Minor change.

Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ install: deps
1414
@# Install OpenFisca-Extension-Template for development.
1515
@# `make install` installs the editable version of openfisca-country_template.
1616
@# This allows contributors to test as they code.
17-
pip install --editable .[dev] --upgrade --use-deprecated=legacy-resolver
17+
pip install --editable .[dev] --upgrade
1818

1919
build: clean deps
2020
@# Install OpenFisca-Extension-Template for deployment and publishing.
2121
@# `make build` allows us to be be sure tests are run against the packaged version
2222
@# of OpenFisca-Extension-Template, the same we put in the hands of users and reusers.
2323
python -m build
24+
pip uninstall --yes openfisca-country-template
2425
find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \;
2526

2627
check-syntax-errors:
@@ -29,15 +30,20 @@ check-syntax-errors:
2930
format-style:
3031
@# Do not analyse .gitignored files.
3132
@# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764.
33+
ruff format `git ls-files | grep "\.py$$"`
3234
isort `git ls-files | grep "\.py$$"`
33-
autopep8 `git ls-files | grep "\.py$$"`
34-
pyupgrade --py39-plus `git ls-files | grep "\.py$$"`
35+
black `git ls-files | grep "\.py$$"`
3536

3637
check-style:
3738
@# Do not analyse .gitignored files.
3839
@# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764.
39-
flake8 `git ls-files | grep "\.py$$"`
40-
pylint `git ls-files | grep "\.py$$"`
40+
ruff check `git ls-files | grep "\.py$$"`
41+
isort --check `git ls-files | grep "\.py$$"`
42+
black --check `git ls-files | grep "\.py$$"`
43+
44+
check-yaml:
45+
@# Do not analyse .gitignored files.
46+
@# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764.
4147
yamllint `git ls-files | grep "\.yaml$$"`
4248

4349
test: clean check-syntax-errors check-style
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
"""
2-
This file defines our country's tax and benefit system.
1+
"""This file defines our country's tax and benefit system.
32
43
A tax and benefit system is the higher-level instance in OpenFisca.
4+
55
Its goal is to model the legislation of a country.
6-
Basically a tax and benefit system contains simulation variables (source code) and legislation parameters (data).
6+
7+
Basically a tax and benefit system contains simulation variables (source code)
8+
and legislation parameters (data).
79
810
See https://openfisca.org/doc/key-concepts/tax_and_benefit_system.html
911
"""
@@ -15,27 +17,31 @@
1517
from openfisca_country_template import entities
1618
from openfisca_country_template.situation_examples import couple
1719

18-
1920
COUNTRY_DIR = os.path.dirname(os.path.abspath(__file__))
2021

2122

22-
# Our country tax and benefit class inherits from the general TaxBenefitSystem class.
23-
# The name CountryTaxBenefitSystem must not be changed, as all tools of the OpenFisca ecosystem expect a CountryTaxBenefitSystem class to be exposed in the __init__ module of a country package.
23+
# Our country tax and benefit class inherits from the general TaxBenefitSystem
24+
# class. The name CountryTaxBenefitSystem must not be changed, as all tools of
25+
# the OpenFisca ecosystem expect a CountryTaxBenefitSystem class to be exposed
26+
# in the __init__ module of a country package.
2427
class CountryTaxBenefitSystem(TaxBenefitSystem):
2528
def __init__(self):
29+
"""Initialize our country's tax and benefit system."""
2630
# We initialize our tax and benefit system with the general constructor
2731
super().__init__(entities.entities)
2832

2933
# We add to our tax and benefit system all the variables
3034
self.add_variables_from_directory(os.path.join(COUNTRY_DIR, "variables"))
3135

32-
# We add to our tax and benefit system all the legislation parameters defined in the parameters files
36+
# We add to our tax and benefit system all the legislation parameters
37+
# defined in the parameters files
3338
param_path = os.path.join(COUNTRY_DIR, "parameters")
3439
self.load_parameters(param_path)
3540

36-
# We define which variable, parameter and simulation example will be used in the OpenAPI specification
41+
# We define which variable, parameter and simulation example will be
42+
# used in the OpenAPI specification
3743
self.open_api_config = {
3844
"variable_example": "disposable_income",
3945
"parameter_example": "taxes.income_tax_rate",
4046
"simulation_example": couple,
41-
}
47+
}
Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,75 @@
1-
"""
2-
This file defines the entities needed by our legislation.
1+
"""This file defines the entities needed by our legislation.
32
4-
Taxes and benefits can be calculated for different entities: persons, household, companies, etc.
3+
Taxes and benefits can be calculated for different entities: persons, household,
4+
companies, etc.
55
66
See https://openfisca.org/doc/key-concepts/person,_entities,_role.html
77
"""
88

99
from openfisca_core.entities import build_entity
1010

1111
Household = build_entity(
12-
key = "household",
13-
plural = "households",
14-
label = "All the people in a family or group who live together in the same place.",
15-
doc = """
12+
key="household",
13+
plural="households",
14+
label="All the people in a family or group who live together in the same place.",
15+
doc="""
1616
Household is an example of a group entity.
1717
A group entity contains one or more individual·s.
18-
Each individual in a group entity has a role (e.g. parent or children). Some roles can only be held by a limited number of individuals (e.g. a 'first_parent' can only be held by one individual), while others can have an unlimited number of individuals (e.g. 'children').
18+
Each individual in a group entity has a role (e.g. parent or children).
19+
Some roles can only be held by a limited number of individuals (e.g. a
20+
'first_parent' can only be held by one individual), while others can
21+
have an unlimited number of individuals (e.g. 'children').
1922
2023
Example:
21-
Housing variables (e.g. housing_tax') are usually defined for a group entity such as 'Household'.
24+
Housing variables (e.g. housing_tax') are usually defined for a group
25+
entity such as 'Household'.
2226
2327
Usage:
24-
Check the number of individuals of a specific role (e.g. check if there is a 'second_parent' with household.nb_persons(Household.SECOND_PARENT)).
25-
Calculate a variable applied to each individual of the group entity (e.g. calculate the 'salary' of each member of the 'Household' with salaries = household.members("salary", period = MONTH); sum_salaries = household.sum(salaries)).
28+
Check the number of individuals of a specific role (e.g. check if there
29+
is a 'second_parent' with household.nb_persons(Household.SECOND_PARENT)).
30+
Calculate a variable applied to each individual of the group entity
31+
(e.g. calculate the 'salary' of each member of the 'Household' with:
32+
salaries = household.members("salary", period = MONTH)
33+
sum_salaries = household.sum(salaries)).
2634
2735
For more information, see: https://openfisca.org/doc/coding-the-legislation/50_entities.html
2836
""",
29-
roles = [
37+
roles=[
3038
{
3139
"key": "parent",
3240
"plural": "parents",
3341
"label": "Parents",
3442
"max": 2,
3543
"subroles": ["first_parent", "second_parent"],
3644
"doc": "The one or two adults in charge of the household.",
37-
},
45+
},
3846
{
3947
"key": "child",
4048
"plural": "children",
4149
"label": "Child",
4250
"doc": "Other individuals living in the household.",
43-
},
44-
],
45-
)
51+
},
52+
],
53+
)
4654

4755
Person = build_entity(
48-
key = "person",
49-
plural = "persons",
50-
label = "An individual. The minimal legal entity on which a legislation might be applied.",
51-
doc = """
52-
53-
Variables like 'salary' and 'income_tax' are usually defined for the entity 'Person'.
56+
key="person",
57+
plural="persons",
58+
label="An individual. The minimal entity on which legislation can be applied.",
59+
doc="""
60+
Variables like 'salary' and 'income_tax' are usually defined for the entity
61+
'Person'.
5462
5563
Usage:
56-
Calculate a variable applied to a 'Person' (e.g. access the 'salary' of a specific month with person("salary", "2017-05")).
57-
Check the role of a 'Person' in a group entity (e.g. check if a the 'Person' is a 'first_parent' in a 'Household' entity with person.has_role(Household.FIRST_PARENT)).
64+
Calculate a variable applied to a 'Person' (e.g. access the 'salary' of
65+
a specific month with person("salary", "2017-05")).
66+
Check the role of a 'Person' in a group entity (e.g. check if a the
67+
'Person' is a 'first_parent' in a 'Household' entity with
68+
person.has_role(Household.FIRST_PARENT)).
5869
5970
For more information, see: https://openfisca.org/doc/coding-the-legislation/50_entities.html
6071
""",
61-
is_person = True,
62-
)
72+
is_person=True,
73+
)
6374

6475
entities = [Household, Person]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
"""
2-
This sub-package is used to define reforms.
1+
"""This sub-package is used to define reforms.
32
4-
A reform is a set of modifications to be applied to a reference tax and benefit system to carry out experiments.
3+
A reform is a set of modifications to be applied to a reference tax and benefit
4+
system to carry out experiments.
55
66
See https://openfisca.org/doc/key-concepts/reforms.html
77
"""
Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
"""
2-
This file defines a reform to add a dynamic variable, based on input data.
1+
"""This file defines a reform to add a dynamic variable, based on input data.
32
4-
A reform is a set of modifications to be applied to a reference tax and benefit system to carry out experiments.
3+
A reform is a set of modifications to be applied to a reference tax and benefit
4+
system to carry out experiments.
55
66
See https://openfisca.org/doc/key-concepts/reforms.html
77
"""
88

9-
# Import from openfisca-core the Python objects used to code the legislation in OpenFisca
9+
# Import from openfisca-core the objects used to code the legislation in OpenFisca
1010
from openfisca_core.periods import MONTH
1111
from openfisca_core.reforms import Reform
1212
from openfisca_core.variables import Variable
@@ -17,36 +17,37 @@
1717

1818
def create_dynamic_variable(name, **variable):
1919
"""Create new variable dynamically."""
20-
NewVariable = type(name, (Variable,), {
21-
"value_type": variable["value_type"],
22-
"entity": variable["entity"],
23-
"default_value": variable["default_value"],
24-
"definition_period": variable["definition_period"],
25-
"label": variable["label"],
26-
"reference": variable["reference"],
27-
})
28-
29-
return NewVariable
20+
return type(
21+
name,
22+
(Variable,),
23+
{
24+
"value_type": variable["value_type"],
25+
"entity": variable["entity"],
26+
"default_value": variable["default_value"],
27+
"definition_period": variable["definition_period"],
28+
"label": variable["label"],
29+
"reference": variable["reference"],
30+
},
31+
)
3032

3133

3234
class add_dynamic_variable(Reform):
3335
def apply(self):
34-
"""
35-
Apply reform.
36+
"""Apply reform.
3637
3738
A reform always defines an `apply` method that builds the reformed tax
3839
and benefit system from the reference one.
3940
4041
See https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform
4142
"""
4243
NewVariable = create_dynamic_variable(
43-
name = "goes_to_school",
44-
value_type = bool,
45-
entity = Person,
46-
default_value = True,
47-
definition_period = MONTH,
48-
label = "The person goes to school (only relevant for children)",
49-
reference = "https://law.gov.example/goes_to_school",
50-
)
44+
name="goes_to_school",
45+
value_type=bool,
46+
entity=Person,
47+
default_value=True,
48+
definition_period=MONTH,
49+
label="The person goes to school (only relevant for children)",
50+
reference="https://law.gov.example/goes_to_school",
51+
)
5152

5253
self.add_variable(NewVariable)

0 commit comments

Comments
 (0)