Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: broken build #57

Merged
merged 10 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/lint-changed-python-files.sh

This file was deleted.

88 changes: 43 additions & 45 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,149 +9,147 @@ 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"

# GitHub Actions does not have a halt job option, to stop from deploying if no functional changes were found.
# 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
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
recursive-include openfisca_extension_template *
graft openfisca_extension_template
global-exclude *~ *.py[cod] *.so
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions openfisca_extension_template/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""
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
package.

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

"""
Empty file.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""
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
# 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


Expand All @@ -19,20 +21,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, period, parameters):
"""Local benefit.

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.
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)
nb_children = family.nb_persons(role=Household.CHILD)
amount_by_child = parameters(period).local_town.child_allowance.amount
return nb_children * amount_by_child
Loading