From 036312b2941135088c02eefab209dce800711cf7 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 15 Nov 2022 18:37:56 +0100 Subject: [PATCH 01/23] Add .editorconfig --- .editorconfig | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cb83070 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[Makefile] +indent_size = 4 +indent_style = tab + +[*.robot] +indent_size = 4 +indent_style = tab + +[*.{py,pyi,rst,toml}] +indent_size = 4 + +[*.md] +trim_trailing_whitespace = false + +[*.{diff,patch}] +trim_trailing_whitespace = false From 977daa840e18effc677ac7a72b09e06553b1177b Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 5 Jan 2023 17:54:35 +0000 Subject: [PATCH 02/23] Apply suggestions from code review Co-authored-by: Matti Schneider --- .editorconfig | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.editorconfig b/.editorconfig index cb83070..a924ef0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,10 +12,6 @@ trim_trailing_whitespace = true indent_size = 4 indent_style = tab -[*.robot] -indent_size = 4 -indent_style = tab - [*.{py,pyi,rst,toml}] indent_size = 4 From 7101545b9428719459f8a4d1a4aa448a1306012d Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sat, 21 Jan 2023 15:32:56 +0100 Subject: [PATCH 03/23] Trim trailing whitespaces all over --- .editorconfig | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.editorconfig b/.editorconfig index a924ef0..3e68138 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,9 +14,3 @@ indent_style = tab [*.{py,pyi,rst,toml}] indent_size = 4 - -[*.md] -trim_trailing_whitespace = false - -[*.{diff,patch}] -trim_trailing_whitespace = false From f60ba44130aed248ac9408526f0c420a64022647 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sat, 21 Jan 2023 15:41:36 +0100 Subject: [PATCH 04/23] Bump version & changelog --- CHANGELOG.md | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c9cd17..7442df5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 1.3.12 - [#52](https://github.com/openfisca/extension-template/pull/52) + +* Minor change. +* Details: + - Add .editorconfig for consistency of editor settings across packages + ### 1.3.11 - [#51](https://github.com/openfisca/extension-template/pull/51) * Technical Changes diff --git a/setup.py b/setup.py index ce832ce..12e2ca1 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name = "OpenFisca-Extension-Template", - version = "1.3.11", + version = "1.3.12", author = "OpenFisca Team", author_email = "contact@openfisca.org", classifiers = [ From d6d9f59789ebbb58dab3351c1401689d81a9bbc1 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 20 Dec 2022 06:29:29 +0100 Subject: [PATCH 05/23] Add isort & pyupgrade to makefile --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 0583f1e..deca03d 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,9 @@ check-syntax-errors: format-style: @# Do not analyse .gitignored files. @# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764. + isort `git ls-files | grep "\.py$$"` autopep8 `git ls-files | grep "\.py$$"` + pyupgrade `git ls-files | grep "\.py$$"` --py37-plus check-style: @# Do not analyse .gitignored files. From ba57b04a8ae3122218fad99bf55758d0cf876e50 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 20 Dec 2022 06:36:00 +0100 Subject: [PATCH 06/23] Add to setup.py --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 12e2ca1..a39f89d 100644 --- a/setup.py +++ b/setup.py @@ -54,8 +54,10 @@ "flake8-simplify >= 0.9.0, < 1.0.0", "flake8-use-fstring >= 1.1.0, < 2.0.0", "importlib-metadata < 4.3.0", + "isort >= 5.10.0, < 6.0.0", "pycodestyle >= 2.7.0, < 2.8.0", "pylint >= 2.6.0, < 3.0.0", + "pyupgrade >= 3.2.0, < 4.0.0", ], }, packages = find_packages(), From 96b3ce28a7c7dafc641610fd2dff30dd5e82078a Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 20 Dec 2022 06:38:37 +0100 Subject: [PATCH 07/23] Add to setup.cfg --- Makefile | 4 +++- setup.cfg | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index deca03d..4b15cb9 100644 --- a/Makefile +++ b/Makefile @@ -41,4 +41,6 @@ check-style: pylint `git ls-files | grep "\.py$$"` test: clean check-syntax-errors check-style - openfisca test openfisca_extension_template/tests --country-package openfisca_country_template --extensions openfisca_extension_template + openfisca test openfisca_extension_template/tests \ + --country-package openfisca_country_template \ + --extensions openfisca_extension_template diff --git a/setup.cfg b/setup.cfg index c3380b1..5ea3994 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,6 +30,17 @@ application-package-names = openfisca_core,openfisca_country_template disable = C0103,C0115,C0301,E0213,E1101,E1102,W0621,W1203 score = no +[isort] +case_sensitive = true +group_by_package = true +include_trailing_comma = true +known_first_party = openfisca_extension_template +known_openfisca = openfisca_core, openfisca_country_template +known_typing = mypy*, *types*, *typing* +multi_line_output = 8 +py_version = 37 +sections = FUTURE,TYPING,STDLIB,THIRDPARTY,OPENFISCA,FIRSTPARTY,LOCALFOLDER + [tool:pytest] addopts = --showlocals --exitfirst --doctest-modules testpaths = openfisca_extension_template/tests From 2d3c3a787b1738bd287874998720ed693d00a239 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sat, 21 Jan 2023 18:24:08 +0100 Subject: [PATCH 08/23] Bump version & changelog --- CHANGELOG.md | 7 +++++++ openfisca_extension_template/local_benefit.py | 12 +++++++++--- setup.py | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7442df5..be60df4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### 1.3.13 - [#53](https://github.com/openfisca/extension-template/pull/53) + +* Minor change. +* Details: + - Improve format with isort & pyupgrade + - This to help transition to py3.8 and np1.21+ + ### 1.3.12 - [#52](https://github.com/openfisca/extension-template/pull/52) * Minor change. diff --git a/openfisca_extension_template/local_benefit.py b/openfisca_extension_template/local_benefit.py index 78eb611..c234843 100644 --- a/openfisca_extension_template/local_benefit.py +++ b/openfisca_extension_template/local_benefit.py @@ -20,13 +20,19 @@ class local_town_child_allowance(Variable): label = "Local benefit: a fixed amount by child each month" def formula(famille, period, parameters): - """ - Local benefit. + """Local benefit. Extensions can only add variables and parameters to the tax and benefit system: they cannot modify or neutralize existing ones. + + Parameters: + period: an `Instant` to calculate the variable. + parameters: a bounded function to query for model's parameters. + + Returns: + A vector with the corresponding values per entity. + """ nb_children = famille.nb_persons(role = Household.CHILD) amount_by_child = parameters(period).local_town.child_allowance.amount - return nb_children * amount_by_child diff --git a/setup.py b/setup.py index a39f89d..3a7c586 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name = "OpenFisca-Extension-Template", - version = "1.3.12", + version = "1.3.13", author = "OpenFisca Team", author_email = "contact@openfisca.org", classifiers = [ From 64ba6872960513c1a56bf2fe99e072ed698f7ceb Mon Sep 17 00:00:00 2001 From: sandcha Date: Mon, 29 Apr 2024 12:43:24 +0200 Subject: [PATCH 09/23] Use PyPi token for authentication on CI deploy job --- .github/workflows/workflow.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 658d326..38fda9f 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -133,8 +133,7 @@ jobs: needs: [ check-for-functional-changes ] if: needs.check-for-functional-changes.outputs.status == 'success' env: - PYPI_USERNAME: openfisca-bot - PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + PYPI_TOKEN_OPENFISCA_BOT: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} steps: - uses: actions/checkout@v2 with: @@ -156,6 +155,6 @@ jobs: path: dist key: release-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Upload a Python package to PyPi - run: twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD + run: twine upload dist/* --username __token__ --password $PYPI_TOKEN_OPENFISCA_BOT - name: Publish a git tag run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" From afbe64d0ca7b2e87a1fed0178bf8f63135278ae5 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Fri, 21 Jun 2024 15:41:14 +0200 Subject: [PATCH 10/23] Use PYPI_TOKEN secret in workflow --- .github/workflows/workflow.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 38fda9f..8148fe7 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -132,8 +132,6 @@ jobs: runs-on: ubuntu-20.04 needs: [ check-for-functional-changes ] if: needs.check-for-functional-changes.outputs.status == 'success' - env: - PYPI_TOKEN_OPENFISCA_BOT: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} steps: - uses: actions/checkout@v2 with: @@ -155,6 +153,6 @@ jobs: path: dist key: release-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Upload a Python package to PyPi - run: twine upload dist/* --username __token__ --password $PYPI_TOKEN_OPENFISCA_BOT + run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN }} - name: Publish a git tag run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" From cd78f7c417e5bb8b135278def2bf2bdd9abcd946 Mon Sep 17 00:00:00 2001 From: sandcha Date: Mon, 29 Apr 2024 12:59:20 +0200 Subject: [PATCH 11/23] Describe CI deploy update in CHANGELOG --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be60df4..90e1624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [#55](https://github.com/openfisca/extension-template/pull/55) + +* Technical improvement. +* Details: + - Use PyPi token for authentication on CI `deploy` job + - Allows for Python package upload since the 2FA enforcement on PyPi + ### 1.3.13 - [#53](https://github.com/openfisca/extension-template/pull/53) * Minor change. From ec4dcfdf44faa775b42d2293a27ad2ed5bbbdfe2 Mon Sep 17 00:00:00 2001 From: sandcha Date: Fri, 28 Jun 2024 17:05:55 +0200 Subject: [PATCH 12/23] Rename PYPI_TOKEN to PYPI_TOKEN_OPENFISCA_BOT in CI configuration --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 8148fe7..a5cd1d2 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -153,6 +153,6 @@ jobs: path: dist key: release-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Upload a Python package to PyPi - run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN }} + run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} - name: Publish a git tag run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" From 555746b36c3f7148a51ed8a2e6dcfaba63331448 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Fri, 21 Jun 2024 15:42:33 +0200 Subject: [PATCH 13/23] Bump version --- CHANGELOG.md | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90e1624..161c058 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -### [#55](https://github.com/openfisca/extension-template/pull/55) +### 1.3.14 - [#55](https://github.com/openfisca/extension-template/pull/55) * Technical improvement. * Details: diff --git a/setup.py b/setup.py index 3a7c586..625a4f3 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name = "OpenFisca-Extension-Template", - version = "1.3.13", + version = "1.3.14", author = "OpenFisca Team", author_email = "contact@openfisca.org", classifiers = [ From b0ff15b366c4021de1a07d1968ff7218f12178e3 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 29 Sep 2024 22:40:00 +0200 Subject: [PATCH 14/23] chore(variables): move to folder --- .../variables/__init__.py | 0 .../{ => variables}/local_benefit.py | 23 ++++--- setup.cfg | 48 -------------- setup.py | 64 ------------------- 4 files changed, 14 insertions(+), 121 deletions(-) create mode 100644 openfisca_extension_template/variables/__init__.py rename openfisca_extension_template/{ => variables}/local_benefit.py (58%) delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/openfisca_extension_template/variables/__init__.py b/openfisca_extension_template/variables/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openfisca_extension_template/local_benefit.py b/openfisca_extension_template/variables/local_benefit.py similarity index 58% rename from openfisca_extension_template/local_benefit.py rename to openfisca_extension_template/variables/local_benefit.py index c234843..1cbe984 100644 --- a/openfisca_extension_template/local_benefit.py +++ b/openfisca_extension_template/variables/local_benefit.py @@ -1,15 +1,19 @@ -""" -This file defines an additional variable for the modelled legislation. +"""This file defines an additional variable for the modelled legislation. A variable is a property of an Entity such as a Person, a Household… -See https://openfisca.org/doc/key-concepts/variables.html +See: + https://openfisca.org/doc/key-concepts/variables.html + """ -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca -# Import the entities specifically defined for this tax and benefit system +from openfisca_core import types as t + +# Import the openfisca-core objects used to code the legislation in OpenFisca. from openfisca_core.periods import MONTH from openfisca_core.variables import Variable + +# Import the entities specifically defined for this tax and benefit system. from openfisca_country_template.entities import Household @@ -19,20 +23,21 @@ class local_town_child_allowance(Variable): definition_period = MONTH label = "Local benefit: a fixed amount by child each month" - def formula(famille, period, parameters): + def formula(family: t.Population, period: t.Instant, params: t.Params) -> t.Array: """Local benefit. Extensions can only add variables and parameters to the tax and benefit system: they cannot modify or neutralize existing ones. Parameters: + family: a population of entities. period: an `Instant` to calculate the variable. - parameters: a bounded function to query for model's parameters. + params: a bounded function to query for model's parameters. Returns: A vector with the corresponding values per entity. """ - nb_children = famille.nb_persons(role = Household.CHILD) - amount_by_child = parameters(period).local_town.child_allowance.amount + nb_children = family.nb_persons(role=Household.CHILD) + amount_by_child = params(period).local_town.child_allowance.amount return nb_children * amount_by_child diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 5ea3994..0000000 --- a/setup.cfg +++ /dev/null @@ -1,48 +0,0 @@ -; D101: Variables already provide label/description -; D107: We do not document __init__ method -; D401: We do not require the imperative mood -; E128/133: We prefer hang-closing visual indents -; E251: We prefer `function(x = 1)` over `function(x=1)` -; E501: We do not enforce a maximum line length -; W503/4: We break lines before binary operators (Knuth's style) - -[flake8] -hang-closing = true -ignore = D101,D107,D401,E128,E251,E501,W503 -in-place = true -inline-quotes = " -multiline-quotes = """ -no-accept-encodings = true -import-order-style = appnexus -application-import-names = openfisca_extension_template -application-package-names = openfisca_core,openfisca_country_template - -; C0103: We (still) snake case variables and reforms -; C0115: Variables already provide label/description -; C0301: We do not enforce a maximum line length -; E0213: This requires changes in OpenFisca-Core -; E1101: False positive, as entities have members -; E1102: False positive, as entities are callable -; W0621: We name variable values the variable name -; W1203: We prefer to log with f-strings - -[pylint.message_control] -disable = C0103,C0115,C0301,E0213,E1101,E1102,W0621,W1203 -score = no - -[isort] -case_sensitive = true -group_by_package = true -include_trailing_comma = true -known_first_party = openfisca_extension_template -known_openfisca = openfisca_core, openfisca_country_template -known_typing = mypy*, *types*, *typing* -multi_line_output = 8 -py_version = 37 -sections = FUTURE,TYPING,STDLIB,THIRDPARTY,OPENFISCA,FIRSTPARTY,LOCALFOLDER - -[tool:pytest] -addopts = --showlocals --exitfirst --doctest-modules -testpaths = openfisca_extension_template/tests -python_files = **/*.py -filterwarnings = ignore::DeprecationWarning diff --git a/setup.py b/setup.py deleted file mode 100644 index 625a4f3..0000000 --- a/setup.py +++ /dev/null @@ -1,64 +0,0 @@ -"""This file contains your extension package's metadata and dependencies.""" - -from pathlib import Path - -from setuptools import find_packages, setup - -# Read the contents of our README file for PyPi -this_directory = Path(__file__).parent -long_description = (this_directory / "README.md").read_text() # pylint: disable=W1514 - -setup( - name = "OpenFisca-Extension-Template", - version = "1.3.14", - author = "OpenFisca Team", - author_email = "contact@openfisca.org", - classifiers = [ - "Development Status :: 5 - Production/Stable", - "License :: OSI Approved :: GNU Affero General Public License v3", - "Operating System :: POSIX", - "Programming Language :: Python", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Topic :: Scientific/Engineering :: Information Analysis", - ], - description = "An OpenFisca extension that adds some variables to an already-existing tax and benefit system", - long_description=long_description, - long_description_content_type="text/markdown", - keywords = "benefit microsimulation social tax", - license = "http://www.fsf.org/licensing/licenses/agpl-3.0.html", - license_files = ("LICENSE",), - url = "https://github.com/openfisca/extension-template", - include_package_data = True, # Will read MANIFEST.in - data_files = [ - ("share/openfisca/openfisca-extension-template", ["CHANGELOG.md", "README.md"]), - ], - install_requires = [ - "OpenFisca-Country-Template >= 5.0.0, < 6", - ], - extras_require = { - "dev": [ - "autopep8 >= 1.5.4, < 2.0.0", - "flake8 >= 3.8.0, < 4.0.0", - "flake8-bugbear >= 20.1.0, < 22.0.0", - "flake8-builtins >= 1.5.0, < 2.0.0", - "flake8-coding >= 1.3.0, < 2.0.0", - "flake8-commas >= 2.0.0, < 3.0.0", - "flake8-comprehensions >= 3.2.0, < 4.0.0", - "flake8-docstrings >= 1.5.0, < 2.0.0", - "flake8-import-order >= 0.18.0, < 1.0.0", - "flake8-print >= 3.1.0, < 5.0.0", - "flake8-quotes >= 3.2.0, < 4.0.0", - "flake8-simplify >= 0.9.0, < 1.0.0", - "flake8-use-fstring >= 1.1.0, < 2.0.0", - "importlib-metadata < 4.3.0", - "isort >= 5.10.0, < 6.0.0", - "pycodestyle >= 2.7.0, < 2.8.0", - "pylint >= 2.6.0, < 3.0.0", - "pyupgrade >= 3.2.0, < 4.0.0", - ], - }, - packages = find_packages(), - ) From 56f430ab87463104671ff549ce94a2d86161eb1c Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 29 Sep 2024 22:40:26 +0200 Subject: [PATCH 15/23] build(setup): add pyproject.toml --- pyproject.toml | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f182f85 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,91 @@ +[build-system] +requires = ["setuptools >= 61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "openfisca-extension_template" +version = "1.3.14" +dependencies = [ + "openfisca-country-template >=7.1.4, <8.0" +] +requires-python = ">=3.9" +authors = [{name = "OpenFisca Team", email = "contact@openfisca.org"}] +maintainers = [{name = "OpenFisca Team", email = "contact@openfisca.org"}] +description = "An OpenFisca extension that adds some variables to an already-existing tax and benefit system." +readme = "README.md" +license = {file = "LICENSE"} +keywords = ["microsimulation", "tax", "benefit", "rac", "rules-as-code"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Operating System :: POSIX", + "Programming Language :: Python", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Topic :: Scientific/Engineering :: Information Analysis", +] + +[project.optional-dependencies] +dev = [ + "black >=24.8.0, <25.0", + "isort >=5.13.2, <6.0", + "ruff >=0.6.7, <1.0", + "ruff-lsp >=0.0.57, <1.0", + "yamllint >=1.35.1" +] + +[project.urls] +Homepage = "https://github.com/openfisca/extension-template" +Repository = "https://github.com/openfisca/extension-template" +Documentation = "https://openfisca.org/doc" +Issues = "https://github.com/openfisca/extension-template/issues" +Changelog = "https://github.com/openfisca/extension-template/blob/main/CHANGELOG.md" + +[tool.black] +target_version = ["py39", "py310", "py311"] + +[tool.isort] +case_sensitive = true +combine_as_imports = true +force_alphabetical_sort_within_sections = false +group_by_package = true +honor_noqa = true +include_trailing_comma = true +known_first_party = ["openfisca_extension_template"] +known_openfisca = ["openfisca_core", "openfisca_country_template"] +known_typing = ["*collections.abc*", "*typing*", "*typing_extensions*"] +known_types = ["*types*"] +multi_line_output = 3 +profile = "black" +py_version = 39 +sections = [ + "FUTURE", + "TYPING", + "TYPES", + "STDLIB", + "THIRDPARTY", + "OPENFISCA", + "FIRSTPARTY", + "LOCALFOLDER", +] + +[tool.pytest.ini_options] +addopts = "--exitfirst --showlocals --doctest-modules" +testpaths = [ "openfisca_extension_template/tests" ] +python_files = "**/*.py" +filterwarnings = ["ignore::DeprecationWarning"] + +[tool.ruff] +target-version = "py39" + +[tool.ruff.format] +docstring-code-format = true +docstring-code-line-length = 72 + +[tool.ruff.lint] +ignore = ["COM812", "D101", "ISC001", "N801", "N805"] +select = ["ALL"] + +[tool.ruff.lint.pydocstyle] +convention = "google" From 74d7dab0c7f5ec75097bf7fa8cf140fff16c52b2 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 29 Sep 2024 22:41:08 +0200 Subject: [PATCH 16/23] build(setup): fix manifest.in --- MANIFEST.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index bf7af33..eb5f06a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ -recursive-include openfisca_extension_template * +graft openfisca_extension_template +global-exclude *~ *.py[cod] *.so From 12228df6338d700ef83a902826195e05b45e10eb Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 29 Sep 2024 22:41:49 +0200 Subject: [PATCH 17/23] build(make): fix openfisca test --- Makefile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 4b15cb9..f361de1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: test uninstall: - pip freeze | grep -v "^-e" | xargs pip uninstall -y + pip freeze | grep -v "^-e" | sed "s/@.*//" | xargs pip uninstall -y clean: rm -rf build dist @@ -30,17 +30,19 @@ check-syntax-errors: format-style: @# Do not analyse .gitignored files. @# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764. + ruff format `git ls-files | grep "\.py$$"` isort `git ls-files | grep "\.py$$"` - autopep8 `git ls-files | grep "\.py$$"` - pyupgrade `git ls-files | grep "\.py$$"` --py37-plus + black `git ls-files | grep "\.py$$"` check-style: @# Do not analyse .gitignored files. @# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764. - flake8 `git ls-files | grep "\.py$$"` - pylint `git ls-files | grep "\.py$$"` + ruff check `git ls-files | grep "\.py$$"` + isort --check `git ls-files | grep "\.py$$"` + black --check `git ls-files | grep "\.py$$"` test: clean check-syntax-errors check-style - openfisca test openfisca_extension_template/tests \ - --country-package openfisca_country_template \ - --extensions openfisca_extension_template + openfisca test \ + --country-package=openfisca_country_template \ + --extensions=openfisca_extension_template \ + openfisca_extension_template/tests From 3257c63e0df9e4713f19f62a496b990f9c1263ec Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 29 Sep 2024 22:42:23 +0200 Subject: [PATCH 18/23] style(lint): fix --- openfisca_extension_template/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openfisca_extension_template/__init__.py b/openfisca_extension_template/__init__.py index c2526d0..cf6a105 100644 --- a/openfisca_extension_template/__init__.py +++ b/openfisca_extension_template/__init__.py @@ -1,5 +1,4 @@ -""" -This package defines a country package extension. +"""This package defines a country package extension. Extensions allow you to define new variables or parameters for a tax and benefit system, while keeping their code separated from the main country @@ -7,5 +6,7 @@ They are for instance used to code local taxes and benefits. -See https://openfisca.org/doc/contribute/extensions.html +See: + https://openfisca.org/doc/contribute/extensions.html + """ From 265cbb9850bcb8265cc30e28f305418638146359 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 29 Sep 2024 23:07:37 +0200 Subject: [PATCH 19/23] ci: update to py39 --- .github/workflows/workflow.yml | 88 +++++++++++++++++----------------- pyproject.toml | 2 +- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index a5cd1d2..81912ae 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -9,102 +9,100 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: 3.7.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any potentiel difference in patches between jobs will lead to a cache not found error. + python-version: 3.9.13 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any potentiel difference in patches between jobs will lead to a cache not found error. - name: Cache build id: restore-build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} # Cache the entire build Python environment + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} # Cache the entire build Python environment restore-keys: | - build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }} + build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }} build-${{ env.pythonLocation }}- - name: Build package run: make build - name: Cache release id: restore-release - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: dist - key: release-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} lint-files: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ build ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all the tags - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: 3.7.12 + python-version: 3.9.13 - name: Cache build id: restore-build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - run: make check-syntax-errors - run: make check-style - - name: Lint Python files - run: "${GITHUB_WORKSPACE}/.github/lint-changed-python-files.sh" - name: Lint YAML tests run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh" test-yaml: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ build ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: 3.7.12 + python-version: 3.9.13 - name: Cache build id: restore-build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - run: openfisca test openfisca_extension_template/tests --country-package openfisca_country_template --extensions openfisca_extension_template test-api: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ build ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: 3.7.12 + python-version: 3.9.13 - name: Cache build id: restore-build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - name: Test the Web API run: "${GITHUB_WORKSPACE}/.github/test-api.sh" check-version-and-changelog: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ lint-files, test-yaml, test-api ] # Last job to run steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all the tags - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: 3.7.12 + python-version: 3.9.13 - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" @@ -112,46 +110,46 @@ jobs: # We build a separate job to substitute the halt option. # The `deploy` job is dependent on the output of the `check-for-functional-changes`job. check-for-functional-changes: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch needs: [ check-version-and-changelog ] outputs: status: ${{ steps.stop-early.outputs.status }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all the tags - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: 3.7.12 + python-version: 3.9.13 - id: stop-early run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi deploy: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ check-for-functional-changes ] if: needs.check-for-functional-changes.outputs.status == 'success' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all the tags - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: 3.7.12 + python-version: 3.9.13 - name: Cache build id: restore-build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - name: Cache release id: restore-release - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: dist - key: release-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - name: Upload a Python package to PyPi run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} - name: Publish a git tag diff --git a/pyproject.toml b/pyproject.toml index f182f85..4b5e9dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,7 +84,7 @@ docstring-code-format = true docstring-code-line-length = 72 [tool.ruff.lint] -ignore = ["COM812", "D101", "ISC001", "N801", "N805"] +ignore = ["COM812", "D101", "D104", "ISC001", "N801", "N805"] select = ["ALL"] [tool.ruff.lint.pydocstyle] From 08b401b8927e2492ce5a0eb44e91b7a95eb8295c Mon Sep 17 00:00:00 2001 From: Mauko Quiroga-Alvarado Date: Mon, 30 Sep 2024 11:49:22 +0000 Subject: [PATCH 20/23] chore: remove types from local_benefit.py --- openfisca_extension_template/variables/local_benefit.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openfisca_extension_template/variables/local_benefit.py b/openfisca_extension_template/variables/local_benefit.py index 1cbe984..a61276b 100644 --- a/openfisca_extension_template/variables/local_benefit.py +++ b/openfisca_extension_template/variables/local_benefit.py @@ -7,8 +7,6 @@ """ -from openfisca_core import types as t - # Import the openfisca-core objects used to code the legislation in OpenFisca. from openfisca_core.periods import MONTH from openfisca_core.variables import Variable @@ -23,7 +21,7 @@ class local_town_child_allowance(Variable): definition_period = MONTH label = "Local benefit: a fixed amount by child each month" - def formula(family: t.Population, period: t.Instant, params: t.Params) -> t.Array: + def formula(family, period, parameters): """Local benefit. Extensions can only add variables and parameters to the tax and benefit From a21dbbb02cf6170d54eafe9981d49db972624d7e Mon Sep 17 00:00:00 2001 From: Mauko Quiroga-Alvarado Date: Mon, 30 Sep 2024 13:12:30 +0000 Subject: [PATCH 21/23] docs: fix params --- openfisca_extension_template/variables/local_benefit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openfisca_extension_template/variables/local_benefit.py b/openfisca_extension_template/variables/local_benefit.py index a61276b..2f5d2dd 100644 --- a/openfisca_extension_template/variables/local_benefit.py +++ b/openfisca_extension_template/variables/local_benefit.py @@ -27,15 +27,15 @@ def formula(family, period, parameters): Extensions can only add variables and parameters to the tax and benefit system: they cannot modify or neutralize existing ones. - Parameters: + Args: family: a population of entities. period: an `Instant` to calculate the variable. - params: a bounded function to query for model's parameters. + parameters: a bounded function to query for model's parameters. Returns: A vector with the corresponding values per entity. """ nb_children = family.nb_persons(role=Household.CHILD) - amount_by_child = params(period).local_town.child_allowance.amount + amount_by_child = parameters(period).local_town.child_allowance.amount return nb_children * amount_by_child From efb344d8ef2bb0c70def09e742abf048c7e3e67a Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 30 Sep 2024 15:43:06 +0200 Subject: [PATCH 22/23] style(lint): fix --- .github/lint-changed-python-files.sh | 11 ----------- pyproject.toml | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100755 .github/lint-changed-python-files.sh diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh deleted file mode 100755 index 72d8aad..0000000 --- a/.github/lint-changed-python-files.sh +++ /dev/null @@ -1,11 +0,0 @@ -#! /usr/bin/env bash - -last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit - -if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py") -then - echo "Linting the following Python files:" - echo $changes - flake8 $changes -else echo "No changed Python files to lint" -fi diff --git a/pyproject.toml b/pyproject.toml index 4b5e9dc..8fc3ac6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,7 +84,7 @@ docstring-code-format = true docstring-code-line-length = 72 [tool.ruff.lint] -ignore = ["COM812", "D101", "D104", "ISC001", "N801", "N805"] +ignore = ["ANN", "COM812", "D101", "D104", "ISC001", "N801", "N805"] select = ["ALL"] [tool.ruff.lint.pydocstyle] From 2e148b4c6bdd557a51ea6fafa15b14a48e326547 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 29 Sep 2024 22:49:59 +0200 Subject: [PATCH 23/23] chore: version bump Fixes #56 * Crash fix * Details: - Add pyproject.toml - Fix variables not being loaded - Upgrade country-template to latest --- CHANGELOG.md | 8 ++++++++ pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 161c058..66c724d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +### 1.3.15 - [#57](https://github.com/openfisca/extension-template/pull/57) + +* Crash fix. +* Details: + - Add pyproject.toml + - Fix variables not being loaded + - Upgrade country-template to latest + ### 1.3.14 - [#55](https://github.com/openfisca/extension-template/pull/55) * Technical improvement. diff --git a/pyproject.toml b/pyproject.toml index 8fc3ac6..0ecfa8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "openfisca-extension_template" -version = "1.3.14" +version = "1.3.15" dependencies = [ "openfisca-country-template >=7.1.4, <8.0" ]