From 9325949a0738d5e62f8e47c80813bf706568f93c Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Wed, 24 Apr 2024 17:20:25 +0545 Subject: [PATCH 01/92] Update references to setup.py in CI workflow --- .github/is-version-number-acceptable.sh | 4 ++-- .github/publish-git-tag.sh | 3 ++- .github/workflows/workflow.yml | 16 ++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/is-version-number-acceptable.sh b/.github/is-version-number-acceptable.sh index 605f8373..3827db06 100755 --- a/.github/is-version-number-acceptable.sh +++ b/.github/is-version-number-acceptable.sh @@ -12,14 +12,14 @@ then exit 0 fi -current_version=$(python setup.py --version) +current_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273 if git rev-parse --verify --quiet $current_version then echo "Version $current_version already exists in commit:" git --no-pager log -1 $current_version echo - echo "Update the version number in setup.py before merging this branch into main." + echo "Update the version number in pyproject.toml before merging this branch into main." echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated." exit 1 fi diff --git a/.github/publish-git-tag.sh b/.github/publish-git-tag.sh index ea0eb489..f60b980c 100755 --- a/.github/publish-git-tag.sh +++ b/.github/publish-git-tag.sh @@ -1,4 +1,5 @@ #! /usr/bin/env bash -git tag $(python setup.py --version) +current_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273 +git tag $current_version git push --tags # update the repository version diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index fb130179..f1567106 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -22,9 +22,9 @@ jobs: uses: actions/cache@v2 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 @@ -33,7 +33,7 @@ jobs: uses: actions/cache@v2 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 @@ -51,7 +51,7 @@ jobs: uses: actions/cache@v2 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 @@ -73,7 +73,7 @@ jobs: uses: actions/cache@v2 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 --country-package openfisca_country_template openfisca_country_template/tests test-api: @@ -90,7 +90,7 @@ jobs: uses: actions/cache@v2 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" @@ -148,13 +148,13 @@ jobs: uses: actions/cache@v2 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 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 $PYPI_USERNAME --password $PYPI_PASSWORD - name: Publish a git tag From fd46d00fbf24a8539cc931d805be2c533f801807 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Wed, 24 Apr 2024 17:21:24 +0545 Subject: [PATCH 02/92] Make errors in finding current version visible Was silent in https://github.com/openfisca/country-template/actions/runs/8810580013, which led to failed merge in https://github.com/openfisca/country-template/pull/139 --- .github/is-version-number-acceptable.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/is-version-number-acceptable.sh b/.github/is-version-number-acceptable.sh index 3827db06..0c86be5b 100755 --- a/.github/is-version-number-acceptable.sh +++ b/.github/is-version-number-acceptable.sh @@ -14,6 +14,12 @@ fi current_version=$(grep '^version =' pyproject.toml | cut -d '"' -f 2) # parsing with tomllib is complicated, see https://github.com/python-poetry/poetry/issues/273 +if [[ ! $current_version ]] +then + echo "Error getting current version" + exit 1 +fi + if git rev-parse --verify --quiet $current_version then echo "Version $current_version already exists in commit:" @@ -21,7 +27,7 @@ then echo echo "Update the version number in pyproject.toml before merging this branch into main." echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated." - exit 1 + exit 2 fi if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md From b4f3f5e5c46bba549439767c263d84f013ebc188 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Wed, 24 Apr 2024 17:44:15 +0545 Subject: [PATCH 03/92] Support detecting changes without git tag Upon initial setup, there might be no tag This entails a risk when a merge to main is made without a tag, but this is a workflow failure that is not supposed to happen --- .github/has-functional-changes.sh | 4 +--- .github/lint-changed-python-files.sh | 8 +++----- .github/lint-changed-yaml-tests.sh | 8 +++----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/has-functional-changes.sh b/.github/has-functional-changes.sh index 61a232da..d44b37d0 100755 --- a/.github/has-functional-changes.sh +++ b/.github/has-functional-changes.sh @@ -2,9 +2,7 @@ IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore .github/*" -last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent) # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit - -if git diff-index --name-only --exit-code $last_tagged_commit -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published. +if git diff-index --name-only --exit-code main -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published. then echo "No functional changes detected." exit 1 diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh index b27a8925..9069a2bc 100755 --- a/.github/lint-changed-python-files.sh +++ b/.github/lint-changed-python-files.sh @@ -1,11 +1,9 @@ #! /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 main through an unlikely intermediary merge commit - -if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py") +if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code main -- "*.py") then echo "Linting the following Python files:" - echo $changes - flake8 $changes + echo $changed_files + flake8 $changed_files else echo "No changed Python files to lint" fi diff --git a/.github/lint-changed-yaml-tests.sh b/.github/lint-changed-yaml-tests.sh index 6c0124c8..4019fb36 100755 --- a/.github/lint-changed-yaml-tests.sh +++ b/.github/lint-changed-yaml-tests.sh @@ -1,11 +1,9 @@ #! /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 main through an unlikely intermediary merge commit - -if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "tests/*.yaml") +if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code main -- "tests/*.yaml") then echo "Linting the following changed YAML tests:" - echo $changes - yamllint $changes + echo $changed_files + yamllint $changed_files else echo "No changed YAML tests to lint" fi From 30b6985e196c260c226ab0a5f5ede77b24eacfb3 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Wed, 24 Apr 2024 20:30:16 +0545 Subject: [PATCH 04/92] Check changes compared to last tagged version Ensure that a first version is tagged --- .github/has-functional-changes.sh | 4 +++- .github/lint-changed-python-files.sh | 4 +++- .github/lint-changed-yaml-tests.sh | 4 +++- bootstrap.sh | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/has-functional-changes.sh b/.github/has-functional-changes.sh index d44b37d0..01db9ee5 100755 --- a/.github/has-functional-changes.sh +++ b/.github/has-functional-changes.sh @@ -2,7 +2,9 @@ IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore .github/*" -if git diff-index --name-only --exit-code main -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published. +last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit + +if git diff-index --name-only --exit-code $last_tagged_commit -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published. then echo "No functional changes detected." exit 1 diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh index 9069a2bc..b7456772 100755 --- a/.github/lint-changed-python-files.sh +++ b/.github/lint-changed-python-files.sh @@ -1,6 +1,8 @@ #! /usr/bin/env bash -if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code main -- "*.py") +last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit + +if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py") then echo "Linting the following Python files:" echo $changed_files diff --git a/.github/lint-changed-yaml-tests.sh b/.github/lint-changed-yaml-tests.sh index 4019fb36..9e2ab562 100755 --- a/.github/lint-changed-yaml-tests.sh +++ b/.github/lint-changed-yaml-tests.sh @@ -1,6 +1,8 @@ #! /usr/bin/env bash -if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code main -- "tests/*.yaml") +last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit + +if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "tests/*.yaml") then echo "Linting the following changed YAML tests:" echo $changed_files diff --git a/bootstrap.sh b/bootstrap.sh index 477af7d7..ba3a4c22 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -104,7 +104,9 @@ git rm bootstrap.sh > /dev/null 2>&1 git add . git commit --no-gpg-sign --message "$second_commit_message" --author='OpenFisca Bot ' --quiet -echo -e "${PURPLE}* ${PURPLE}Second git commit made to 'main' branch: '\033[0m${BLUE}$second_commit_message\033[0m${PURPLE}'\033[0m" +git tag "0.0.1" + +echo -e "${PURPLE}* ${PURPLE}Second commit and first tag made on 'main' branch: '\033[0m${BLUE}$second_commit_message\033[0m${PURPLE}'\033[0m" echo echo -e "${YELLOW}* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \033[0m" From 2c70fce0c1bdf22dda6125fcc3468b2e6e0a707e Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Wed, 24 Apr 2024 20:30:25 +0545 Subject: [PATCH 05/92] Update version number on initial setup --- bootstrap.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bootstrap.sh b/bootstrap.sh index ba3a4c22..31ef96ac 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -92,7 +92,8 @@ sed -i.template -e "1,${last_changelog_number}d" CHANGELOG.md # remove country- echo -e "${PURPLE}* ${PURPLE}Prepare \033[0m${BLUE}pyproject.toml\033[0m" sed -i.template "s|https://github.com/openfisca/country-template|$REPOSITORY_URL|g" pyproject.toml -sed -i.template "s|:: 5 - Production/Stable|:: 1 - Planning|g" pyproject.toml +sed -i.template 's|:: 5 - Production/Stable|:: 1 - Planning|g' pyproject.toml +sed -i.template 's|^version = "[0-9.]*"|version = "0.0.1"|g' pyproject.toml sed -i.template "s|repository_folder|$REPOSITORY_FOLDER|g" README.md find . -name "*.template" -type f -delete From 25f6f8522be73e7c63926932c8f4c2b170341ef5 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 24 Apr 2024 15:00:49 +0200 Subject: [PATCH 06/92] Allow to bypass steps on CI with `CI` env variable --- bootstrap.sh | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 31ef96ac..712a5cab 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -12,7 +12,7 @@ if [[ $JURISDICTION_NAME ]] && [[ $REPOSITORY_URL ]] then continue=Y fi -if [[ -d .git ]] +if [[ $CI ]] && [ ! -d .git ] then echo 'It seems you cloned this repository, or already initialised it.' echo 'Refusing to go further as you might lose work.' @@ -62,17 +62,20 @@ last_changelog_number=$(grep --line-number '^# Example Entry' CHANGELOG.md | cut first_commit_message='Initial import from OpenFisca country-template' second_commit_message='Customise country-template through script' -echo -cd .. -mv $parent_folder openfisca-$NO_SPACES_JURISDICTION_LABEL -cd openfisca-$NO_SPACES_JURISDICTION_LABEL +if [[ ! "$CI" ]] +then + echo + cd .. + mv $parent_folder openfisca-$NO_SPACES_JURISDICTION_LABEL + cd openfisca-$NO_SPACES_JURISDICTION_LABEL -echo -e "${PURPLE}* ${PURPLE}Initialise git repository\033[0m" -git init --initial-branch=main > /dev/null 2>&1 -git add . + echo -e "${PURPLE}* ${PURPLE}Initialise git repository\033[0m" + git init --initial-branch=main > /dev/null 2>&1 + git add . -git commit --no-gpg-sign --message "$first_commit_message" --author='OpenFisca Bot ' --quiet -echo -e "${PURPLE}* ${PURPLE}Initial git commit made to 'main' branch: '\033[0m${BLUE}$first_commit_message\033[0m${PURPLE}'\033[0m" + git commit --no-gpg-sign --message "$first_commit_message" --author='OpenFisca Bot ' --quiet + echo -e "${PURPLE}* ${PURPLE}Initial git commit made to 'main' branch: '\033[0m${BLUE}$first_commit_message\033[0m${PURPLE}'\033[0m" +fi all_module_files=`find openfisca_country_template -type f ! -name "*.DS_Store"` echo -e "${PURPLE}* ${PURPLE}Replace default country_template references\033[0m" @@ -102,6 +105,12 @@ git mv openfisca_country_template $package_name echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}bootstrap.sh\033[0m${PURPLE} script\033[0m" git rm bootstrap.sh > /dev/null 2>&1 + +if [[ $CI ]] +then + exit 0 +fi + git add . git commit --no-gpg-sign --message "$second_commit_message" --author='OpenFisca Bot ' --quiet From c29c9036e85b8d4cd17bde8f009a71e149de9576 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 24 Apr 2024 15:04:08 +0200 Subject: [PATCH 07/92] Avoid modifying main workflow in bootstrap script --- .github/workflows/workflow.yml | 4 ++-- bootstrap.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f1567106..f105400c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,4 +1,4 @@ -name: Country-Template +name: CI/CD Pipeline on: push: @@ -74,7 +74,7 @@ jobs: with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - run: openfisca test --country-package openfisca_country_template openfisca_country_template/tests + - run: make test test-api: runs-on: ubuntu-20.04 diff --git a/bootstrap.sh b/bootstrap.sh index 712a5cab..e65a1b23 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -81,8 +81,8 @@ all_module_files=`find openfisca_country_template -type f ! -name "*.DS_Store"` echo -e "${PURPLE}* ${PURPLE}Replace default country_template references\033[0m" # Use intermediate backup files (`-i`) with a weird syntax due to lack of portable 'no backup' option. See https://stackoverflow.com/q/5694228/594053. sed -i.template "s|openfisca-country_template|openfisca-$NO_SPACES_JURISDICTION_LABEL|g" README.md Makefile pyproject.toml CONTRIBUTING.md -sed -i.template "s|country_template|$SNAKE_CASE_JURISDICTION|g" README.md pyproject.toml .flake8 .github/workflows/workflow.yml Makefile MANIFEST.in $all_module_files -sed -i.template "s|Country-Template|$JURISDICTION_NAME|g" README.md pyproject.toml .github/workflows/workflow.yml .github/PULL_REQUEST_TEMPLATE.md CONTRIBUTING.md +sed -i.template "s|country_template|$SNAKE_CASE_JURISDICTION|g" README.md pyproject.toml .flake8 Makefile MANIFEST.in $all_module_files +sed -i.template "s|Country-Template|$JURISDICTION_NAME|g" README.md pyproject.toml .github/PULL_REQUEST_TEMPLATE.md CONTRIBUTING.md echo -e "${PURPLE}* ${PURPLE}Remove bootstrap instructions\033[0m" sed -i.template -e "3,${last_bootstrapping_line_number}d" README.md # remove instructions lines From 5f54fae1f2e47161ed35e53d8d3154e4921b9d5e Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 24 Apr 2024 15:10:32 +0200 Subject: [PATCH 08/92] Perform bootstrapping when used as GitHub template --- .github/workflows/bootstrap.yml | 31 +++++++++++++++++++++++++++++++ .github/workflows/workflow.yml | 2 +- bootstrap.sh | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/bootstrap.yml diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/bootstrap.yml new file mode 100644 index 00000000..3d2c4af7 --- /dev/null +++ b/.github/workflows/bootstrap.yml @@ -0,0 +1,31 @@ +name: Bootstrap + +on: + create: + +permissions: + actions: write + checks: write + contents: write + +jobs: + bootstrap: + # Ensure this job does not run on the template repository or when the repository is forked + if: ${{ !github.event.repository.is_template && !github.event.repository.fork }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Execute the bootstrap script + run: CI=true JURISDICTION_NAME="$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//')" REPOSITORY_URL="${{ github.repositoryUrl }}" ./bootstrap.sh + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Adapt template automatically" + tagging_message: "0.0.1" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f105400c..164a454d 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,4 +1,4 @@ -name: CI/CD Pipeline +name: CI and CD Pipeline on: push: diff --git a/bootstrap.sh b/bootstrap.sh index e65a1b23..1b29b9f0 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -106,6 +106,9 @@ git mv openfisca_country_template $package_name echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}bootstrap.sh\033[0m${PURPLE} script\033[0m" git rm bootstrap.sh > /dev/null 2>&1 +echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}bootstrap.yml\033[0m${PURPLE} GitHub Action\033[0m" +rm -f .github/workflows/bootstrap.yml + if [[ $CI ]] then exit 0 From 176574b8acca5841e948fc60ea5c62c6dcd8cee1 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 24 Apr 2024 15:27:39 +0200 Subject: [PATCH 09/92] Use a less technical naming for better accessibility --- .github/workflows/{bootstrap.yml => first-time-setup.yml} | 8 ++++---- bootstrap.sh => first-time-setup.sh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename .github/workflows/{bootstrap.yml => first-time-setup.yml} (85%) rename bootstrap.sh => first-time-setup.sh (95%) diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/first-time-setup.yml similarity index 85% rename from .github/workflows/bootstrap.yml rename to .github/workflows/first-time-setup.yml index 3d2c4af7..141e57dd 100644 --- a/.github/workflows/bootstrap.yml +++ b/.github/workflows/first-time-setup.yml @@ -1,4 +1,4 @@ -name: Bootstrap +name: First time setup on: create: @@ -9,7 +9,7 @@ permissions: contents: write jobs: - bootstrap: + first-time-setup: # Ensure this job does not run on the template repository or when the repository is forked if: ${{ !github.event.repository.is_template && !github.event.repository.fork }} runs-on: ubuntu-latest @@ -19,8 +19,8 @@ jobs: with: repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Execute the bootstrap script - run: CI=true JURISDICTION_NAME="$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//')" REPOSITORY_URL="${{ github.repositoryUrl }}" ./bootstrap.sh + - name: Execute the first-time-setup script + run: CI=true JURISDICTION_NAME="$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//')" REPOSITORY_URL="${{ github.repositoryUrl }}" ./first-time-setup.sh - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/bootstrap.sh b/first-time-setup.sh similarity index 95% rename from bootstrap.sh rename to first-time-setup.sh index 1b29b9f0..8f58de77 100755 --- a/bootstrap.sh +++ b/first-time-setup.sh @@ -103,11 +103,11 @@ find . -name "*.template" -type f -delete echo -e "${PURPLE}* ${PURPLE}Rename package to: \033[0m${BLUE}$package_name\033[0m" git mv openfisca_country_template $package_name -echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}bootstrap.sh\033[0m${PURPLE} script\033[0m" -git rm bootstrap.sh > /dev/null 2>&1 +echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.sh\033[0m${PURPLE} script\033[0m" +git rm first-time-setup.sh > /dev/null 2>&1 -echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}bootstrap.yml\033[0m${PURPLE} GitHub Action\033[0m" -rm -f .github/workflows/bootstrap.yml +echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.yml\033[0m${PURPLE} GitHub Action\033[0m" +rm -f .github/workflows/first-time-setup.yml if [[ $CI ]] then From 668beab90d49028f11b81d401d3c88a64010180b Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 24 Apr 2024 15:11:34 +0200 Subject: [PATCH 10/92] Update documentation --- README.md | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c675bbfc..ff9333bb 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,37 @@ # OpenFisca Country-Template -This repository helps you quickly bootstrap and use your own OpenFisca country package. +This repository helps you quickly set up and use your own OpenFisca country package. -**You should NOT fork it but [download a copy](https://github.com/openfisca/country-template/archive/master.zip) of it** and follow the bootstrapping instructions below. +**You should NOT fork it** but follow the set up instructions below. > Otherwise, you will have to clean up all tags when you deploy your own country package. -## Bootstrapping your Country Package +## Setting up your Country Package This set of instructions **only needs to be followed once** and will create your own copy of this boilerplate directory, customising it to the country you want to work on. You will need to have [Git](https://git-scm.com) installed. -1. [Download a copy](https://github.com/openfisca/country-template/archive/master.zip) of this repository, unzip it and `cd` into it in a Terminal window. +### Using GitHub (recommended for GitHub users) + +1. Click on the “Use this template” dropdown and select “Create a new repository” -2. Create a new repository on your favourite git host (Github, Bitbucket, GitLab, etc) with the name openfisca-your_country_name. For example, `openfisca-new_zealand` or `openfisca-france`. +2. Set the repository name to `openfisca-`. For example, `openfisca-new_zealand` or `openfisca-france`. -3. Execute the `bootstrap.sh` script to initialise the git repository. This performs numerous tasks including replacing all references to `openfisca-country_template` with references to the new country package. - - To execute the script run `bash bootstrap.sh` from the command line. _Note: this script can only run on Unix systems, but OpenFisca and the resulting package will work on Windows too._ - - After the `bootstrap.sh` has run both it and these instructions are removed. +3. Wait a minute or two for the automatic setup to run after being redirected to the newly generated repository. Once done, the title of the readme should be `OpenFisca `. 4. Follow the instructions in the new repository's README.md. +### Manual setup (recommended for users of other Git hosts) + +1. [Download a copy](https://github.com/openfisca/country-template/archive/master.zip) of this repository, unzip it and `cd` into it in a Terminal window. + +2. Create a new repository on your favourite git host (Bitbucket, GitLab, …) with the name `openfisca-`. For example, `openfisca-new_zealand` or `openfisca-france`. + +3. Execute the `first-time-setup.sh` script to initialise the git repository. This performs numerous tasks including replacing all references to `openfisca-country_template` with references to the new country package. + - To execute the script run `bash first-time-setup.sh` from the command line + - After the `first-time-setup.sh` has run both it and these instructions are removed. + +4. Follow the instructions in the new repository's `README.md.` + ## Writing the Legislation The country whose law is modelled here has a very simple tax and benefit system. From 00260ce156e686437866d62f0059e45139bbb86b Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 11:45:56 +0200 Subject: [PATCH 11/92] Unify commit message with first-time-setup script --- .github/workflows/first-time-setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/first-time-setup.yml b/.github/workflows/first-time-setup.yml index 141e57dd..d18fbf28 100644 --- a/.github/workflows/first-time-setup.yml +++ b/.github/workflows/first-time-setup.yml @@ -25,7 +25,7 @@ jobs: - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 with: - commit_message: "Adapt template automatically" + commit_message: "Customise country-template through CI" tagging_message: "0.0.1" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 4361f2a5e2484fc953bd7c97b7516122b622fbed Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 11:04:42 +0200 Subject: [PATCH 12/92] Decompose monolithic workflow into specialized workflows --- .github/workflows/build.yml | 33 +++++++ .github/workflows/deploy.yml | 63 +++++++++++++ .github/workflows/validate.yml | 85 +++++++++++++++++ .github/workflows/workflow.yml | 161 --------------------------------- 4 files changed, 181 insertions(+), 161 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/validate.yml delete mode 100644 .github/workflows/workflow.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..633e343d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,33 @@ +name: Build + +on: + workflow_call: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 # 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 + with: + path: ${{ env.pythonLocation }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} # Cache the entire build Python environment + restore-keys: | + 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 + with: + path: dist + key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..65fb0d30 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,63 @@ +name: Deploy + +on: + pull_request_target: + branches: + - main + types: [ closed ] + + +jobs: + validate: + uses: "./.github/workflows/validate.yml" + + # 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 + if: github.ref == 'refs/heads/main' # Only triggered for the `main` branch + outputs: + status: ${{ steps.stop-early.outputs.status }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - 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 + needs: [ validate, check-for-functional-changes ] + if: github.event.pull_request.merged == true && needs.check-for-functional-changes.outputs.status == 'success' + env: + PYPI_USERNAME: openfisca-bot + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + - name: Cache release + id: restore-release + uses: actions/cache@v2 + with: + path: dist + key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + - name: Upload a Python package to PyPi + run: twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD + - name: Publish a git tag + run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 00000000..1c31468a --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,85 @@ +name: Validate + +on: + pull_request: + types: [ assigned, opened, reopened, synchronize, ready_for_review ] + workflow_dispatch: + workflow_call: + + +jobs: + build: + uses: "./.github/workflows/build.yml" + + lint-files: + runs-on: ubuntu-20.04 + needs: [ build ] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + 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 + needs: [ build ] + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + - run: make test + + test-api: + runs-on: ubuntu-20.04 + needs: [ build ] + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + 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 + needs: [ lint-files, test-yaml, test-api ] # Last job to run + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9.9 + - name: Check version number has been properly updated + run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml deleted file mode 100644 index 164a454d..00000000 --- a/.github/workflows/workflow.yml +++ /dev/null @@ -1,161 +0,0 @@ -name: CI and CD Pipeline - -on: - push: - branches: [ main ] - pull_request: - types: [ assigned, opened, reopened, synchronize, ready_for_review ] - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 # 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 - with: - path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} # Cache the entire build Python environment - restore-keys: | - 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 - with: - path: dist - key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - lint-files: - runs-on: ubuntu-20.04 - needs: [ build ] - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - name: Cache build - id: restore-build - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - 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 - needs: [ build ] - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - name: Cache build - id: restore-build - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - run: make test - - test-api: - runs-on: ubuntu-20.04 - needs: [ build ] - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - name: Cache build - id: restore-build - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - 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 - needs: [ lint-files, test-yaml, test-api ] # Last job to run - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - 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 - if: github.ref == 'refs/heads/main' # Only triggered for the `main` branch - needs: [ check-version-and-changelog ] - outputs: - status: ${{ steps.stop-early.outputs.status }} - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - 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 - needs: [ check-for-functional-changes ] - if: needs.check-for-functional-changes.outputs.status == 'success' - env: - PYPI_USERNAME: openfisca-bot - PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9.9 - - name: Cache build - id: restore-build - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - name: Cache release - id: restore-release - uses: actions/cache@v2 - with: - path: dist - key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - name: Upload a Python package to PyPi - run: twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD - - name: Publish a git tag - run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" From a6d1175cb98c0570b653f7d339ca018d2ccf4342 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 11:07:37 +0200 Subject: [PATCH 13/92] Remove obsolete dependency --- .github/workflows/validate.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 1c31468a..f45c2bb4 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -72,7 +72,6 @@ jobs: check-version-and-changelog: runs-on: ubuntu-20.04 - needs: [ lint-files, test-yaml, test-api ] # Last job to run steps: - uses: actions/checkout@v2 with: From 24d6c036f44dc115a9c190bf1eb5b1b5aa9d864f Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 11:12:22 +0200 Subject: [PATCH 14/92] Update job condition --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 65fb0d30..2add4bec 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,7 +16,7 @@ jobs: # The `deploy` job is dependent on the output of the `check-for-functional-changes`job. check-for-functional-changes: runs-on: ubuntu-20.04 - if: github.ref == 'refs/heads/main' # Only triggered for the `main` branch + if: github.event.pull_request.merged == true outputs: status: ${{ steps.stop-early.outputs.status }} steps: From 721d53fdda8306e983732620e6d03f855c1addfe Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 14:30:00 +0200 Subject: [PATCH 15/92] Add changelog entry --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbee3e09..b3f48c7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## 7.1.0 [#143](https://github.com/openfisca/country-template/pull/143) + +* Technical improvement +* Minor change +* Details: + - Automate template setup process via CI for GitHub users: + - When creating a new repository by using this template on GitHub, the setup script is automatically executed by the CI on the resulting generated repository. + - Improve accessibility by adopting less technical terminology: + - Replaced "bootstrap" with "first-time setup," clarifying its purpose as a one-time project initialization, particularly useful for users unfamiliar with the technical vocabulary. + - Decompose GitHub Actions monolithic workflow into specialized workflows: + - Split the `Country-Template` workflow into three distinct workflows: `build`, `validate` and `deploy` enhancing clarity and organization. + - Enhance accuracy of workflow triggers: + - Trigger deployment exclusively when a PR is merged on the `main` branch + - Trigger validation on PR events or as a dependency of the deployment workflow + + ## 7.0.0 [#139](https://github.com/openfisca/country-template/pull/139) * Technical improvement From ee2baedca5c84c046aae67b63022acd632fd76f9 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 14:30:10 +0200 Subject: [PATCH 16/92] Update version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 47445df9..6ba3c093 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openfisca-country_template" -version = "7.0.0" +version = "7.1.0" description = "OpenFisca Rules as Code model for Country-Template." readme = "README.md" keywords = ["microsimulation", "tax", "benefit", "rac", "rules-as-code"] From 90a7d70c789b9750387f9bc10b0e0e7d483bc701 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 14:34:52 +0200 Subject: [PATCH 17/92] Improve documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ff9333bb..3c251ffc 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,11 @@ This set of instructions **only needs to be followed once** and will create your ### Using GitHub (recommended for GitHub users) -1. Click on the “Use this template” dropdown and select “Create a new repository” +1. Click on the [“Use this template” dropdown and select “Create a new repository”](https://github.com/new?template_name=country-template&template_owner=openfisca). 2. Set the repository name to `openfisca-`. For example, `openfisca-new_zealand` or `openfisca-france`. -3. Wait a minute or two for the automatic setup to run after being redirected to the newly generated repository. Once done, the title of the readme should be `OpenFisca `. +3. Wait a moment for the automatic setup to run after being redirected to the newly generated repository. Once done, the title of the readme should be `OpenFisca `. 4. Follow the instructions in the new repository's README.md. From 63977180fd341a1c436121aec1870b61098a4dc7 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 14:54:40 +0200 Subject: [PATCH 18/92] Title case the jurisdiction name --- .github/workflows/first-time-setup.yml | 6 +++++- README.md | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/first-time-setup.yml b/.github/workflows/first-time-setup.yml index d18fbf28..caf6bbfd 100644 --- a/.github/workflows/first-time-setup.yml +++ b/.github/workflows/first-time-setup.yml @@ -19,8 +19,12 @@ jobs: with: repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Set environment variables + run: | + echo "TITLE_CASE_JURISDICTION_NAME=$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//' | sed 's/[-|_]/ /g' | awk '{for (i=1; i<=NF; i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1')" >> $GITHUB_ENV + - name: Execute the first-time-setup script - run: CI=true JURISDICTION_NAME="$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//')" REPOSITORY_URL="${{ github.repositoryUrl }}" ./first-time-setup.sh + run: CI=true JURISDICTION_NAME="$TITLE_CASE_JURISDICTION_NAME" REPOSITORY_URL="${{ github.repositoryUrl }}" ./first-time-setup.sh - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/README.md b/README.md index 3c251ffc..aad42ade 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This set of instructions **only needs to be followed once** and will create your 1. Click on the [“Use this template” dropdown and select “Create a new repository”](https://github.com/new?template_name=country-template&template_owner=openfisca). -2. Set the repository name to `openfisca-`. For example, `openfisca-new_zealand` or `openfisca-france`. +2. Set the repository name to `openfisca-`; use underscore `_` or dash `-` as separators. For example, `openfisca-new_zealand`, `openfisca-new-zealand` or `openfisca-france`. 3. Wait a moment for the automatic setup to run after being redirected to the newly generated repository. Once done, the title of the readme should be `OpenFisca `. From 7b3e90ffcbf7be3f0f051987e9bf2d0a866c04c8 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 15:08:31 +0200 Subject: [PATCH 19/92] Allow to manually trigger first time setup workflow --- .github/workflows/first-time-setup.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/first-time-setup.yml b/.github/workflows/first-time-setup.yml index caf6bbfd..9512ff44 100644 --- a/.github/workflows/first-time-setup.yml +++ b/.github/workflows/first-time-setup.yml @@ -2,6 +2,7 @@ name: First time setup on: create: + workflow_dispatch: permissions: actions: write From de9206f3258db306bfbec486b886897179c2af20 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 15:20:27 +0200 Subject: [PATCH 20/92] Improve documentation --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aad42ade..ee718d2b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,12 @@ This set of instructions **only needs to be followed once** and will create your 2. Set the repository name to `openfisca-`; use underscore `_` or dash `-` as separators. For example, `openfisca-new_zealand`, `openfisca-new-zealand` or `openfisca-france`. -3. Wait a moment for the automatic setup to run after being redirected to the newly generated repository. Once done, the title of the readme should be `OpenFisca `. +3. After being redirected to your newly created repository, please allow a short period for the automatic setup to be executed. Once done, the title of the readme should be updated to `OpenFisca `. + +> If the automatic setup does not start within a few minutes, you can initiate it manually: +> - Navigate to the “Actions” tab. +> - Select the “First time setup” workflow. +> - Click on “Run workflow” to start the setup process manually. 4. Follow the instructions in the new repository's README.md. @@ -26,7 +31,7 @@ This set of instructions **only needs to be followed once** and will create your 2. Create a new repository on your favourite git host (Bitbucket, GitLab, …) with the name `openfisca-`. For example, `openfisca-new_zealand` or `openfisca-france`. -3. Execute the `first-time-setup.sh` script to initialise the git repository. This performs numerous tasks including replacing all references to `openfisca-country_template` with references to the new country package. +3. Execute the `first-time-setup.sh` script to initialise the git repository. This performs numerous tasks including replacing all references to `openfisca-country_template` with references to the new country package. - To execute the script run `bash first-time-setup.sh` from the command line - After the `first-time-setup.sh` has run both it and these instructions are removed. From e1924a873c394d83a646af63f13a832b65c45dfb Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 26 Apr 2024 15:32:45 +0200 Subject: [PATCH 21/92] Remove spaces --- .github/workflows/deploy.yml | 1 - .github/workflows/validate.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2add4bec..10dac37a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,7 +6,6 @@ on: - main types: [ closed ] - jobs: validate: uses: "./.github/workflows/validate.yml" diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index f45c2bb4..715b09ea 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -6,7 +6,6 @@ on: workflow_dispatch: workflow_call: - jobs: build: uses: "./.github/workflows/build.yml" From fd141ad58813a361ca33cf21569f85e4157dc7c4 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Mon, 29 Apr 2024 14:57:20 +0200 Subject: [PATCH 22/92] Fix typos and improve some phrasings --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 4 ++-- CHANGELOG.md | 4 ++-- README.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 633e343d..96fe0ccc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.9.9 # 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.9 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - name: Cache build id: restore-build uses: actions/cache@v2 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 10dac37a..424e15a0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,9 +10,9 @@ jobs: validate: uses: "./.github/workflows/validate.yml" - # GitHub Actions does not have a halt job option, to stop from deploying if no functional changes were found. + # 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. + # The `deploy` job is dependent on the output of the `check-for-functional-changes` job. check-for-functional-changes: runs-on: ubuntu-20.04 if: github.event.pull_request.merged == true diff --git a/CHANGELOG.md b/CHANGELOG.md index b3f48c7d..d672d147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,9 @@ - Automate template setup process via CI for GitHub users: - When creating a new repository by using this template on GitHub, the setup script is automatically executed by the CI on the resulting generated repository. - Improve accessibility by adopting less technical terminology: - - Replaced "bootstrap" with "first-time setup," clarifying its purpose as a one-time project initialization, particularly useful for users unfamiliar with the technical vocabulary. + - Replace "bootstrap" with "first-time setup", clarifying its purpose as a one-time project initialisation, particularly for users unfamiliar with the technical vocabulary. - Decompose GitHub Actions monolithic workflow into specialized workflows: - - Split the `Country-Template` workflow into three distinct workflows: `build`, `validate` and `deploy` enhancing clarity and organization. + - Split the `Country-Template` workflow into three distinct workflows: `build`, `validate` and `deploy`. - Enhance accuracy of workflow triggers: - Trigger deployment exclusively when a PR is merged on the `main` branch - Trigger validation on PR events or as a dependency of the deployment workflow diff --git a/README.md b/README.md index ee718d2b..dcc58030 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This set of instructions **only needs to be followed once** and will create your 2. Set the repository name to `openfisca-`; use underscore `_` or dash `-` as separators. For example, `openfisca-new_zealand`, `openfisca-new-zealand` or `openfisca-france`. -3. After being redirected to your newly created repository, please allow a short period for the automatic setup to be executed. Once done, the title of the readme should be updated to `OpenFisca `. +3. After being redirected to your newly created repository, please allow a few minutes for the automatic setup to be executed. Once done, the title of the readme should be updated to `OpenFisca `. > If the automatic setup does not start within a few minutes, you can initiate it manually: > - Navigate to the “Actions” tab. From 2b23d6bf45befb0a03c9e51a35759741bc32ed4f Mon Sep 17 00:00:00 2001 From: sandcha Date: Mon, 29 Apr 2024 11:43:05 +0200 Subject: [PATCH 23/92] Use PyPi token for deployment https://github.com/openfisca/country-template/pull/144 --- .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 f1567106..881c1e47 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('pyproject.toml') }}-${{ 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 dadc4b026fa6aca495b1d5b06b80935555a976c1 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Thu, 2 May 2024 09:43:46 +0200 Subject: [PATCH 24/92] Fix changelog hierarchy --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbee3e09..ffe8e7a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 7.0.0 [#139](https://github.com/openfisca/country-template/pull/139) +# 7.0.0 [#139](https://github.com/openfisca/country-template/pull/139) * Technical improvement * Major change From c906b86ad7acc68243f955be063eec6fcc110866 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:20:48 +0200 Subject: [PATCH 25/92] Improve wording Co-authored-by: Matti Schneider --- CHANGELOG.md | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d672d147..bfecc320 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,8 @@ - Decompose GitHub Actions monolithic workflow into specialized workflows: - Split the `Country-Template` workflow into three distinct workflows: `build`, `validate` and `deploy`. - Enhance accuracy of workflow triggers: - - Trigger deployment exclusively when a PR is merged on the `main` branch - - Trigger validation on PR events or as a dependency of the deployment workflow + - Trigger deployment exclusively when a PR is merged on the `main` branch. + - Trigger validation on PR events or as a dependency of the deployment workflow. ## 7.0.0 [#139](https://github.com/openfisca/country-template/pull/139) diff --git a/README.md b/README.md index dcc58030..c0a76444 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This set of instructions **only needs to be followed once** and will create your 1. Click on the [“Use this template” dropdown and select “Create a new repository”](https://github.com/new?template_name=country-template&template_owner=openfisca). -2. Set the repository name to `openfisca-`; use underscore `_` or dash `-` as separators. For example, `openfisca-new_zealand`, `openfisca-new-zealand` or `openfisca-france`. +2. Set the repository name to `openfisca-`; use underscore `_` as separator if there are spaces in the country name. For example, `openfisca-new_zealand` or `openfisca-france`. 3. After being redirected to your newly created repository, please allow a few minutes for the automatic setup to be executed. Once done, the title of the readme should be updated to `OpenFisca `. From 5c65f275088c9e51f7324f41dc388056ff5b2ade Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:22:03 +0200 Subject: [PATCH 26/92] Fix condition Co-authored-by: Matti Schneider --- first-time-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/first-time-setup.sh b/first-time-setup.sh index 8f58de77..5ee4e97d 100755 --- a/first-time-setup.sh +++ b/first-time-setup.sh @@ -12,7 +12,7 @@ if [[ $JURISDICTION_NAME ]] && [[ $REPOSITORY_URL ]] then continue=Y fi -if [[ $CI ]] && [ ! -d .git ] +if [[ ! $CI ]] && [[ -d .git ]] then echo 'It seems you cloned this repository, or already initialised it.' echo 'Refusing to go further as you might lose work.' From dcec0738de6edbe264842fa7ecb35693fc876786 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:22:24 +0200 Subject: [PATCH 27/92] Unify syntax Co-authored-by: Matti Schneider --- first-time-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/first-time-setup.sh b/first-time-setup.sh index 5ee4e97d..2fd9cd3d 100755 --- a/first-time-setup.sh +++ b/first-time-setup.sh @@ -62,7 +62,7 @@ last_changelog_number=$(grep --line-number '^# Example Entry' CHANGELOG.md | cut first_commit_message='Initial import from OpenFisca country-template' second_commit_message='Customise country-template through script' -if [[ ! "$CI" ]] +if [[ ! $CI ]] then echo cd .. From fdeb4288bd183a094cd9680e86f6821dcc70bea9 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:23:09 +0200 Subject: [PATCH 28/92] Add comment Co-authored-by: Matti Schneider --- first-time-setup.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/first-time-setup.sh b/first-time-setup.sh index 2fd9cd3d..2cde129d 100755 --- a/first-time-setup.sh +++ b/first-time-setup.sh @@ -110,8 +110,7 @@ echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.y rm -f .github/workflows/first-time-setup.yml if [[ $CI ]] -then - exit 0 +then exit 0 # committing and tagging take directly place in the GitHub Actions workflow fi git add . From 6b5f74ddbef24af107f8d516ba57bdad881cfff3 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:33:27 +0200 Subject: [PATCH 29/92] Delete file via Git to ensure the removal will be committed --- first-time-setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/first-time-setup.sh b/first-time-setup.sh index 2cde129d..3eff99ec 100755 --- a/first-time-setup.sh +++ b/first-time-setup.sh @@ -103,12 +103,12 @@ find . -name "*.template" -type f -delete echo -e "${PURPLE}* ${PURPLE}Rename package to: \033[0m${BLUE}$package_name\033[0m" git mv openfisca_country_template $package_name +echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.yml\033[0m${PURPLE} GitHub Action\033[0m" +git rm .github/workflows/first-time-setup.yml > /dev/null 2>&1 + echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.sh\033[0m${PURPLE} script\033[0m" git rm first-time-setup.sh > /dev/null 2>&1 -echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.yml\033[0m${PURPLE} GitHub Action\033[0m" -rm -f .github/workflows/first-time-setup.yml - if [[ $CI ]] then exit 0 # committing and tagging take directly place in the GitHub Actions workflow fi From 93bb53e3b02c29dd85fdaa4101125c187f107d86 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:50:26 +0200 Subject: [PATCH 30/92] Update stefanzweifel/git-auto-commit-action to v5 --- .github/workflows/first-time-setup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/first-time-setup.yml b/.github/workflows/first-time-setup.yml index 9512ff44..b0fc8e5b 100644 --- a/.github/workflows/first-time-setup.yml +++ b/.github/workflows/first-time-setup.yml @@ -28,7 +28,7 @@ jobs: run: CI=true JURISDICTION_NAME="$TITLE_CASE_JURISDICTION_NAME" REPOSITORY_URL="${{ github.repositoryUrl }}" ./first-time-setup.sh - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: "Customise country-template through CI" tagging_message: "0.0.1" From 1238ffbf8c7c416ad559d99e95ab1cb753bf5a8e Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:06:56 +0200 Subject: [PATCH 31/92] Remove obsolete IDs --- .github/workflows/build.yml | 2 -- .github/workflows/deploy.yml | 2 -- .github/workflows/validate.yml | 3 --- 3 files changed, 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 96fe0ccc..c3b76b4d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,6 @@ jobs: with: python-version: 3.9.9 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - name: Cache build - id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -26,7 +25,6 @@ jobs: - name: Build package run: make build - name: Cache release - id: restore-release uses: actions/cache@v2 with: path: dist diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f1050acb..e65c8804 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -44,13 +44,11 @@ jobs: with: python-version: 3.9.9 - name: Cache build - id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - name: Cache release - id: restore-release uses: actions/cache@v2 with: path: dist diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 715b09ea..bfa539ff 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -22,7 +22,6 @@ jobs: with: python-version: 3.9.9 - name: Cache build - id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -44,7 +43,6 @@ jobs: with: python-version: 3.9.9 - name: Cache build - id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -61,7 +59,6 @@ jobs: with: python-version: 3.9.9 - name: Cache build - id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} From faea0bcc4ac1749c7161b2a7c7818065261eae4d Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:11:47 +0200 Subject: [PATCH 32/92] Improve naming --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 2 +- .github/workflows/validate.yml | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c3b76b4d..da2147b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9.9 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - - name: Cache build + - name: Restore build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e65c8804..a94709d5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -43,7 +43,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9.9 - - name: Cache build + - name: Restore build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index bfa539ff..5d28c326 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -21,7 +21,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9.9 - - name: Cache build + - name: Restore build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -42,7 +42,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9.9 - - name: Cache build + - name: Restore build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -58,7 +58,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9.9 - - name: Cache build + - name: Restore build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} From 01be1753218204364d00078792112b529ddc321b Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:30:01 +0200 Subject: [PATCH 33/92] Remove obsolete checkout option --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a94709d5..40947040 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -37,8 +37,6 @@ jobs: PYPI_TOKEN_OPENFISCA_BOT: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} steps: - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - name: Set up Python uses: actions/setup-python@v2 with: From 0dcdbcf57e6d262bd58e5037c8e8da1accfca1a1 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:31:17 +0200 Subject: [PATCH 34/92] Remove manual trigger on `build` and `validate` workflows --- .github/workflows/build.yml | 1 - .github/workflows/validate.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da2147b8..c272840d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,6 @@ name: Build on: workflow_call: - workflow_dispatch: jobs: build: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 5d28c326..96de6a71 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -3,7 +3,6 @@ name: Validate on: pull_request: types: [ assigned, opened, reopened, synchronize, ready_for_review ] - workflow_dispatch: workflow_call: jobs: From 4130dfe54dae39efbc3c253801f4443b7a5b92e4 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:51:44 +0200 Subject: [PATCH 35/92] Update Ubuntu to `v22.04` on CI --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 4 ++-- .github/workflows/validate.yml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c272840d..59a14ae8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 40947040..58798403 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,7 +14,7 @@ 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.event.pull_request.merged == true outputs: status: ${{ steps.stop-early.outputs.status }} @@ -30,7 +30,7 @@ jobs: 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: [ validate, check-for-functional-changes ] if: github.event.pull_request.merged == true && needs.check-for-functional-changes.outputs.status == 'success' env: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 96de6a71..a90cb027 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -10,7 +10,7 @@ jobs: uses: "./.github/workflows/build.yml" lint-files: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ build ] steps: - uses: actions/checkout@v2 @@ -33,7 +33,7 @@ jobs: 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 @@ -49,7 +49,7 @@ jobs: - run: make test test-api: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 needs: [ build ] steps: - uses: actions/checkout@v2 @@ -66,7 +66,7 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/test-api.sh" check-version-and-changelog: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: From 7d13315e471200049c748e167ab85b15bd3f42cb Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:54:08 +0200 Subject: [PATCH 36/92] Update CI dependency `actions/setup-python` to `v5` --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 4 ++-- .github/workflows/validate.yml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59a14ae8..ca74fd59 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - name: Restore build diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 58798403..dae59af2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,7 +23,7 @@ jobs: 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.9.9 - id: stop-early @@ -38,7 +38,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 - name: Restore build diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index a90cb027..ecbe900e 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -17,7 +17,7 @@ jobs: 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.9.9 - name: Restore build @@ -38,7 +38,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 - name: Restore build @@ -54,7 +54,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.9.9 - name: Restore build @@ -72,7 +72,7 @@ jobs: 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.9.9 - name: Check version number has been properly updated From b3e4ebbaaeff0260a28d0c8b1c127dc91afff1b5 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 09:58:39 +0200 Subject: [PATCH 37/92] Update Python to `v3.9.12` on CI Python `v3.9.9` is not available for Ubuntu `v22.04` --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 4 ++-- .github/workflows/validate.yml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca74fd59..1563a246 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. + python-version: 3.9.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - name: Restore build uses: actions/cache@v2 with: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dae59af2..11b4e323 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,7 +25,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - id: stop-early run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi @@ -40,7 +40,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - name: Restore build uses: actions/cache@v2 with: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index ecbe900e..96d2202e 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - name: Restore build uses: actions/cache@v2 with: @@ -40,7 +40,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - name: Restore build uses: actions/cache@v2 with: @@ -56,7 +56,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - name: Restore build uses: actions/cache@v2 with: @@ -74,6 +74,6 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9.9 + python-version: 3.9.12 - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" From 71b05d3fb5fd6d1b309a964dae33ed7f4a2bb461 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:04:01 +0200 Subject: [PATCH 38/92] Update CI dependency `actions/checkout` to `v4` --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 4 ++-- .github/workflows/validate.yml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1563a246..f65c0e80 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 11b4e323..ad27c34d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,7 +19,7 @@ jobs: 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 @@ -36,7 +36,7 @@ jobs: env: PYPI_TOKEN_OPENFISCA_BOT: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 96d2202e..2e9f1e0c 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -13,7 +13,7 @@ jobs: 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 @@ -36,7 +36,7 @@ jobs: runs-on: ubuntu-22.04 needs: [ build ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: @@ -52,7 +52,7 @@ jobs: runs-on: ubuntu-22.04 needs: [ build ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: @@ -68,7 +68,7 @@ jobs: check-version-and-changelog: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all the tags - name: Set up Python From 830be467149dcafe22689988da06e582a9790c2b Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 10:05:37 +0200 Subject: [PATCH 39/92] Update CI dependency `actions/cache` to `v4` --- .github/workflows/build.yml | 4 ++-- .github/workflows/deploy.yml | 4 ++-- .github/workflows/validate.yml | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f65c0e80..093234e6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: with: python-version: 3.9.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - name: Restore build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} # Cache the entire build Python environment @@ -24,7 +24,7 @@ jobs: - name: Build package run: make build - name: Cache release - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: dist key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ad27c34d..94c060f6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -42,12 +42,12 @@ jobs: with: python-version: 3.9.12 - name: Restore build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - name: Cache release - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: dist key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 2e9f1e0c..5241f279 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -21,7 +21,7 @@ jobs: with: python-version: 3.9.12 - name: Restore build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} @@ -42,7 +42,7 @@ jobs: with: python-version: 3.9.12 - name: Restore build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} @@ -58,7 +58,7 @@ jobs: with: python-version: 3.9.12 - name: Restore build - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} From 6df2cb82503ae670a001bb1a017c3a0302d03461 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 15:33:44 +0200 Subject: [PATCH 40/92] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43c9c756..00c845ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Enhance accuracy of workflow triggers: - Trigger deployment exclusively when a PR is merged on the `main` branch. - Trigger validation on PR events or as a dependency of the deployment workflow. + - Update CI dependencies # 7.0.0 [#139](https://github.com/openfisca/country-template/pull/139) From 3e012098da6460076dd803d8ad8e30c15a2b837f Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Fri, 3 May 2024 16:37:02 +0200 Subject: [PATCH 41/92] Improve copywriting --- .github/workflows/deploy.yml | 5 ++--- .github/workflows/first-time-setup.yml | 2 +- README.md | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 94c060f6..716806f4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -11,8 +11,7 @@ jobs: uses: "./.github/workflows/validate.yml" # 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. + # We thus execute a separate deployment job depending on the output of this job. check-for-functional-changes: runs-on: ubuntu-22.04 if: github.event.pull_request.merged == true @@ -46,7 +45,7 @@ jobs: with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} - - name: Cache release + - name: Restore built package uses: actions/cache@v4 with: path: dist diff --git a/.github/workflows/first-time-setup.yml b/.github/workflows/first-time-setup.yml index b0fc8e5b..31b55375 100644 --- a/.github/workflows/first-time-setup.yml +++ b/.github/workflows/first-time-setup.yml @@ -20,7 +20,7 @@ jobs: with: repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Set environment variables + - name: Infer jurisdiction name from repository name run: | echo "TITLE_CASE_JURISDICTION_NAME=$(echo ${{ github.event.repository.name }} | sed 's/openfisca-//' | sed 's/[-|_]/ /g' | awk '{for (i=1; i<=NF; i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1')" >> $GITHUB_ENV diff --git a/README.md b/README.md index c0a76444..1fbbe623 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This set of instructions **only needs to be followed once** and will create your 2. Set the repository name to `openfisca-`; use underscore `_` as separator if there are spaces in the country name. For example, `openfisca-new_zealand` or `openfisca-france`. -3. After being redirected to your newly created repository, please allow a few minutes for the automatic setup to be executed. Once done, the title of the readme should be updated to `OpenFisca `. +3. After being redirected to your newly created repository, please allow a few minutes for the automatic setup to be executed. Once done, the title of the README file should be updated to `OpenFisca `. > If the automatic setup does not start within a few minutes, you can initiate it manually: > - Navigate to the “Actions” tab. From 5b43f1a64569c158508884bf121ea011d3fd11d2 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 16:44:04 +0200 Subject: [PATCH 42/92] Fix step name Co-authored-by: Matti Schneider --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 093234e6..a42811d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: 3.9.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. - - name: Restore build + - name: Cache build uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} From 50b840851ece68bd5cbff60be53b60d3b8ed6388 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 16:57:30 +0200 Subject: [PATCH 43/92] Trigger deployment on any push to `main` --- .github/workflows/deploy.yml | 9 +++------ CHANGELOG.md | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 716806f4..ae68a6d1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,10 +1,8 @@ name: Deploy on: - pull_request_target: - branches: - - main - types: [ closed ] + push: + branches: [ main ] jobs: validate: @@ -14,7 +12,6 @@ jobs: # We thus execute a separate deployment job depending on the output of this job. check-for-functional-changes: runs-on: ubuntu-22.04 - if: github.event.pull_request.merged == true outputs: status: ${{ steps.stop-early.outputs.status }} steps: @@ -31,9 +28,9 @@ jobs: deploy: runs-on: ubuntu-22.04 needs: [ validate, check-for-functional-changes ] - if: github.event.pull_request.merged == true && needs.check-for-functional-changes.outputs.status == 'success' env: PYPI_TOKEN_OPENFISCA_BOT: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} + if: needs.check-for-functional-changes.outputs.status == 'success' steps: - uses: actions/checkout@v4 - name: Set up Python diff --git a/CHANGELOG.md b/CHANGELOG.md index 00c845ad..ecd91df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - Decompose GitHub Actions monolithic workflow into specialized workflows: - Split the `Country-Template` workflow into three distinct workflows: `build`, `validate` and `deploy`. - Enhance accuracy of workflow triggers: - - Trigger deployment exclusively when a PR is merged on the `main` branch. + - Trigger deployment only when changes are pushed to the `main` branch. - Trigger validation on PR events or as a dependency of the deployment workflow. - Update CI dependencies From dd4f13b8405faf0290a1039b028a78d843a7fab9 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 16:57:45 +0200 Subject: [PATCH 44/92] Simplify code --- .github/workflows/deploy.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ae68a6d1..34dd0274 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,8 +28,6 @@ jobs: deploy: runs-on: ubuntu-22.04 needs: [ validate, check-for-functional-changes ] - env: - PYPI_TOKEN_OPENFISCA_BOT: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} if: needs.check-for-functional-changes.outputs.status == 'success' steps: - uses: actions/checkout@v4 @@ -48,6 +46,6 @@ jobs: path: dist key: release-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ 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_OPENFISCA_BOT }} - name: Publish a git tag run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" From 3f351331b178e3f02708962bd224cd6f8332c233 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 16:58:30 +0200 Subject: [PATCH 45/92] Use consistent line breaks across workflows --- .github/workflows/build.yml | 4 ++++ .github/workflows/validate.yml | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a42811d4..419e8b07 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,10 +9,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: Set up Python uses: actions/setup-python@v5 with: python-version: 3.9.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any difference in patches between jobs will lead to a cache not found error. + - name: Cache build uses: actions/cache@v4 with: @@ -21,8 +23,10 @@ jobs: restore-keys: | build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }} build-${{ env.pythonLocation }}- + - name: Build package run: make build + - name: Cache release uses: actions/cache@v4 with: diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 5241f279..982ee857 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -16,19 +16,25 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all the tags + - name: Set up Python uses: actions/setup-python@v5 with: python-version: 3.9.12 + - name: Restore build uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} 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" @@ -37,15 +43,18 @@ jobs: needs: [ build ] steps: - uses: actions/checkout@v4 + - name: Set up Python uses: actions/setup-python@v5 with: python-version: 3.9.12 + - name: Restore build uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + - run: make test test-api: @@ -53,15 +62,18 @@ jobs: needs: [ build ] steps: - uses: actions/checkout@v4 + - name: Set up Python uses: actions/setup-python@v5 with: python-version: 3.9.12 + - name: Restore build uses: actions/cache@v4 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ github.sha }} + - name: Test the Web API run: "${GITHUB_WORKSPACE}/.github/test-api.sh" @@ -71,9 +83,11 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all the tags + - name: Set up Python uses: actions/setup-python@v5 with: python-version: 3.9.12 + - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" From 73ba03b156bad53d33e86f4c1a60918fd36f1bf9 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 17:01:56 +0200 Subject: [PATCH 46/92] Reduce logs --- first-time-setup.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/first-time-setup.sh b/first-time-setup.sh index 3eff99ec..a64b3b38 100755 --- a/first-time-setup.sh +++ b/first-time-setup.sh @@ -103,10 +103,8 @@ find . -name "*.template" -type f -delete echo -e "${PURPLE}* ${PURPLE}Rename package to: \033[0m${BLUE}$package_name\033[0m" git mv openfisca_country_template $package_name -echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.yml\033[0m${PURPLE} GitHub Action\033[0m" +echo -e "${PURPLE}* ${PURPLE}Remove single use first time setup files\033[0m" git rm .github/workflows/first-time-setup.yml > /dev/null 2>&1 - -echo -e "${PURPLE}* ${PURPLE}Remove single use \033[0m${BLUE}first-time-setup.sh\033[0m${PURPLE} script\033[0m" git rm first-time-setup.sh > /dev/null 2>&1 if [[ $CI ]] From e70eaf8833baf874bfc2b7750694172cd3f2e9f0 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 3 May 2024 17:08:05 +0200 Subject: [PATCH 47/92] Improve job name --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 419e8b07..b38ed1a1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: workflow_call: jobs: - build: + build-and-cache: runs-on: ubuntu-22.04 steps: - name: Checkout From fe5126e892e44a581f9c93d48852e4af03c2222c Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Tue, 7 May 2024 14:26:07 +0200 Subject: [PATCH 48/92] Use version specifiers compatible with Conda According to https://github.com/openfisca/openfisca-france/pull/2298/commits/196c469832180b264d339a0c3a32537d5e1461e8, generating conda.yaml fails if specifiers contain a space --- pyproject.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6ba3c093..c61a2db0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,9 +14,9 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Topic :: Scientific/Engineering :: Information Analysis", ] -requires-python = ">= 3.9" +requires-python = ">=3.9" dependencies = [ - "openfisca-core[web-api] >= 41.0.0, < 42.0.0" + "openfisca-core[web-api] >=41.0.0, <42.0.0" ] [project.urls] @@ -28,12 +28,12 @@ Changelog = "https://github.com/openfisca/country-template/blob/main/CHANGELOG.m [project.optional-dependencies] dev = [ - "autopep8 >= 2.0.4", - "flake8 >= 7.0.0", - "isort >= 5.13.2", - "pylint >= 3.1.0", - "pyupgrade >= 3.15.1", - "yamllint >= 1.35.1" + "autopep8 >=2.0.4", + "flake8 >=7.0.0", + "isort >=5.13.2", + "pylint >=3.1.0", + "pyupgrade >=3.15.1", + "yamllint >=1.35.1" ] [tool.pytest.ini_options] From 157461447ccdcb2b4126c053ba82b3ded800cfa5 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Tue, 7 May 2024 14:26:39 +0200 Subject: [PATCH 49/92] Update Core dependency Require a version that can parse pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c61a2db0..56564817 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ classifiers = [ ] requires-python = ">=3.9" dependencies = [ - "openfisca-core[web-api] >=41.0.0, <42.0.0" + "openfisca-core[web-api] >=41.4.5, <42.0.0" ] [project.urls] From 823869c7e91e60bf45b887a0d37a0b98dd140b22 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Tue, 7 May 2024 14:35:34 +0200 Subject: [PATCH 50/92] Bump version number and changelog --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecd91df8..251fe116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### 7.1.1 [#146](https://github.com/openfisca/country-template/pull/146) + +* Technical improvement +* Details: + - Update minimal Core dependency to require a version that can parse `pyproject.toml` (see https://github.com/openfisca/openfisca-core/pull/1209) + - Use version specifiers compatible with Conda packaging + ## 7.1.0 [#143](https://github.com/openfisca/country-template/pull/143) * Technical improvement diff --git a/pyproject.toml b/pyproject.toml index 56564817..73e06bcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openfisca-country_template" -version = "7.1.0" +version = "7.1.1" description = "OpenFisca Rules as Code model for Country-Template." readme = "README.md" keywords = ["microsimulation", "tax", "benefit", "rac", "rules-as-code"] From 2782d3a8f2cc546e647054c37d3469f04a7d14e6 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Thu, 9 May 2024 17:14:58 +0200 Subject: [PATCH 51/92] Ensure scripts fail if finding the latest tagged commit fails --- .github/lint-changed-python-files.sh | 5 +++++ .github/lint-changed-yaml-tests.sh | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh index b7456772..afaffbf0 100755 --- a/.github/lint-changed-python-files.sh +++ b/.github/lint-changed-python-files.sh @@ -2,6 +2,11 @@ last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit +if [ $? -ne 0 ]; then + echo "Error: Failed to find the last tagged commit." + exit 1 +fi + if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py") then echo "Linting the following Python files:" diff --git a/.github/lint-changed-yaml-tests.sh b/.github/lint-changed-yaml-tests.sh index 9e2ab562..2f3c5d63 100755 --- a/.github/lint-changed-yaml-tests.sh +++ b/.github/lint-changed-yaml-tests.sh @@ -2,6 +2,11 @@ last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit +if [ $? -ne 0 ]; then + echo "Error: Failed to find the last tagged commit." + exit 1 +fi + if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "tests/*.yaml") then echo "Linting the following changed YAML tests:" From 667a70fe962fd3074106166e5eaa450dfd3feabb Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Thu, 9 May 2024 17:18:10 +0200 Subject: [PATCH 52/92] Always return a result even with no reachable tags --- .github/lint-changed-python-files.sh | 2 +- .github/lint-changed-yaml-tests.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh index afaffbf0..c0615433 100755 --- a/.github/lint-changed-python-files.sh +++ b/.github/lint-changed-python-files.sh @@ -1,6 +1,6 @@ #! /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 main through an unlikely intermediary merge commit +last_tagged_commit=`git describe --always --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit if [ $? -ne 0 ]; then echo "Error: Failed to find the last tagged commit." diff --git a/.github/lint-changed-yaml-tests.sh b/.github/lint-changed-yaml-tests.sh index 2f3c5d63..9b080f2f 100755 --- a/.github/lint-changed-yaml-tests.sh +++ b/.github/lint-changed-yaml-tests.sh @@ -1,6 +1,6 @@ #! /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 main through an unlikely intermediary merge commit +last_tagged_commit=`git describe --always --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit if [ $? -ne 0 ]; then echo "Error: Failed to find the last tagged commit." From 7afe3008235bfcbf04d30fdc9c5567eb664059a7 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Thu, 9 May 2024 17:23:06 +0200 Subject: [PATCH 53/92] Skip deploy job if Pypi token is not defined Use intermediary job as secrets cannot be directly referenced in `if:` conditionals; see https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow --- .github/workflows/deploy.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 34dd0274..6ab4b1ef 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,10 +25,24 @@ jobs: - id: stop-early run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi + check-pypi-token: + runs-on: ubuntu-22.04 + outputs: + pypi_token_present: ${{ steps.check_token.outputs.pypi_token_present }} + steps: + - name: Check PYPI Token + id: check_token + run: | + if [[ -n "${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }}" ]]; then + echo "pypi_token_present=true" >> $GITHUB_OUTPUT + else + echo "pypi_token_present=false" >> $GITHUB_OUTPUT + fi + deploy: runs-on: ubuntu-22.04 - needs: [ validate, check-for-functional-changes ] - if: needs.check-for-functional-changes.outputs.status == 'success' + needs: [ validate, check-for-functional-changes, check-pypi-token ] + if: needs.check-for-functional-changes.outputs.status == 'success' && needs.check-pypi-token.outputs.pypi_token_present == 'true' steps: - uses: actions/checkout@v4 - name: Set up Python From 661329a7a2763509adddb75572a3f8507ffb3956 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Thu, 9 May 2024 17:23:15 +0200 Subject: [PATCH 54/92] Update deprecated syntax --- .github/workflows/deploy.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6ab4b1ef..cbf4378a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,7 +23,10 @@ jobs: with: python-version: 3.9.12 - id: stop-early - run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi + run: | + if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then + echo "status=success" >> $GITHUB_OUTPUT + fi check-pypi-token: runs-on: ubuntu-22.04 From 695050aa95990d4262e16ec475f252f1a44b63b1 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Thu, 9 May 2024 17:24:56 +0200 Subject: [PATCH 55/92] Rename PyPI token GitHub secret --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cbf4378a..1d586d05 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -36,7 +36,7 @@ jobs: - name: Check PYPI Token id: check_token run: | - if [[ -n "${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }}" ]]; then + if [[ -n "${{ secrets.PYPI_TOKEN }}" ]]; then echo "pypi_token_present=true" >> $GITHUB_OUTPUT else echo "pypi_token_present=false" >> $GITHUB_OUTPUT @@ -63,6 +63,6 @@ jobs: path: dist 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 }} + run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN }} - name: Publish a git tag run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" From 9eb3c6896b0855c73ac3f259993d5cdababfb80f Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Thu, 9 May 2024 17:44:53 +0200 Subject: [PATCH 56/92] Update packaging section in README --- README.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1fbbe623..000e7c99 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,35 @@ The files that are outside from the `openfisca_country_template` folder are used ## Packaging your Country Package for Distribution -Country packages are python distributions. To distribute your package via `pip`, follow the steps given by the [Python Packaging Authority](https://python-packaging-user-guide.readthedocs.io/tutorials/distributing-packages/#packaging-your-project). +Country packages are Python distributions. You can choose to distribute your package automatically via our continuous deployment system on GitHub, or manually. + +### Automatic continuous deployment on GitHub + +This repository is configured with a continuous deployment system to automate the distribution of your package via `pip`. + +#### Setting up continuous deployment + +To activate the continuous deployment: + +1. Create an account on [PyPI](https://pypi.org/) if you don't already have one. +2. Generate a token in your PyPI account. This token will allow GitHub Actions to securely upload new versions of your package to PyPI. +3. Add this token to your GitHub repository's secrets under the name `PYPI_TOKEN`. + +Once set up, changes to the `main` branch will trigger an automated workflow to build and publish your package to PyPI, making it available for `pip` installation. + +### Manual distribution + +If you prefer to manually manage the release and distribution of your package, follow the guidelines provided by the [Python Packaging Authority](https://python-packaging-user-guide.readthedocs.io/tutorials/distributing-packages/#packaging-your-project). + +This involves detailed steps on preparing your package, creating distribution files, and uploading them to PyPI. + +### Accessing your package + +Once deployed, your package can be easily installed by users with the following command: + +```sh +pip install openfisca- +``` ## Install Instructions for Users and Contributors From 2bf47771f2233f04259a45798859b47913df4dcb Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Thu, 9 May 2024 17:59:50 +0200 Subject: [PATCH 57/92] Add changelog entry --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 251fe116..1f0a2eab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +### 7.1.2 [#147](https://github.com/openfisca/country-template/pull/147) + +* Technical improvement +* Details: + - Skip `deploy` workflow when PyPI token is not defined in GitHub secrets + - Ensure lint scripts work properly without reachable tags + - Rename the GitHub secret `PYPI_TOKEN_OPENFISCA_BOT` used in `deploy` workflow to `PYPI_TOKEN` + - Update deprecated syntax in GitHub Action workflow + ### 7.1.1 [#146](https://github.com/openfisca/country-template/pull/146) * Technical improvement From 42d4e9d34e59b481c25d1f776a73b710b9068e6b Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Thu, 9 May 2024 18:01:12 +0200 Subject: [PATCH 58/92] Update version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 73e06bcc..02d51f0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openfisca-country_template" -version = "7.1.1" +version = "7.1.2" description = "OpenFisca Rules as Code model for Country-Template." readme = "README.md" keywords = ["microsimulation", "tax", "benefit", "rac", "rules-as-code"] From e751b8b96806b99dd1b98555c2fc45892f317146 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 10 May 2024 10:18:53 +0200 Subject: [PATCH 59/92] Improve wording Co-authored-by: Matti Schneider --- .github/workflows/deploy.yml | 2 +- CHANGELOG.md | 2 +- README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1d586d05..4c469a98 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -33,7 +33,7 @@ jobs: outputs: pypi_token_present: ${{ steps.check_token.outputs.pypi_token_present }} steps: - - name: Check PYPI Token + - name: Check PyPI token is defined id: check_token run: | if [[ -n "${{ secrets.PYPI_TOKEN }}" ]]; then diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f0a2eab..29db7322 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - Skip `deploy` workflow when PyPI token is not defined in GitHub secrets - Ensure lint scripts work properly without reachable tags - Rename the GitHub secret `PYPI_TOKEN_OPENFISCA_BOT` used in `deploy` workflow to `PYPI_TOKEN` - - Update deprecated syntax in GitHub Action workflow + - Update deprecated syntax in GitHub Actions workflow ### 7.1.1 [#146](https://github.com/openfisca/country-template/pull/146) diff --git a/README.md b/README.md index 000e7c99..a0edb526 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ The files that are outside from the `openfisca_country_template` folder are used ## Packaging your Country Package for Distribution -Country packages are Python distributions. You can choose to distribute your package automatically via our continuous deployment system on GitHub, or manually. +Country packages are Python distributions. You can choose to distribute your package automatically via the predefined continuous deployment system on GitHub Actions, or manually. ### Automatic continuous deployment on GitHub From ff314a53587f56c6067534046a9b9fa9e877ec29 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 10 May 2024 10:19:18 +0200 Subject: [PATCH 60/92] Remove redundant instructions Co-authored-by: Matti Schneider --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index a0edb526..bbc8983a 100644 --- a/README.md +++ b/README.md @@ -78,13 +78,6 @@ If you prefer to manually manage the release and distribution of your package, f This involves detailed steps on preparing your package, creating distribution files, and uploading them to PyPI. -### Accessing your package - -Once deployed, your package can be easily installed by users with the following command: - -```sh -pip install openfisca- -``` ## Install Instructions for Users and Contributors From 69286d832392648da1c5c5cf34cc32f04d0c83fa Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 10 May 2024 10:18:06 +0200 Subject: [PATCH 61/92] Unify bash multiline --- .github/lint-changed-python-files.sh | 3 ++- .github/lint-changed-yaml-tests.sh | 3 ++- .github/workflows/deploy.yml | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh index c0615433..a23bcefe 100755 --- a/.github/lint-changed-python-files.sh +++ b/.github/lint-changed-python-files.sh @@ -2,7 +2,8 @@ last_tagged_commit=`git describe --always --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit -if [ $? -ne 0 ]; then +if [ $? -ne 0 ] +then echo "Error: Failed to find the last tagged commit." exit 1 fi diff --git a/.github/lint-changed-yaml-tests.sh b/.github/lint-changed-yaml-tests.sh index 9b080f2f..a1a42fb3 100755 --- a/.github/lint-changed-yaml-tests.sh +++ b/.github/lint-changed-yaml-tests.sh @@ -2,7 +2,8 @@ last_tagged_commit=`git describe --always --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit -if [ $? -ne 0 ]; then +if [ $? -ne 0 ] +then echo "Error: Failed to find the last tagged commit." exit 1 fi diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4c469a98..19d7d40d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -24,7 +24,8 @@ jobs: python-version: 3.9.12 - id: stop-early run: | - if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then + if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" + then echo "status=success" >> $GITHUB_OUTPUT fi @@ -36,7 +37,8 @@ jobs: - name: Check PyPI token is defined id: check_token run: | - if [[ -n "${{ secrets.PYPI_TOKEN }}" ]]; then + if [[ -n "${{ secrets.PYPI_TOKEN }}" ]] + then echo "pypi_token_present=true" >> $GITHUB_OUTPUT else echo "pypi_token_present=false" >> $GITHUB_OUTPUT From f90bf289e03ab12efc7fdb67fce56bee2dfed668 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 10 May 2024 10:20:26 +0200 Subject: [PATCH 62/92] Add comment --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 19d7d40d..76a02ae7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,7 +29,7 @@ jobs: echo "status=success" >> $GITHUB_OUTPUT fi - check-pypi-token: + check-pypi-token: # Use intermediary job as secrets cannot be directly referenced in `if:` conditionals; see https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow runs-on: ubuntu-22.04 outputs: pypi_token_present: ${{ steps.check_token.outputs.pypi_token_present }} From cb310dc31825c905ed0ee0506e5a2e5a31603547 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 10 May 2024 10:41:07 +0200 Subject: [PATCH 63/92] Fallback to lint all files if there are no tags --- .github/lint-changed-python-files.sh | 7 +++---- .github/lint-changed-yaml-tests.sh | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh index a23bcefe..fe0709ca 100755 --- a/.github/lint-changed-python-files.sh +++ b/.github/lint-changed-python-files.sh @@ -1,11 +1,10 @@ #! /usr/bin/env bash -last_tagged_commit=`git describe --always --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit +last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent 2>/dev/null) # Attempt to find the last tagged commit in the direct ancestry of the main branch avoiding tags introduced by merge commits from other branches -if [ $? -ne 0 ] +if [ -z "$last_tagged_commit" ] then - echo "Error: Failed to find the last tagged commit." - exit 1 + last_tagged_commit=$(git rev-list --max-parents=0 HEAD) # Fallback to finding the root commit if no tags are present fi if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py") diff --git a/.github/lint-changed-yaml-tests.sh b/.github/lint-changed-yaml-tests.sh index a1a42fb3..5d3288c0 100755 --- a/.github/lint-changed-yaml-tests.sh +++ b/.github/lint-changed-yaml-tests.sh @@ -1,11 +1,10 @@ #! /usr/bin/env bash -last_tagged_commit=`git describe --always --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit +last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent 2>/dev/null) # Attempt to find the last tagged commit in the direct ancestry of the main branch avoiding tags introduced by merge commits from other branches -if [ $? -ne 0 ] +if [ -z "$last_tagged_commit" ] then - echo "Error: Failed to find the last tagged commit." - exit 1 + last_tagged_commit=$(git rev-list --max-parents=0 HEAD) # Fallback to finding the root commit if no tags are present fi if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "tests/*.yaml") From 269240f3dcbab63b0cc632d7705be5b0bfc01414 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 10 May 2024 10:50:55 +0200 Subject: [PATCH 64/92] Refactor duplication by creating a generic linting script --- .github/lint-changed-python-files.sh | 16 -------------- .github/lint-changed-yaml-tests.sh | 16 -------------- .github/lint-files.sh | 32 ++++++++++++++++++++++++++++ .github/workflows/validate.yml | 6 +++--- 4 files changed, 35 insertions(+), 35 deletions(-) delete mode 100755 .github/lint-changed-python-files.sh delete mode 100755 .github/lint-changed-yaml-tests.sh create mode 100755 .github/lint-files.sh diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh deleted file mode 100755 index fe0709ca..00000000 --- a/.github/lint-changed-python-files.sh +++ /dev/null @@ -1,16 +0,0 @@ -#! /usr/bin/env bash - -last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent 2>/dev/null) # Attempt to find the last tagged commit in the direct ancestry of the main branch avoiding tags introduced by merge commits from other branches - -if [ -z "$last_tagged_commit" ] -then - last_tagged_commit=$(git rev-list --max-parents=0 HEAD) # Fallback to finding the root commit if no tags are present -fi - -if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py") -then - echo "Linting the following Python files:" - echo $changed_files - flake8 $changed_files -else echo "No changed Python files to lint" -fi diff --git a/.github/lint-changed-yaml-tests.sh b/.github/lint-changed-yaml-tests.sh deleted file mode 100755 index 5d3288c0..00000000 --- a/.github/lint-changed-yaml-tests.sh +++ /dev/null @@ -1,16 +0,0 @@ -#! /usr/bin/env bash - -last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent 2>/dev/null) # Attempt to find the last tagged commit in the direct ancestry of the main branch avoiding tags introduced by merge commits from other branches - -if [ -z "$last_tagged_commit" ] -then - last_tagged_commit=$(git rev-list --max-parents=0 HEAD) # Fallback to finding the root commit if no tags are present -fi - -if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "tests/*.yaml") -then - echo "Linting the following changed YAML tests:" - echo $changed_files - yamllint $changed_files -else echo "No changed YAML tests to lint" -fi diff --git a/.github/lint-files.sh b/.github/lint-files.sh new file mode 100755 index 00000000..507dff81 --- /dev/null +++ b/.github/lint-files.sh @@ -0,0 +1,32 @@ +#! /usr/bin/env bash + +# Usage: lint-files.sh +# +# Example usage: +# lint-files.sh "*.py" "flake8" +# lint-files.sh "tests/*.yaml" "yamllint" + +file_pattern=$1 +linter_command=$2 + +if [ -z "$file_pattern" ] || [ -z "$linter_command" ] +then + echo "Usage: $0 " + exit 1 +fi + +last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent 2>/dev/null) # Attempt to find the last tagged commit in the direct ancestry of the main branch avoiding tags introduced by merge commits from other branches + +if [ -z "$last_tagged_commit" ] +then + last_tagged_commit=$(git rev-list --max-parents=0 HEAD) # Fallback to finding the root commit if no tags are present +fi + +if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "$file_pattern") +then + echo "Linting the following files:" + echo "$changed_files" + $linter_command $changed_files +else + echo "No changed files matching pattern '$file_pattern' to lint." +fi diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 982ee857..349f4d1c 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -33,10 +33,10 @@ jobs: - run: make check-style - name: Lint Python files - run: "${GITHUB_WORKSPACE}/.github/lint-changed-python-files.sh" - + run: "${GITHUB_WORKSPACE}/.github/lint-files.sh '*.py' 'flake8'" + - name: Lint YAML tests - run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh" + run: "${GITHUB_WORKSPACE}/.github/lint-files.sh 'tests/*.yaml' 'yamllint'" test-yaml: runs-on: ubuntu-22.04 From 0af37a7ebb4bcb1ee30d27f09c22793448c5f343 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Fri, 10 May 2024 11:02:27 +0200 Subject: [PATCH 65/92] Remove whitespaces --- .github/workflows/validate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 349f4d1c..1072fbcc 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -34,7 +34,7 @@ jobs: - name: Lint Python files run: "${GITHUB_WORKSPACE}/.github/lint-files.sh '*.py' 'flake8'" - + - name: Lint YAML tests run: "${GITHUB_WORKSPACE}/.github/lint-files.sh 'tests/*.yaml' 'yamllint'" From e61a6d15d95e4208a57127be4a9c55c4b4323112 Mon Sep 17 00:00:00 2001 From: Hamish Fraser Date: Sun, 19 May 2024 22:05:56 +1200 Subject: [PATCH 66/92] Update classifiers for supported versions of python in pyproject.toml --- CHANGELOG.md | 6 ++++++ pyproject.toml | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29db7322..71125b91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 7.1.3 [#152](https://github.com/openfisca/country-template/pull/147) + +* Technical improvement. +* Details: + - Update classifiers in pyproject.toml to include all supported versions of python + ### 7.1.2 [#147](https://github.com/openfisca/country-template/pull/147) * Technical improvement diff --git a/pyproject.toml b/pyproject.toml index 02d51f0b..070531c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openfisca-country_template" -version = "7.1.2" +version = "7.1.3" description = "OpenFisca Rules as Code model for Country-Template." readme = "README.md" keywords = ["microsimulation", "tax", "benefit", "rac", "rules-as-code"] @@ -12,6 +12,8 @@ classifiers = [ "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", ] requires-python = ">=3.9" From a4f600377d7b3fde2975151b853828be1f7c5959 Mon Sep 17 00:00:00 2001 From: Hamish Fraser Date: Fri, 24 May 2024 18:51:25 +1200 Subject: [PATCH 67/92] Update README.md python references, Reorder pyproject.toml --- CHANGELOG.md | 9 ++++++++- README.md | 6 +++--- pyproject.toml | 29 +++++++++++++++-------------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71125b91..eedfd7a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog -### 7.1.3 [#152](https://github.com/openfisca/country-template/pull/147) +### 7.1.4 [#153](https://github.com/openfisca/country-template/pull/153) + +* Technical improvement. +* Details: + - Update README.md references to latest supported python (3.11) + - Reorder pyproject.toml content to match official example + +### 7.1.3 [#152](https://github.com/openfisca/country-template/pull/152) * Technical improvement. * Details: diff --git a/README.md b/README.md index bbc8983a..bf9ffe7f 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ This involves detailed steps on preparing your package, creating distribution fi ## Install Instructions for Users and Contributors -This package requires [Python 3.9](https://www.python.org/downloads/release/python-390/). More recent versions should work, but are not tested. +This package requires [Python 3.11](https://www.python.org/downloads/release/python-390/). More recent versions should work, but are not tested. All platforms that can execute Python are supported, which includes GNU/Linux, macOS and Microsoft Windows. @@ -121,7 +121,7 @@ For more advanced uses, head to the [Advanced Installation](#advanced-installati Inside your venv, check the prerequisites: ```sh -python --version # should print "Python 3.9.xx". +python --version # should print "Python 3.11.xx". ``` ```sh @@ -163,7 +163,7 @@ Set your working directory to the location where you want this OpenFisca Country Inside your venv, check the prerequisites: ```sh -python --version # should print "Python 3.9.xx". +python --version # should print "Python 3.11.xx". ``` Clone this Country Package on your machine: diff --git a/pyproject.toml b/pyproject.toml index 070531c7..f047cc7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,15 @@ [project] name = "openfisca-country_template" -version = "7.1.3" +version = "7.1.4" +dependencies = [ + "openfisca-core[web-api] >=41.4.5, <42.0.0" +] +requires-python = ">=3.9" +authors = [] +maintainers = [] description = "OpenFisca Rules as Code model for Country-Template." readme = "README.md" keywords = ["microsimulation", "tax", "benefit", "rac", "rules-as-code"] -authors = [] -maintainers = [] classifiers = [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: GNU Affero General Public License v3", @@ -16,17 +20,6 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Topic :: Scientific/Engineering :: Information Analysis", ] -requires-python = ">=3.9" -dependencies = [ - "openfisca-core[web-api] >=41.4.5, <42.0.0" -] - -[project.urls] -Homepage = "https://github.com/openfisca/country-template" -Repository = "https://github.com/openfisca/country-template" -Documentation = "https://openfisca.org/doc" -Issues = "https://github.com/openfisca/country-template/issues" -Changelog = "https://github.com/openfisca/country-template/blob/main/CHANGELOG.md" [project.optional-dependencies] dev = [ @@ -38,6 +31,14 @@ dev = [ "yamllint >=1.35.1" ] +[project.urls] +Homepage = "https://github.com/openfisca/country-template" +Repository = "https://github.com/openfisca/country-template" +Documentation = "https://openfisca.org/doc" +Issues = "https://github.com/openfisca/country-template/issues" +Changelog = "https://github.com/openfisca/country-template/blob/main/CHANGELOG.md" + + [tool.pytest.ini_options] addopts = "--showlocals --doctest-modules" testpaths = [ "openfisca_country_template/tests" ] From 93b17e983b2ca227f7cfa6d6dde4fe356cb29433 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Fri, 27 Sep 2024 00:28:50 +0200 Subject: [PATCH 68/92] chore(deps): bump core --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f047cc7b..1053ce23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "openfisca-country_template" version = "7.1.4" dependencies = [ - "openfisca-core[web-api] >=41.4.5, <42.0.0" + "openfisca-core[web-api] @ https://github.com/openfisca/openfisca-core/archive/fix-mypy-checks-periods.zip" ] requires-python = ">=3.9" authors = [] @@ -80,8 +80,8 @@ known_openfisca = [ "openfisca_country_template" ] known_typing = [ - "mypy*", - "*types*", + "mypy*", + "*types*", "*typing*" ] sections = [ From 6fba5ee5192706cc4d951a7e796c2e323ae25bf1 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Fri, 27 Sep 2024 00:36:34 +0200 Subject: [PATCH 69/92] chore: version bump --- CHANGELOG.md | 7 ++++++- Makefile | 2 +- pyproject.toml | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eedfd7a8..7e59ceff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +### 7.1.5 [#154](https://github.com/openfisca/country-template/pull/154) + +* Minor change. + - Update OpenFisca-Core to 42.0.0 + ### 7.1.4 [#153](https://github.com/openfisca/country-template/pull/153) * Technical improvement. @@ -7,7 +12,7 @@ - Update README.md references to latest supported python (3.11) - Reorder pyproject.toml content to match official example -### 7.1.3 [#152](https://github.com/openfisca/country-template/pull/152) +### 7.1.3 [#152](https://github.com/openfisca/country-template/pull/147) * Technical improvement. * Details: diff --git a/Makefile b/Makefile index 7f9f5a46..9e57fd6e 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 diff --git a/pyproject.toml b/pyproject.toml index 1053ce23..6c97619c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,8 @@ [project] name = "openfisca-country_template" -version = "7.1.4" +version = "7.1.5" dependencies = [ - "openfisca-core[web-api] @ https://github.com/openfisca/openfisca-core/archive/fix-mypy-checks-periods.zip" + "openfisca-core[web-api] >= 42.0.0, <43.0.0", ] requires-python = ">=3.9" authors = [] From b8131ffbfb5da3eb746862ae9ea59e46769d1959 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 14 Oct 2024 16:20:13 +0200 Subject: [PATCH 70/92] build: normalize pyproject --- .flake8 | 20 ---- Makefile | 13 ++- openfisca_country_template/__init__.py | 24 ++-- openfisca_country_template/entities.py | 63 ++++++----- .../reforms/__init__.py | 6 +- .../reforms/add_dynamic_variable.py | 49 ++++---- .../reforms/add_new_tax.py | 14 +-- .../flat_social_security_contribution.py | 25 ++-- .../modify_social_security_taxation.py | 32 +++--- .../reforms/removal_basic_income.py | 19 ++-- .../situation_examples/__init__.py | 3 +- .../variables/__init__.py | 3 +- .../variables/benefits.py | 76 ++++++++----- .../variables/demographics.py | 20 ++-- .../variables/housing.py | 10 +- .../variables/income.py | 17 +-- openfisca_country_template/variables/stats.py | 26 +++-- openfisca_country_template/variables/taxes.py | 43 ++++--- pyproject.toml | 107 ++++++++++-------- 19 files changed, 303 insertions(+), 267 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index cd91d602..00000000 --- a/.flake8 +++ /dev/null @@ -1,20 +0,0 @@ -[flake8] -hang-closing = true -ignore = D101,D102,D103,D107,D401,E128,E251,E501,W503 -in-place = true -inline-quotes = " -multiline-quotes = """ -import-order-style = appnexus -no-accept-encodings = true -application-import-names = openfisca_country_template -application-package-names = openfisca_core -exclude = .git,__pycache__,.venv,.github,.devcontainer,docs - -; D101: Variables already provide label/description -; D102/103: Do not document methods/functions -; D107: Do not document __init__ method -; D401: Do not require the imperative mood -; E128/133: Prefer hang-closing visual indents -; E251: Prefer `function(x = 1)` over `function(x=1)` -; E501: Do not enforce a maximum line length -; W503/4: Break lines before binary operators (Knuth's style) diff --git a/Makefile b/Makefile index 9e57fd6e..978269a2 100644 --- a/Makefile +++ b/Makefile @@ -14,13 +14,14 @@ install: deps @# Install OpenFisca-Extension-Template for development. @# `make install` installs the editable version of openfisca-country_template. @# This allows contributors to test as they code. - pip install --editable .[dev] --upgrade --use-deprecated=legacy-resolver + pip install --editable .[dev] --upgrade build: clean deps @# Install OpenFisca-Extension-Template for deployment and publishing. @# `make build` allows us to be be sure tests are run against the packaged version @# of OpenFisca-Extension-Template, the same we put in the hands of users and reusers. python -m build + pip uninstall --yes openfisca-country-template find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; check-syntax-errors: @@ -29,16 +30,16 @@ 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 --py39-plus `git ls-files | grep "\.py$$"` + 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$$"` - yamllint `git ls-files | grep "\.yaml$$"` + 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 --country-package openfisca_country_template openfisca_country_template/tests diff --git a/openfisca_country_template/__init__.py b/openfisca_country_template/__init__.py index a1ca8a92..d8fc243b 100644 --- a/openfisca_country_template/__init__.py +++ b/openfisca_country_template/__init__.py @@ -1,9 +1,11 @@ -""" -This file defines our country's tax and benefit system. +"""This file defines our country's tax and benefit system. A tax and benefit system is the higher-level instance in OpenFisca. + Its goal is to model the legislation of a country. -Basically a tax and benefit system contains simulation variables (source code) and legislation parameters (data). + +Basically a tax and benefit system contains simulation variables (source code) +and legislation parameters (data). See https://openfisca.org/doc/key-concepts/tax_and_benefit_system.html """ @@ -15,27 +17,31 @@ from openfisca_country_template import entities from openfisca_country_template.situation_examples import couple - COUNTRY_DIR = os.path.dirname(os.path.abspath(__file__)) -# Our country tax and benefit class inherits from the general TaxBenefitSystem class. -# 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. +# Our country tax and benefit class inherits from the general TaxBenefitSystem +# class. 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. class CountryTaxBenefitSystem(TaxBenefitSystem): def __init__(self): + """Initialize our country's tax and benefit system.""" # We initialize our tax and benefit system with the general constructor super().__init__(entities.entities) # We add to our tax and benefit system all the variables self.add_variables_from_directory(os.path.join(COUNTRY_DIR, "variables")) - # We add to our tax and benefit system all the legislation parameters defined in the parameters files + # We add to our tax and benefit system all the legislation parameters + # defined in the parameters files param_path = os.path.join(COUNTRY_DIR, "parameters") self.load_parameters(param_path) - # We define which variable, parameter and simulation example will be used in the OpenAPI specification + # We define which variable, parameter and simulation example will be + # used in the OpenAPI specification self.open_api_config = { "variable_example": "disposable_income", "parameter_example": "taxes.income_tax_rate", "simulation_example": couple, - } + } diff --git a/openfisca_country_template/entities.py b/openfisca_country_template/entities.py index 297bed6a..2cd3c255 100644 --- a/openfisca_country_template/entities.py +++ b/openfisca_country_template/entities.py @@ -1,7 +1,7 @@ -""" -This file defines the entities needed by our legislation. +"""This file defines the entities needed by our legislation. -Taxes and benefits can be calculated for different entities: persons, household, companies, etc. +Taxes and benefits can be calculated for different entities: persons, household, +companies, etc. See https://openfisca.org/doc/key-concepts/person,_entities,_role.html """ @@ -9,24 +9,32 @@ from openfisca_core.entities import build_entity Household = build_entity( - key = "household", - plural = "households", - label = "All the people in a family or group who live together in the same place.", - doc = """ + key="household", + plural="households", + label="All the people in a family or group who live together in the same place.", + doc=""" Household is an example of a group entity. A group entity contains one or more individual·s. - 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'). + 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'). Example: - Housing variables (e.g. housing_tax') are usually defined for a group entity such as 'Household'. + Housing variables (e.g. housing_tax') are usually defined for a group + entity such as 'Household'. Usage: - 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)). - 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)). + 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)). + 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)). For more information, see: https://openfisca.org/doc/coding-the-legislation/50_entities.html """, - roles = [ + roles=[ { "key": "parent", "plural": "parents", @@ -34,31 +42,34 @@ "max": 2, "subroles": ["first_parent", "second_parent"], "doc": "The one or two adults in charge of the household.", - }, + }, { "key": "child", "plural": "children", "label": "Child", "doc": "Other individuals living in the household.", - }, - ], - ) + }, + ], +) Person = build_entity( - key = "person", - plural = "persons", - label = "An individual. The minimal legal entity on which a legislation might be applied.", - doc = """ - - Variables like 'salary' and 'income_tax' are usually defined for the entity 'Person'. + key="person", + plural="persons", + label="An individual. The minimal entity on which legislation can be applied.", + doc=""" + Variables like 'salary' and 'income_tax' are usually defined for the entity + 'Person'. Usage: - Calculate a variable applied to a 'Person' (e.g. access the 'salary' of a specific month with person("salary", "2017-05")). - 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)). + Calculate a variable applied to a 'Person' (e.g. access the 'salary' of + a specific month with person("salary", "2017-05")). + 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)). For more information, see: https://openfisca.org/doc/coding-the-legislation/50_entities.html """, - is_person = True, - ) + is_person=True, +) entities = [Household, Person] diff --git a/openfisca_country_template/reforms/__init__.py b/openfisca_country_template/reforms/__init__.py index bde04d0a..ee4e01ea 100644 --- a/openfisca_country_template/reforms/__init__.py +++ b/openfisca_country_template/reforms/__init__.py @@ -1,7 +1,7 @@ -""" -This sub-package is used to define reforms. +"""This sub-package is used to define reforms. -A reform is a set of modifications to be applied to a reference tax and benefit system to carry out experiments. +A reform is a set of modifications to be applied to a reference tax and benefit +system to carry out experiments. See https://openfisca.org/doc/key-concepts/reforms.html """ diff --git a/openfisca_country_template/reforms/add_dynamic_variable.py b/openfisca_country_template/reforms/add_dynamic_variable.py index 84718662..60d28414 100644 --- a/openfisca_country_template/reforms/add_dynamic_variable.py +++ b/openfisca_country_template/reforms/add_dynamic_variable.py @@ -1,12 +1,12 @@ -""" -This file defines a reform to add a dynamic variable, based on input data. +"""This file defines a reform to add a dynamic variable, based on input data. -A reform is a set of modifications to be applied to a reference tax and benefit system to carry out experiments. +A reform is a set of modifications to be applied to a reference tax and benefit +system to carry out experiments. See https://openfisca.org/doc/key-concepts/reforms.html """ -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from openfisca-core the objects used to code the legislation in OpenFisca from openfisca_core.periods import MONTH from openfisca_core.reforms import Reform from openfisca_core.variables import Variable @@ -17,22 +17,23 @@ def create_dynamic_variable(name, **variable): """Create new variable dynamically.""" - NewVariable = type(name, (Variable,), { - "value_type": variable["value_type"], - "entity": variable["entity"], - "default_value": variable["default_value"], - "definition_period": variable["definition_period"], - "label": variable["label"], - "reference": variable["reference"], - }) - - return NewVariable + return type( + name, + (Variable,), + { + "value_type": variable["value_type"], + "entity": variable["entity"], + "default_value": variable["default_value"], + "definition_period": variable["definition_period"], + "label": variable["label"], + "reference": variable["reference"], + }, + ) class add_dynamic_variable(Reform): def apply(self): - """ - Apply reform. + """Apply reform. A reform always defines an `apply` method that builds the reformed tax and benefit system from the reference one. @@ -40,13 +41,13 @@ def apply(self): See https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform """ NewVariable = create_dynamic_variable( - name = "goes_to_school", - value_type = bool, - entity = Person, - default_value = True, - definition_period = MONTH, - label = "The person goes to school (only relevant for children)", - reference = "https://law.gov.example/goes_to_school", - ) + name="goes_to_school", + value_type=bool, + entity=Person, + default_value=True, + definition_period=MONTH, + label="The person goes to school (only relevant for children)", + reference="https://law.gov.example/goes_to_school", + ) self.add_variable(NewVariable) diff --git a/openfisca_country_template/reforms/add_new_tax.py b/openfisca_country_template/reforms/add_new_tax.py index 710698c3..b9a5ac54 100644 --- a/openfisca_country_template/reforms/add_new_tax.py +++ b/openfisca_country_template/reforms/add_new_tax.py @@ -1,12 +1,12 @@ -""" -This file defines a reform. +"""This file defines a reform. -A reform is a set of modifications to be applied to a reference tax and benefit system to carry out experiments. +A reform is a set of modifications to be applied to a reference tax and benefit +system to carry out experiments. See https://openfisca.org/doc/key-concepts/reforms.html """ -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from openfisca-core the objects used to code the legislation in OpenFisca from openfisca_core.periods import MONTH from openfisca_core.reforms import Reform from openfisca_core.variables import Variable @@ -32,8 +32,7 @@ class new_tax(Variable): reference = "https://law.gov.example/new_tax" # Always use the most official source def formula(person, period, _parameters): - """ - New tax reform. + """New tax reform. Our reform adds a new variable `new_tax` that is calculated based on the current `income_tax`, if the person has a car. @@ -46,8 +45,7 @@ def formula(person, period, _parameters): class add_new_tax(Reform): def apply(self): - """ - Apply reform. + """Apply reform. A reform always defines an `apply` method that builds the reformed tax and benefit system from the reference one. diff --git a/openfisca_country_template/reforms/flat_social_security_contribution.py b/openfisca_country_template/reforms/flat_social_security_contribution.py index c224fc1c..dddc9a44 100644 --- a/openfisca_country_template/reforms/flat_social_security_contribution.py +++ b/openfisca_country_template/reforms/flat_social_security_contribution.py @@ -1,34 +1,35 @@ -""" -This file defines a reform. +"""This file defines a reform. -A reform is a set of modifications to be applied to a reference tax and benefit system to carry out experiments. +A reform is a set of modifications to be applied to a reference tax and benefit +system to carry out experiments. See https://openfisca.org/doc/key-concepts/reforms.html """ -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from openfisca-core the objects used to code the legislation in OpenFisca from openfisca_core.reforms import Reform from openfisca_core.variables import Variable class social_security_contribution(Variable): - # Variable metadata don't need to be redefined. By default, the reference variable metadatas will be used. + # Variable metadata don't need to be redefined. By default, the reference + # variable metadata will be used. def formula(person, period, _parameters): - """ - Social security contribution reform. + """Social security contribution reform. - Our reform replaces `social_security_contribution` (the "reference" variable) by the following variable. + Our reform replaces `social_security_contribution` (the "reference" + variable) by the following variable. """ return person("salary", period) * 0.03 class flat_social_security_contribution(Reform): def apply(self): - """ - Apply reform. + """Apply reform. - A reform always defines an `apply` method that builds the reformed tax and benefit system from the reference one. - See https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform + A reform always defines an `apply` method that builds the reformed tax + and benefit system from the reference one. See + https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform """ self.update_variable(social_security_contribution) diff --git a/openfisca_country_template/reforms/modify_social_security_taxation.py b/openfisca_country_template/reforms/modify_social_security_taxation.py index 7d4099d7..6e88c123 100644 --- a/openfisca_country_template/reforms/modify_social_security_taxation.py +++ b/openfisca_country_template/reforms/modify_social_security_taxation.py @@ -1,35 +1,35 @@ -""" -This file defines a reform. +"""This file defines a reform. -A reform is a set of modifications to be applied to a reference tax and benefit system to carry out experiments. +A reform is a set of modifications to be applied to a reference tax and benefit +system to carry out experiments. See https://openfisca.org/doc/key-concepts/reforms.html """ -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from openfisca-core the objects used to code the legislation in OpenFisca from openfisca_core.parameters import ParameterScaleBracket from openfisca_core.reforms import Reform class modify_social_security_taxation(Reform): def apply(self): - """ - Apply reform. + """Apply reform. - A reform always defines an `apply` method that builds the reformed tax and benefit system from the reference one. - See https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform + A reform always defines an `apply` method that builds the reformed tax + and benefit system from the reference one. See + https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform - Our reform modifies the `social_security_contribution` parameter, which is a scale. - This parameter is declared in `parameters/taxes/social_security_contribution.yaml`. + Our reform modifies the `social_security_contribution` parameter, which + is a scale. This parameter is declared in + `parameters/taxes/social_security_contribution.yaml`. See https://openfisca.org/doc/coding-the-legislation/legislation_parameters.html """ - self.modify_parameters(modifier_function = self.modify_brackets) + self.modify_parameters(modifier_function=self.modify_brackets) @staticmethod def modify_brackets(parameters): - """ - Social security taxation reform. + """Social security taxation reform. This function takes an argument `parameters` which is a in-memory representation of the YAML parameters. It can be modified and must be returned. @@ -47,11 +47,11 @@ def modify_brackets(parameters): # Add a new bracket with a higher tax rate for rich people: new_bracket = ParameterScaleBracket( "new_bracket", - data = { + data={ "rate": {"2017-01-01": {"value": 0.4}}, "threshold": {"2017-01-01": {"value": 40000}}, - }, - ) + }, + ) brackets.append(new_bracket) return parameters diff --git a/openfisca_country_template/reforms/removal_basic_income.py b/openfisca_country_template/reforms/removal_basic_income.py index 58de4968..754e7558 100644 --- a/openfisca_country_template/reforms/removal_basic_income.py +++ b/openfisca_country_template/reforms/removal_basic_income.py @@ -1,23 +1,24 @@ -""" -This file defines a reform. +"""This file defines a reform. -A reform is a set of modifications to be applied to a reference tax and benefit system to carry out experiments. +A reform is a set of modifications to be applied to a reference tax and benefit +system to carry out experiments. See https://openfisca.org/doc/key-concepts/reforms.html """ -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from openfisca-core the objects used to code the legislation in OpenFisca from openfisca_core.reforms import Reform class removal_basic_income(Reform): def apply(self): - """ - Apply reform. + """Apply reform. - A reform always defines an `apply` method that builds the reformed tax and benefit system from the reference one. - See https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform + A reform always defines an `apply` method that builds the reformed tax + and benefit system from the reference one. See + https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform - Our reform neutralizes the `basic_income` variable. When this reform is applied, calculating `basic_income` will always return its default value, 0. + Our reform neutralizes the `basic_income` variable. When this reform is + applied, calculating `basic_income` will always return its default value, 0. """ self.neutralize_variable("basic_income") diff --git a/openfisca_country_template/situation_examples/__init__.py b/openfisca_country_template/situation_examples/__init__.py index b1b7cfb4..27ef68f7 100644 --- a/openfisca_country_template/situation_examples/__init__.py +++ b/openfisca_country_template/situation_examples/__init__.py @@ -3,14 +3,13 @@ import json import os - DIR_PATH = os.path.dirname(os.path.abspath(__file__)) def parse(file_name): """Load json example situations.""" file_path = os.path.join(DIR_PATH, file_name) - with open(file_path, "r", encoding="utf8") as file: + with open(file_path, encoding="utf8") as file: return json.loads(file.read()) diff --git a/openfisca_country_template/variables/__init__.py b/openfisca_country_template/variables/__init__.py index 718ad20d..dd8e3f45 100644 --- a/openfisca_country_template/variables/__init__.py +++ b/openfisca_country_template/variables/__init__.py @@ -1,5 +1,4 @@ -""" -This sub-package is used to define variables. +"""This sub-package is used to define variables. A variable is a property of an Entity such as a Person, a Household… diff --git a/openfisca_country_template/variables/benefits.py b/openfisca_country_template/variables/benefits.py index 3703113d..13319be4 100644 --- a/openfisca_country_template/variables/benefits.py +++ b/openfisca_country_template/variables/benefits.py @@ -1,12 +1,11 @@ -""" -This file defines variables for the modelled legislation. +"""This file defines variables 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 """ -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from openfisca-core the objects used to code the legislation in OpenFisca from openfisca_core.periods import MONTH from openfisca_core.variables import Variable @@ -19,27 +18,39 @@ class basic_income(Variable): entity = Person definition_period = MONTH label = "Basic income provided to adults" - reference = "https://law.gov.example/basic_income" # Always use the most official source + reference = ( + "https://law.gov.example/basic_income" # Always use the most official source + ) def formula_2016_12(person, period, parameters): - """ - Basic income provided to adults. + """Basic income provided to adults. - Since Dec 1st 2016, the basic income is provided to any adult, without considering their income. + Since Dec 1st 2016, the basic income is provided to any adult, without + considering their income. """ - age_condition = person("age", period) >= parameters(period).general.age_of_majority - return age_condition * parameters(period).benefits.basic_income # This '*' is a vectorial 'if'. See https://openfisca.org/doc/coding-the-legislation/25_vectorial_computing.html#control-structures + age_condition = ( + person("age", period) >= parameters(period).general.age_of_majority + ) + # This '*' is a vectorial 'if'. See + # https://openfisca.org/doc/coding-the-legislation/25_vectorial_computing.html#control-structures + return age_condition * parameters(period).benefits.basic_income def formula_2015_12(person, period, parameters): - """ - Basic income provided to adults. + """Basic income provided to adults. - From Dec 1st 2015 to Nov 30 2016, the basic income is provided to adults who have no income. - Before Dec 1st 2015, the basic income does not exist in the law, and calculating it returns its default value, which is 0. + From Dec 1st 2015 to Nov 30 2016, the basic income is provided to adults + who have no income. Before Dec 1st 2015, the basic income does not exist + in the law, and calculating it returns its default value, which is 0. """ - age_condition = person("age", period) >= parameters(period).general.age_of_majority + age_condition = ( + person("age", period) >= parameters(period).general.age_of_majority + ) salary_condition = person("salary", period) == 0 - return age_condition * salary_condition * parameters(period).benefits.basic_income # The '*' is also used as a vectorial 'and'. See https://openfisca.org/doc/coding-the-legislation/25_vectorial_computing.html#boolean-operations + # The '*' is also used as a vectorial 'and'. See + # https://openfisca.org/doc/coding-the-legislation/25_vectorial_computing.html#boolean-operations + return ( + age_condition * salary_condition * parameters(period).benefits.basic_income + ) class housing_allowance(Variable): @@ -47,8 +58,11 @@ class housing_allowance(Variable): entity = Household definition_period = MONTH label = "Housing allowance" - reference = "https://law.gov.example/housing_allowance" # Always use the most official source - end = "2016-11-30" # This allowance was removed on the 1st of Dec 2016. Calculating it before this date will always return the variable default value, 0. + # Always use the most official source + reference = "https://law.gov.example/housing_allowance" + # This allowance was removed on the 1st of Dec 2016. Calculating it before + # this date will always return the variable default value, 0. + end = "2016-11-30" unit = "currency-EUR" documentation = """ This allowance was introduced on the 1st of Jan 1980. @@ -56,36 +70,37 @@ class housing_allowance(Variable): """ def formula_1980(household, period, parameters): - """ - Housing allowance. + """Housing allowance. - This allowance was introduced on the 1st of Jan 1980. - Calculating it before this date will always return the variable default value, 0. + This allowance was introduced on the 1st of Jan 1980. Calculating it + before this date will always return the variable default value, 0. - To compute this allowance, the 'rent' value must be provided for the same month, - but 'housing_occupancy_status' is not necessary. + To compute this allowance, the 'rent' value must be provided for the + same month, but 'housing_occupancy_status' is not necessary. """ return household("rent", period) * parameters(period).benefits.housing_allowance -# By default, you can use utf-8 characters in a variable. OpenFisca web API manages utf-8 encoding. +# By default, you can use utf-8 characters in a variable. OpenFisca web API +# manages utf-8 encoding. class pension(Variable): value_type = float entity = Person definition_period = MONTH label = "Pension for the elderly. Pension attribuée aux personnes âgées. تقاعد." - reference = ["https://fr.wikipedia.org/wiki/Retraite_(économie)", "https://ar.wikipedia.org/wiki/تقاعد"] + reference = ( + "https://fr.wikipedia.org/wiki/Retraite_(économie)", + "https://ar.wikipedia.org/wiki/تقاعد", + ) def formula(person, period, parameters): - """ - Pension for the elderly. + """Pension for the elderly. A person's pension depends on their birth date. In French: retraite selon l'âge. In Arabic: تقاعد. """ - age_condition = person("age", period) >= parameters(period).general.age_of_retirement - return age_condition + return person("age", period) >= parameters(period).general.age_of_retirement class parenting_allowance(Variable): @@ -97,8 +112,7 @@ class parenting_allowance(Variable): reference = "https://www.servicesaustralia.gov.au/individuals/services/centrelink/parenting-payment/who-can-get-it" def formula(household, period, parameters): - """ - Parenting allowance for households. + """Parenting allowance for households. A person's parenting allowance depends on how many dependents they have, how much they, and their partner, earn diff --git a/openfisca_country_template/variables/demographics.py b/openfisca_country_template/variables/demographics.py index e2872a99..406d9e47 100644 --- a/openfisca_country_template/variables/demographics.py +++ b/openfisca_country_template/variables/demographics.py @@ -1,5 +1,4 @@ -""" -This file defines variables for the modelled legislation. +"""This file defines variables for the modelled legislation. A variable is a property of an Entity such as a Person, a Household… @@ -9,7 +8,7 @@ from datetime import date # Import from numpy the operations you need to apply on OpenFisca's population vectors -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from openfisca-core the objects used to code the legislation in OpenFisca from numpy import where from openfisca_core.periods import ETERNITY, MONTH @@ -22,7 +21,9 @@ # This variable is a pure input: it doesn't have a formula class birth(Variable): value_type = date - default_value = date(1970, 1, 1) # By default, if no value is set for a simulation, we consider the people involved in a simulation to be born on the 1st of Jan 1970. + # By default, if no value is set for a simulation, we consider the people + # involved in a simulation to be born on the 1st of Jan 1970. + default_value = date(1970, 1, 1) entity = Person label = "Birth date" definition_period = ETERNITY # This variable cannot change over time. @@ -36,8 +37,7 @@ class age(Variable): label = "Person's age (in years)" def formula(person, period, _parameters): - """ - Person's age (in years). + """Person's age (in years). A person's age is computed according to its birth date. """ @@ -46,6 +46,10 @@ def formula(person, period, _parameters): birth_month = birth.astype("datetime64[M]").astype(int) % 12 + 1 birth_day = (birth - birth.astype("datetime64[M]") + 1).astype(int) - is_birthday_past = (birth_month < period.start.month) + (birth_month == period.start.month) * (birth_day <= period.start.day) + is_birthday_past = (birth_month < period.start.month) + ( + birth_month == period.start.month + ) * (birth_day <= period.start.day) - return (period.start.year - birth_year) - where(is_birthday_past, 0, 1) # If the birthday is not passed this year, subtract one year + return (period.start.year - birth_year) - where( + is_birthday_past, 0, 1 + ) # If the birthday is not passed this year, subtract one year diff --git a/openfisca_country_template/variables/housing.py b/openfisca_country_template/variables/housing.py index 780720e9..eec53fdf 100644 --- a/openfisca_country_template/variables/housing.py +++ b/openfisca_country_template/variables/housing.py @@ -1,12 +1,11 @@ -""" -This file defines variables for the modelled legislation. +"""This file defines variables 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 """ -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from openfisca-core the objects used to code the legislation in OpenFisca from openfisca_core.indexed_enums import Enum from openfisca_core.periods import MONTH from openfisca_core.variables import Variable @@ -31,8 +30,9 @@ class rent(Variable): label = "Rent paid by the household" -# Possible values for the housing_occupancy_status variable, defined further down -# See more at +# Possible values for the housing_occupancy_status variable, defined further +# down. See more at +# class HousingOccupancyStatus(Enum): __order__ = "owner tenant free_lodger homeless" owner = "Owner" diff --git a/openfisca_country_template/variables/income.py b/openfisca_country_template/variables/income.py index 1b48144c..1479471b 100644 --- a/openfisca_country_template/variables/income.py +++ b/openfisca_country_template/variables/income.py @@ -1,12 +1,11 @@ -""" -This file defines variables for the modelled legislation. +"""This file defines variables 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 """ -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from openfisca-core the objects used to code the legislation in OpenFisca from openfisca_core.holders import set_input_divide_by_period from openfisca_core.periods import MONTH from openfisca_core.variables import Variable @@ -20,7 +19,9 @@ class salary(Variable): value_type = float entity = Person definition_period = MONTH - set_input = set_input_divide_by_period # Optional attribute. Allows user to declare a salary for a year. OpenFisca will spread the yearly amount over the months contained in the year. + # Optional attribute. Allows user to declare a salary for a year. OpenFisca + # will spread the yearly amount over the months contained in the year. + set_input = set_input_divide_by_period label = "Salary" reference = "https://law.gov.example/salary" # Always use the most official source @@ -30,13 +31,15 @@ class disposable_income(Variable): entity = Person definition_period = MONTH label = "Actual amount available to the person at the end of the month" - reference = "https://stats.gov.example/disposable_income" # Some variables represent quantities used in economic models, and not defined by law. Always give the source of your definitions. + # Some variables represent quantities used in economic models, and not + # defined by law. Always give the source of your definitions. + reference = "https://stats.gov.example/disposable_income" def formula(person, period, _parameters): """Disposable income.""" return ( - + person("salary", period) + +person("salary", period) + person("basic_income", period) - person("income_tax", period) - person("social_security_contribution", period) - ) + ) diff --git a/openfisca_country_template/variables/stats.py b/openfisca_country_template/variables/stats.py index d2fa6f49..361f1c45 100644 --- a/openfisca_country_template/variables/stats.py +++ b/openfisca_country_template/variables/stats.py @@ -1,12 +1,11 @@ -""" -This file defines variables for the modelled legislation. +"""This file defines variables 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 """ -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from openfisca-core the objects used to code the legislation in OpenFisca from openfisca_core.periods import MONTH from openfisca_core.variables import Variable @@ -23,12 +22,15 @@ class total_benefits(Variable): def formula(household, period, _parameters): """Total benefits.""" - basic_income_i = household.members("basic_income", period) # Calculates the value of basic_income for each member of the household + basic_income_i = household.members( + "basic_income", period + ) # Calculates the value of basic_income for each member of the household - return ( - + household.sum(basic_income_i) # Sum the household members basic incomes - + household("housing_allowance", period) - ) + return +household.sum( + basic_income_i + ) + household( # Sum the household members basic incomes + "housing_allowance", period + ) class total_taxes(Variable): @@ -41,10 +43,12 @@ class total_taxes(Variable): def formula(household, period, _parameters): """Total taxes.""" income_tax_i = household.members("income_tax", period) - social_security_contribution_i = household.members("social_security_contribution", period) + social_security_contribution_i = household.members( + "social_security_contribution", period + ) return ( - + household.sum(income_tax_i) + +household.sum(income_tax_i) + household.sum(social_security_contribution_i) + household("housing_tax", period.this_year) / 12 - ) + ) diff --git a/openfisca_country_template/variables/taxes.py b/openfisca_country_template/variables/taxes.py index 5e93700e..b6dd6a6c 100644 --- a/openfisca_country_template/variables/taxes.py +++ b/openfisca_country_template/variables/taxes.py @@ -1,13 +1,12 @@ -""" -This file defines variables for the modelled legislation. +"""This file defines variables 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 """ -# Import from numpy the operations you need to apply on OpenFisca's population vectors -# Import from openfisca-core the Python objects used to code the legislation in OpenFisca +# Import from numpy the what you need to apply on OpenFisca's population vectors +# Import from openfisca-core the objects used to code the legislation in OpenFisca from numpy import maximum as max_ from openfisca_core.periods import MONTH, YEAR @@ -22,11 +21,12 @@ class income_tax(Variable): entity = Person definition_period = MONTH label = "Income tax" - reference = "https://law.gov.example/income_tax" # Always use the most official source + reference = ( + "https://law.gov.example/income_tax" # Always use the most official source + ) def formula(person, period, parameters): - """ - Income tax. + """Income tax. The formula to compute the income tax for a given person at a given period """ @@ -38,11 +38,11 @@ class social_security_contribution(Variable): entity = Person definition_period = MONTH label = "Progressive contribution paid on salaries to finance social security" - reference = "https://law.gov.example/social_security_contribution" # Always use the most official source + # Always use the most official source + reference = "https://law.gov.example/social_security_contribution" def formula(person, period, parameters): - """ - Social security contribution. + """Social security contribution. The social_security_contribution is computed according to a marginal scale. """ @@ -57,25 +57,32 @@ class housing_tax(Variable): entity = Household definition_period = YEAR # This housing tax is defined for a year. label = "Tax paid by each household proportionally to the size of its accommodation" - reference = "https://law.gov.example/housing_tax" # Always use the most official source + reference = ( + "https://law.gov.example/housing_tax" # Always use the most official source + ) def formula(household, period, parameters): - """ - Housing tax. + """Housing tax. - The housing tax is defined for a year, but depends on the `accommodation_size` and `housing_occupancy_status` on the first month of the year. - Here period is a year. We can get the first month of a year with the following shortcut. - To build different periods, see https://openfisca.org/doc/coding-the-legislation/35_periods.html#calculate-dependencies-for-a-specific-period + The housing tax is defined for a year, but depends on the `accommodation_size` + and `housing_occupancy_status` on the first month of the year. Here period + is a year. We can get the first month of a year with the following shortcut. + To build different periods, see + https://openfisca.org/doc/coding-the-legislation/35_periods.html#calculate-dependencies-for-a-specific-period """ january = period.first_month accommodation_size = household("accommodation_size", january) tax_params = parameters(period).taxes.housing_tax - tax_amount = max_(accommodation_size * tax_params.rate, tax_params.minimal_amount) + tax_amount = max_( + accommodation_size * tax_params.rate, tax_params.minimal_amount + ) # `housing_occupancy_status` is an Enum variable occupancy_status = household("housing_occupancy_status", january) - HousingOccupancyStatus = occupancy_status.possible_values # Get the enum associated with the variable + HousingOccupancyStatus = ( + occupancy_status.possible_values + ) # Get the enum associated with the variable # To access an enum element, we use the `.` notation. tenant = occupancy_status == HousingOccupancyStatus.tenant owner = occupancy_status == HousingOccupancyStatus.owner diff --git a/pyproject.toml b/pyproject.toml index 6c97619c..88fe379c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "openfisca-country_template" version = "7.1.5" dependencies = [ - "openfisca-core[web-api] >= 42.0.0, <43.0.0", + "openfisca-core[web-api] >= 43", ] requires-python = ">=3.9" authors = [] @@ -23,11 +23,10 @@ classifiers = [ [project.optional-dependencies] dev = [ - "autopep8 >=2.0.4", - "flake8 >=7.0.0", - "isort >=5.13.2", - "pylint >=3.1.0", - "pyupgrade >=3.15.1", + "black >=24.8.0, <25.0", + "isort >=5.13.2, <6.0", + "ruff >=0.6.9, <1.0", + "ruff-lsp >=0.0.57, <1.0", "yamllint >=1.35.1" ] @@ -39,57 +38,65 @@ Issues = "https://github.com/openfisca/country-template/issues" Changelog = "https://github.com/openfisca/country-template/blob/main/CHANGELOG.md" -[tool.pytest.ini_options] -addopts = "--showlocals --doctest-modules" -testpaths = [ "openfisca_country_template/tests" ] -python_files = "**/*.py" -filterwarnings = [ - "error", - "ignore::UserWarning", - 'ignore:function ham\(\) is deprecated:DeprecationWarning' -] - -[tool.pylint.messages_control] -disable = [ - "invalid-name", - "missing-class-docstring", - "missing-function-docstring", - "line-too-long", - "no-self-argument", - "invalid-enum-extension", - "no-member", - "not-callable", - "duplicate-code", - "too-many-locals", - "fixme", - "unused-argument", - "redefined-outer-name" -] -score = "no" +[tool.black] +target_version = ["py39", "py310", "py311"] [tool.isort] -case_sensitive = "true" -force_alphabetical_sort_within_sections = "false" -group_by_package = "true" -include_trailing_comma = "true" -multi_line_output = "8" -py_version = "39" -known_first_party = "openfisca_country_template" -known_openfisca = [ - "openfisca_core", - "openfisca_country_template" -] -known_typing = [ - "mypy*", - "*types*", - "*typing*" -] +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_country_template"] +known_openfisca = ["openfisca_core", "openfisca_extension_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" + "LOCALFOLDER", ] + +[tool.pytest.ini_options] +addopts = "--exitfirst --showlocals --doctest-modules" +testpaths = [ "openfisca_country_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 = [ + "ANN", + "COM812", + "D101", + "D104", + "I001", + "ISC001", + "N801", + "N805", + "N806", + "PLR2004", + "PTH100", + "PTH118", + "PTH120", + "PTH123", +] +select = ["ALL"] + +[tool.ruff.lint.pydocstyle] +convention = "google" From ea59d9cbeeb658f20eb227d39e4747abb6db1754 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 14 Oct 2024 16:24:56 +0200 Subject: [PATCH 71/92] chore: version bump --- CHANGELOG.md | 8 ++++++++ pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e59ceff..af454e30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +### 7.1.6 [#156](https://github.com/openfisca/country-template/pull/156) + +* Minor change. +* Impacted areas: `**/*` +* Details: + - Normalize `pyproject.toml` + - Update OpenFisca-Core to 43.0.0 + ### 7.1.5 [#154](https://github.com/openfisca/country-template/pull/154) * Minor change. diff --git a/pyproject.toml b/pyproject.toml index 88fe379c..7aade143 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openfisca-country_template" -version = "7.1.5" +version = "7.1.6" dependencies = [ "openfisca-core[web-api] >= 43", ] From 69d065ef29c0ae6d7f9f681af6490386e20f51b2 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 15 Oct 2024 13:21:39 +0200 Subject: [PATCH 72/92] ci: remove duplicate lint check --- .github/lint-files.sh | 32 -------------------------------- .github/workflows/validate.yml | 4 +--- 2 files changed, 1 insertion(+), 35 deletions(-) delete mode 100755 .github/lint-files.sh diff --git a/.github/lint-files.sh b/.github/lint-files.sh deleted file mode 100755 index 507dff81..00000000 --- a/.github/lint-files.sh +++ /dev/null @@ -1,32 +0,0 @@ -#! /usr/bin/env bash - -# Usage: lint-files.sh -# -# Example usage: -# lint-files.sh "*.py" "flake8" -# lint-files.sh "tests/*.yaml" "yamllint" - -file_pattern=$1 -linter_command=$2 - -if [ -z "$file_pattern" ] || [ -z "$linter_command" ] -then - echo "Usage: $0 " - exit 1 -fi - -last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent 2>/dev/null) # Attempt to find the last tagged commit in the direct ancestry of the main branch avoiding tags introduced by merge commits from other branches - -if [ -z "$last_tagged_commit" ] -then - last_tagged_commit=$(git rev-list --max-parents=0 HEAD) # Fallback to finding the root commit if no tags are present -fi - -if ! changed_files=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "$file_pattern") -then - echo "Linting the following files:" - echo "$changed_files" - $linter_command $changed_files -else - echo "No changed files matching pattern '$file_pattern' to lint." -fi diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 1072fbcc..33d9b941 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -30,10 +30,8 @@ jobs: - run: make check-syntax-errors - - run: make check-style - - name: Lint Python files - run: "${GITHUB_WORKSPACE}/.github/lint-files.sh '*.py' 'flake8'" + run: make check-style - name: Lint YAML tests run: "${GITHUB_WORKSPACE}/.github/lint-files.sh 'tests/*.yaml' 'yamllint'" From 17f94ad0e1315d513b386874fadba8981de39d85 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 15 Oct 2024 14:20:06 +0200 Subject: [PATCH 73/92] ci: fix yamllint --- .github/workflows/validate.yml | 2 +- Makefile | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 33d9b941..56087b87 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -34,7 +34,7 @@ jobs: run: make check-style - name: Lint YAML tests - run: "${GITHUB_WORKSPACE}/.github/lint-files.sh 'tests/*.yaml' 'yamllint'" + run: make check-yaml test-yaml: runs-on: ubuntu-22.04 diff --git a/Makefile b/Makefile index 978269a2..7414e72d 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,11 @@ check-style: isort --check `git ls-files | grep "\.py$$"` black --check `git ls-files | grep "\.py$$"` +check-yaml: + @# Do not analyse .gitignored files. + @# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764. + yamllint `git ls-files | grep "\.yaml$$"` + test: clean check-syntax-errors check-style openfisca test --country-package openfisca_country_template openfisca_country_template/tests From 5fd47567bbcbd0fdd4509deef2ab227ab23ec24a Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Fri, 4 Feb 2022 16:37:44 +0100 Subject: [PATCH 74/92] WIP Publish to conda --- .conda/README.md | 32 +++++++++++++ .conda/meta.yaml | 101 +++++++++++++++++++++++++++++++++++++++ .github/get_pypi_info.py | 47 ++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 .conda/README.md create mode 100644 .conda/meta.yaml create mode 100644 .github/get_pypi_info.py diff --git a/.conda/README.md b/.conda/README.md new file mode 100644 index 00000000..a465f1ed --- /dev/null +++ b/.conda/README.md @@ -0,0 +1,32 @@ +# Publish to conda + +There is two way of publishing to conda: +- A fully automatic in CI that publish to an "openfisca" channel. See below for more information. +- A more complex for Conda-Forge. + +We use both for openfisca-core but only _openfisca channel_ for _country-template_. + +## Automatic upload + +The CI automaticaly upload the PyPi package, see the `.github/workflow.yml`, step `publish-to-conda`. + +## Manual actions made to make it works the first time + +- Create an account on https://anaconda.org. +- Create a token on https://anaconda.org/openfisca/settings/access with _Allow write access to the API site_. Warning, it expire on 2023/01/13. +- Put the token in a CI env variable ANACONDA_TOKEN. + +## Manual actions before CI exist + +To create the package you can do the following in the project root folder: + +- Edit `.conda/meta.yaml` and update it if needed: + - Version number + - Hash SHA256 + - Package URL on PyPi + +- Build & Upload package: + - `conda install -c anaconda conda-build anaconda-client` + - `conda build .conda` + - `anaconda login` + - `anaconda upload openfisca-country-template--py_0.tar.bz2` \ No newline at end of file diff --git a/.conda/meta.yaml b/.conda/meta.yaml new file mode 100644 index 00000000..4dbba880 --- /dev/null +++ b/.conda/meta.yaml @@ -0,0 +1,101 @@ +############################################################################### +## Package description for Anaconda.org +## Warning : string PYPI_VERSION, PYPI_URL and PYPI_SHA256 are replaced by CI +## Keep them as is. +############################################################################### + +{% set name = "OpenFisca-Country-Template" %} +{% set version = "PYPI_VERSION" %} + +package: + name: {{ name|lower }} + version: {{ version }} + +source: + url: PYPI_URL + sha256: PYPI_SHA256 + +build: + noarch: python + number: 0 + script: "{{ PYTHON }} -m pip install . -vv" + +requirements: + host: + - python + - pip + run: + - python >=3.6,<4.0 + - chardet >=4.0,<5.0 + - configparser + - humanize + - openfisca-core >=35.0.0,<36.0.0 + - pandas >=0.22 + - pyxdg + - PyYAML + - pytables >=3.5.1, <4.0.0 + - tabulate + - weightedcalcs + - wquantiles>=0.3 + + +test: + imports: + - openfisca_survey_manager + requires: + - pip + commands: + - pip check + +outputs: + - name: openfisca-survey-manager + + - name: openfisca-survey-manager-matching + build: + noarch: python + requirements: + host: + - python + run: + - feather + - rpy2 + - {{ pin_subpackage('openfisca-survey-manager', exact=True) }} + + - name: openfisca-survey-manager-dev + build: + noarch: python + requirements: + host: + - python + run: + - autopep8 >=1.4.0,<=1.5.7 + - coveralls >=1.5.0,<3.4.0 + - flake8 >=3.8.0,<3.10.0 + - openfisca-country-template >=3.6.0,<4.0.0 + - pytest >=4.0.0,<7.0.0 + - pytest-cov >=2.0.0, <3.0.0 + - scipy >=1.2.1, <2.0.0 + - {{ pin_subpackage('openfisca-survey-manager', exact=True) }} + + - name: openfisca-survey-manager-sas + build: + noarch: python + requirements: + host: + - python + run: + - pyreadstat >=1.1.4, <2.0.0 + - SAS7BDAT >=2.2.2, <3.0.0 + - {{ pin_subpackage('openfisca-survey-manager', exact=True) }} + +about: + home: https://fr.openfisca.org/ + license_family: AGPL + license: AGPL-3.0-only + license_file: LICENSE.AGPL.txt + summary: "Survey-Manager module, to work with OpenFisca and survey data." + description: | + OpenFisca is a versatile microsimulation free software. + This repository contains the Survey-Manager module, to work with OpenFisca and survey data. + doc_url: https://fr.openfisca.org/ + dev_url: https://github.com/openfisca/openfisca-survey-manager/ diff --git a/.github/get_pypi_info.py b/.github/get_pypi_info.py new file mode 100644 index 00000000..b82904f2 --- /dev/null +++ b/.github/get_pypi_info.py @@ -0,0 +1,47 @@ +import argparse +import requests + + +def get_info(package_name: str = "") -> dict: + """ + Get minimal informations needed by .conda/meta.yaml from PyPi JSON API. + ::package_name:: Name of package to get infos from. + ::return:: A dict with last_version, url and sha256 + """ + if package_name == "": + raise ValueError("Package name not provided.") + resp = requests.get(f"https://pypi.org/pypi/{package_name}/json").json() + version = resp["info"]["version"] + for v in resp["releases"][version]: + if v["packagetype"] == "sdist": # for .tag.gz + return { + "last_version": version, + "url": v["url"], + "sha256": v["digests"]["sha256"] + } + + +def replace_in_file(filepath: str, info: dict): + ''' + ::filepath:: Path to meta.yaml, with filename + ::info:: Dict with information to populate + ''' + with open(filepath, "rt") as fin: + meta = fin.read() + # Replace with info from PyPi + meta = meta.replace("PYPI_VERSION", info["last_version"]) + meta = meta.replace("PYPI_URL", info["url"]) + meta = meta.replace("PYPI_SHA256", info["sha256"]) + with open(filepath, "wt") as fout: + fout.write(meta) + print(f"File {filepath} has been updated with informations from PyPi.") # noqa: T001 + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("-p", "--package", type=str, default="", required=True, help="The name of the package") + parser.add_argument("-f", "--filename", type=str, default=".conda/meta.yaml", help="Path to meta.yaml, with filename") + args = parser.parse_args() + info = get_info(args.package) + print("Information of the last published PyPi package :", info) # noqa: T001 + replace_in_file(args.filename, info) From 4a488b9ddb1320953e63c043a24aedd3388034ba Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Fri, 4 Feb 2022 17:24:08 +0100 Subject: [PATCH 75/92] Fix style --- .github/get_pypi_info.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/.github/get_pypi_info.py b/.github/get_pypi_info.py index b82904f2..42801dbc 100644 --- a/.github/get_pypi_info.py +++ b/.github/get_pypi_info.py @@ -1,10 +1,19 @@ +""" +Script to get information needed by .conda/meta.yaml from PyPi JSON API. +This script use get_info to get the info (yes !) and replace_in_file to +write them into .conda/meta.yaml. +Sample call: +python3 .github/get_pypi_info.py -p OpenFisca-Country-Template +""" + import argparse + import requests def get_info(package_name: str = "") -> dict: """ - Get minimal informations needed by .conda/meta.yaml from PyPi JSON API. + Get minimal information needed by .conda/meta.yaml from PyPi JSON API. ::package_name:: Name of package to get infos from. ::return:: A dict with last_version, url and sha256 """ @@ -17,15 +26,15 @@ def get_info(package_name: str = "") -> dict: return { "last_version": version, "url": v["url"], - "sha256": v["digests"]["sha256"] + "sha256": v["digests"]["sha256"], } def replace_in_file(filepath: str, info: dict): - ''' + """ ::filepath:: Path to meta.yaml, with filename ::info:: Dict with information to populate - ''' + """ with open(filepath, "rt") as fin: meta = fin.read() # Replace with info from PyPi @@ -34,13 +43,26 @@ def replace_in_file(filepath: str, info: dict): meta = meta.replace("PYPI_SHA256", info["sha256"]) with open(filepath, "wt") as fout: fout.write(meta) - print(f"File {filepath} has been updated with informations from PyPi.") # noqa: T001 + print(f"File {filepath} has been updated with info from PyPi.") # noqa: T001 -if __name__ == '__main__': +if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("-p", "--package", type=str, default="", required=True, help="The name of the package") - parser.add_argument("-f", "--filename", type=str, default=".conda/meta.yaml", help="Path to meta.yaml, with filename") + parser.add_argument( + "-p", + "--package", + type=str, + default="", + required=True, + help="The name of the package", + ) + parser.add_argument( + "-f", + "--filename", + type=str, + default=".conda/meta.yaml", + help="Path to meta.yaml, with filename", + ) args = parser.parse_args() info = get_info(args.package) print("Information of the last published PyPi package :", info) # noqa: T001 From adcb972b84e1af69296b0864cc80aeccdfdb03aa Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Fri, 4 Feb 2022 17:51:43 +0100 Subject: [PATCH 76/92] Update emeta.yaml --- .conda/meta.yaml | 60 ++++++++++-------------------------------------- 1 file changed, 12 insertions(+), 48 deletions(-) diff --git a/.conda/meta.yaml b/.conda/meta.yaml index 4dbba880..a373dfd3 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -18,7 +18,7 @@ source: build: noarch: python number: 0 - script: "{{ PYTHON }} -m pip install . -vv" + script: "python3 -m pip install . -vv" requirements: host: @@ -26,76 +26,40 @@ requirements: - pip run: - python >=3.6,<4.0 - - chardet >=4.0,<5.0 - - configparser - - humanize - openfisca-core >=35.0.0,<36.0.0 - - pandas >=0.22 - - pyxdg - - PyYAML - - pytables >=3.5.1, <4.0.0 - - tabulate - - weightedcalcs - - wquantiles>=0.3 - test: imports: - - openfisca_survey_manager + - country_template requires: - pip commands: - pip check outputs: - - name: openfisca-survey-manager - - - name: openfisca-survey-manager-matching - build: - noarch: python - requirements: - host: - - python - run: - - feather - - rpy2 - - {{ pin_subpackage('openfisca-survey-manager', exact=True) }} - - - name: openfisca-survey-manager-dev - build: - noarch: python - requirements: - host: - - python - run: - - autopep8 >=1.4.0,<=1.5.7 - - coveralls >=1.5.0,<3.4.0 - - flake8 >=3.8.0,<3.10.0 - - openfisca-country-template >=3.6.0,<4.0.0 - - pytest >=4.0.0,<7.0.0 - - pytest-cov >=2.0.0, <3.0.0 - - scipy >=1.2.1, <2.0.0 - - {{ pin_subpackage('openfisca-survey-manager', exact=True) }} + - name: openfisca-country-template - - name: openfisca-survey-manager-sas + - name: openfisca-country-template-dev build: noarch: python requirements: host: - python run: - - pyreadstat >=1.1.4, <2.0.0 - - SAS7BDAT >=2.2.2, <3.0.0 - - {{ pin_subpackage('openfisca-survey-manager', exact=True) }} + - autopep8 >=1.5.4, <2.0.0 + - flake8 >=3.8.0,<4.0.0 + - pylint >=2.6.0, <3.0.0 + - pycodestyle >=2.6.0, <3.0.0 + - {{ pin_subpackage('openfisca-country-template', exact=True) }} about: home: https://fr.openfisca.org/ license_family: AGPL license: AGPL-3.0-only license_file: LICENSE.AGPL.txt - summary: "Survey-Manager module, to work with OpenFisca and survey data." + summary: "OpenFisca tax and benefit system for Country-Template." description: | OpenFisca is a versatile microsimulation free software. - This repository contains the Survey-Manager module, to work with OpenFisca and survey data. + This repository contains the Country-Template module, to work with OpenFisca. doc_url: https://fr.openfisca.org/ - dev_url: https://github.com/openfisca/openfisca-survey-manager/ + dev_url: https://github.com/openfisca/country-template/ From 2722609fed99ed46fb1e7fa3e7bdc9b58510840b Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Fri, 4 Feb 2022 18:03:52 +0100 Subject: [PATCH 77/92] Fix style --- .github/get_pypi_info.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/get_pypi_info.py b/.github/get_pypi_info.py index 42801dbc..f85d0283 100644 --- a/.github/get_pypi_info.py +++ b/.github/get_pypi_info.py @@ -1,5 +1,4 @@ -""" -Script to get information needed by .conda/meta.yaml from PyPi JSON API. +"""Script to get information needed by .conda/meta.yaml from PyPi JSON API. This script use get_info to get the info (yes !) and replace_in_file to write them into .conda/meta.yaml. Sample call: @@ -12,8 +11,7 @@ def get_info(package_name: str = "") -> dict: - """ - Get minimal information needed by .conda/meta.yaml from PyPi JSON API. + """Get minimal information needed by .conda/meta.yaml from PyPi JSON API. ::package_name:: Name of package to get infos from. ::return:: A dict with last_version, url and sha256 """ @@ -31,9 +29,9 @@ def get_info(package_name: str = "") -> dict: def replace_in_file(filepath: str, info: dict): - """ - ::filepath:: Path to meta.yaml, with filename - ::info:: Dict with information to populate + """ Replace placeholder in meta.yaml by their values. + ::filepath:: Path to meta.yaml, with filename. + ::info:: Dict with information to populate. """ with open(filepath, "rt") as fin: meta = fin.read() From 2fe29050df7cf54a1789b6fe075ffebe8d13f523 Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Fri, 4 Feb 2022 18:12:42 +0100 Subject: [PATCH 78/92] Fix Style --- .github/get_pypi_info.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/get_pypi_info.py b/.github/get_pypi_info.py index f85d0283..27ed2503 100644 --- a/.github/get_pypi_info.py +++ b/.github/get_pypi_info.py @@ -1,4 +1,5 @@ """Script to get information needed by .conda/meta.yaml from PyPi JSON API. + This script use get_info to get the info (yes !) and replace_in_file to write them into .conda/meta.yaml. Sample call: @@ -12,6 +13,7 @@ def get_info(package_name: str = "") -> dict: """Get minimal information needed by .conda/meta.yaml from PyPi JSON API. + ::package_name:: Name of package to get infos from. ::return:: A dict with last_version, url and sha256 """ @@ -29,7 +31,8 @@ def get_info(package_name: str = "") -> dict: def replace_in_file(filepath: str, info: dict): - """ Replace placeholder in meta.yaml by their values. + """Replace placeholder in meta.yaml by their values. + ::filepath:: Path to meta.yaml, with filename. ::info:: Dict with information to populate. """ From 389ff6a930736244092452b37529d546f106c1cd Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Fri, 4 Feb 2022 18:19:53 +0100 Subject: [PATCH 79/92] Fix style --- .github/get_pypi_info.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/get_pypi_info.py b/.github/get_pypi_info.py index 27ed2503..fc26c92a 100644 --- a/.github/get_pypi_info.py +++ b/.github/get_pypi_info.py @@ -28,6 +28,7 @@ def get_info(package_name: str = "") -> dict: "url": v["url"], "sha256": v["digests"]["sha256"], } + return {} def replace_in_file(filepath: str, info: dict): @@ -36,13 +37,13 @@ def replace_in_file(filepath: str, info: dict): ::filepath:: Path to meta.yaml, with filename. ::info:: Dict with information to populate. """ - with open(filepath, "rt") as fin: + with open(filepath, "rt", encoding="utf-8") as fin: meta = fin.read() # Replace with info from PyPi meta = meta.replace("PYPI_VERSION", info["last_version"]) meta = meta.replace("PYPI_URL", info["url"]) meta = meta.replace("PYPI_SHA256", info["sha256"]) - with open(filepath, "wt") as fout: + with open(filepath, "wt", encoding="utf-8") as fout: fout.write(meta) print(f"File {filepath} has been updated with info from PyPi.") # noqa: T001 From 8e398b2af7697bfe2d464b35846d182c172d3d45 Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Mon, 7 Feb 2022 09:30:57 +0100 Subject: [PATCH 80/92] Fix LICENSE --- .conda/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.conda/meta.yaml b/.conda/meta.yaml index a373dfd3..e33da304 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -56,7 +56,7 @@ about: home: https://fr.openfisca.org/ license_family: AGPL license: AGPL-3.0-only - license_file: LICENSE.AGPL.txt + license_file: LICENSE summary: "OpenFisca tax and benefit system for Country-Template." description: | OpenFisca is a versatile microsimulation free software. From 3e5d3f4e1336c85393225325385df016f0df5af3 Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Mon, 7 Feb 2022 10:28:50 +0100 Subject: [PATCH 81/92] Change package import --- .conda/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.conda/meta.yaml b/.conda/meta.yaml index e33da304..5950841a 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -30,7 +30,7 @@ requirements: test: imports: - - country_template + - openfisca_country_template requires: - pip commands: From c31cb8c4a998d297237e68f43511d17dbcc2eade Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Mon, 7 Feb 2022 11:20:46 +0100 Subject: [PATCH 82/92] bump --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af454e30..2cf27eea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,7 +73,6 @@ - Add an example entry to the changelog ([#116](https://github.com/openfisca/country-template/issues/116) - Relax Python version constraint - ### 6.0.3 [#136](https://github.com/openfisca/country-template/pull/136) * Technical improvement. From 8a3f642a28aa7b8cbb99a3cc289ed8d889ffc058 Mon Sep 17 00:00:00 2001 From: Benoit Courty <6603048+benoit-cty@users.noreply.github.com> Date: Mon, 16 May 2022 16:18:19 +0200 Subject: [PATCH 83/92] Update .conda/README.md Co-authored-by: sandcha --- .conda/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.conda/README.md b/.conda/README.md index a465f1ed..3834842f 100644 --- a/.conda/README.md +++ b/.conda/README.md @@ -1,6 +1,7 @@ # Publish to conda -There is two way of publishing to conda: +There are two ways to publish to conda: + - A fully automatic in CI that publish to an "openfisca" channel. See below for more information. - A more complex for Conda-Forge. From 5c06516f607d00034dda69ae14c3a078f53b12da Mon Sep 17 00:00:00 2001 From: Benoit Courty <6603048+benoit-cty@users.noreply.github.com> Date: Mon, 30 May 2022 13:51:15 +0200 Subject: [PATCH 84/92] Update .github/get_pypi_info.py Co-authored-by: sandcha --- .github/get_pypi_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/get_pypi_info.py b/.github/get_pypi_info.py index fc26c92a..7fd211b9 100644 --- a/.github/get_pypi_info.py +++ b/.github/get_pypi_info.py @@ -22,7 +22,8 @@ def get_info(package_name: str = "") -> dict: resp = requests.get(f"https://pypi.org/pypi/{package_name}/json").json() version = resp["info"]["version"] for v in resp["releases"][version]: - if v["packagetype"] == "sdist": # for .tag.gz + if v["packagetype"] == "sdist": # for source code (.tar.gz) + return { "last_version": version, "url": v["url"], From accd5b61068eb48dafbebbbe0697afcd6a7f8e57 Mon Sep 17 00:00:00 2001 From: Benoit Courty <6603048+benoit-cty@users.noreply.github.com> Date: Mon, 30 May 2022 13:51:51 +0200 Subject: [PATCH 85/92] Update .conda/README.md Co-authored-by: sandcha --- .conda/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.conda/README.md b/.conda/README.md index 3834842f..ddae6862 100644 --- a/.conda/README.md +++ b/.conda/README.md @@ -26,8 +26,10 @@ To create the package you can do the following in the project root folder: - Hash SHA256 - Package URL on PyPi -- Build & Upload package: +- Install `conda-build` to build the package and [anaconda-client](https://github.com/Anaconda-Platform/anaconda-client) to push the package to anaconda.org: - `conda install -c anaconda conda-build anaconda-client` + +- Build & Upload package: - `conda build .conda` - `anaconda login` - `anaconda upload openfisca-country-template--py_0.tar.bz2` \ No newline at end of file From 6ff0b1ff534975f529374531369275db3977eb32 Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Fri, 17 May 2024 15:28:51 +0200 Subject: [PATCH 86/92] Conda use pyproject.toml --- .conda/README.md | 27 ++++++++++++++++++++++++++- .conda/meta.yaml | 26 +++++++------------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/.conda/README.md b/.conda/README.md index ddae6862..45d0a88b 100644 --- a/.conda/README.md +++ b/.conda/README.md @@ -32,4 +32,29 @@ To create the package you can do the following in the project root folder: - Build & Upload package: - `conda build .conda` - `anaconda login` - - `anaconda upload openfisca-country-template--py_0.tar.bz2` \ No newline at end of file + - `anaconda upload openfisca-country-template--py_0.tar.bz2` + + +## Test with Docker + +Docker could be used to test the build and the installation of the package. + +To test the build: + +```sh +docker run --volume $PWD:/openfisca -i -t continuumio/anaconda3 /bin/bash +cd /openfisca +# Pour tester le meta.yaml +conda-build conda-recipe -c openfisca -c conda-forge .conda +# Pour lancer le build +conda build -c openfisca -c conda-forge .conda +``` + +To test the installation of the package: + +```sh +docker run --volume $PWD:/openfisca -i -t continuumio/anaconda3 /bin/bash +cd /openfisca +conda install -c openfisca -c conda-forge openfisca-country-template +openfisca test --country-package openfisca-country-template tests +``` \ No newline at end of file diff --git a/.conda/meta.yaml b/.conda/meta.yaml index 5950841a..faf65698 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -5,28 +5,29 @@ ############################################################################### {% set name = "OpenFisca-Country-Template" %} -{% set version = "PYPI_VERSION" %} +{% set pyproject = load_file_data('pyproject.toml') %} +{% set version = pyproject.get('project').get('version') %} package: name: {{ name|lower }} version: {{ version }} source: - url: PYPI_URL - sha256: PYPI_SHA256 + path: .. build: noarch: python number: 0 - script: "python3 -m pip install . -vv" + script: "{{ PYTHON }} -m pip install . -vv" requirements: host: - python - pip run: - - python >=3.6,<4.0 - - openfisca-core >=35.0.0,<36.0.0 + {% for req in pyproject.get('project').get('dependencies') %} + - {{ req }} + {% endfor %} test: imports: @@ -39,19 +40,6 @@ test: outputs: - name: openfisca-country-template - - name: openfisca-country-template-dev - build: - noarch: python - requirements: - host: - - python - run: - - autopep8 >=1.5.4, <2.0.0 - - flake8 >=3.8.0,<4.0.0 - - pylint >=2.6.0, <3.0.0 - - pycodestyle >=2.6.0, <3.0.0 - - {{ pin_subpackage('openfisca-country-template', exact=True) }} - about: home: https://fr.openfisca.org/ license_family: AGPL From baa549fca3e0bd8776e037feeb9121f71318d341 Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Fri, 17 May 2024 15:33:03 +0200 Subject: [PATCH 87/92] Conda doc --- .conda/README.md | 51 +++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/.conda/README.md b/.conda/README.md index 45d0a88b..06cfcf98 100644 --- a/.conda/README.md +++ b/.conda/README.md @@ -11,30 +11,6 @@ We use both for openfisca-core but only _openfisca channel_ for _country-templat The CI automaticaly upload the PyPi package, see the `.github/workflow.yml`, step `publish-to-conda`. -## Manual actions made to make it works the first time - -- Create an account on https://anaconda.org. -- Create a token on https://anaconda.org/openfisca/settings/access with _Allow write access to the API site_. Warning, it expire on 2023/01/13. -- Put the token in a CI env variable ANACONDA_TOKEN. - -## Manual actions before CI exist - -To create the package you can do the following in the project root folder: - -- Edit `.conda/meta.yaml` and update it if needed: - - Version number - - Hash SHA256 - - Package URL on PyPi - -- Install `conda-build` to build the package and [anaconda-client](https://github.com/Anaconda-Platform/anaconda-client) to push the package to anaconda.org: - - `conda install -c anaconda conda-build anaconda-client` - -- Build & Upload package: - - `conda build .conda` - - `anaconda login` - - `anaconda upload openfisca-country-template--py_0.tar.bz2` - - ## Test with Docker Docker could be used to test the build and the installation of the package. @@ -44,17 +20,34 @@ To test the build: ```sh docker run --volume $PWD:/openfisca -i -t continuumio/anaconda3 /bin/bash cd /openfisca -# Pour tester le meta.yaml -conda-build conda-recipe -c openfisca -c conda-forge .conda -# Pour lancer le build +# Check meta.yaml +conda-build --check .conda +# Build conda build -c openfisca -c conda-forge .conda ``` -To test the installation of the package: +To test the installation of the published package: ```sh docker run --volume $PWD:/openfisca -i -t continuumio/anaconda3 /bin/bash cd /openfisca conda install -c openfisca -c conda-forge openfisca-country-template openfisca test --country-package openfisca-country-template tests -``` \ No newline at end of file +``` + +To do the publication of the package, normaly not needed as it is done by the CI! : + +```sh +docker run --volume $PWD:/openfisca -i -t continuumio/anaconda3 /bin/bash +cd /openfisca +# Build +conda build -c openfisca -c conda-forge .conda +anaconda login +anaconda upload openfisca-country-template--py_0.tar.bz2 +``` + +## Manual actions made to make it works the first time + +- Create an account on https://anaconda.org. +- Create a token on https://anaconda.org/openfisca/settings/access with _Allow write access to the API site_. Warning, it expire on 2023/01/13. +- Put the token in a CI env variable ANACONDA_TOKEN. From 4e5e3f51599368069b5d0740d026e32a0c8130d5 Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Fri, 17 May 2024 15:40:55 +0200 Subject: [PATCH 88/92] Remove get_pypi_info.py not needed anymore. --- .github/get_pypi_info.py | 72 ---------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 .github/get_pypi_info.py diff --git a/.github/get_pypi_info.py b/.github/get_pypi_info.py deleted file mode 100644 index 7fd211b9..00000000 --- a/.github/get_pypi_info.py +++ /dev/null @@ -1,72 +0,0 @@ -"""Script to get information needed by .conda/meta.yaml from PyPi JSON API. - -This script use get_info to get the info (yes !) and replace_in_file to -write them into .conda/meta.yaml. -Sample call: -python3 .github/get_pypi_info.py -p OpenFisca-Country-Template -""" - -import argparse - -import requests - - -def get_info(package_name: str = "") -> dict: - """Get minimal information needed by .conda/meta.yaml from PyPi JSON API. - - ::package_name:: Name of package to get infos from. - ::return:: A dict with last_version, url and sha256 - """ - if package_name == "": - raise ValueError("Package name not provided.") - resp = requests.get(f"https://pypi.org/pypi/{package_name}/json").json() - version = resp["info"]["version"] - for v in resp["releases"][version]: - if v["packagetype"] == "sdist": # for source code (.tar.gz) - - return { - "last_version": version, - "url": v["url"], - "sha256": v["digests"]["sha256"], - } - return {} - - -def replace_in_file(filepath: str, info: dict): - """Replace placeholder in meta.yaml by their values. - - ::filepath:: Path to meta.yaml, with filename. - ::info:: Dict with information to populate. - """ - with open(filepath, "rt", encoding="utf-8") as fin: - meta = fin.read() - # Replace with info from PyPi - meta = meta.replace("PYPI_VERSION", info["last_version"]) - meta = meta.replace("PYPI_URL", info["url"]) - meta = meta.replace("PYPI_SHA256", info["sha256"]) - with open(filepath, "wt", encoding="utf-8") as fout: - fout.write(meta) - print(f"File {filepath} has been updated with info from PyPi.") # noqa: T001 - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument( - "-p", - "--package", - type=str, - default="", - required=True, - help="The name of the package", - ) - parser.add_argument( - "-f", - "--filename", - type=str, - default=".conda/meta.yaml", - help="Path to meta.yaml, with filename", - ) - args = parser.parse_args() - info = get_info(args.package) - print("Information of the last published PyPi package :", info) # noqa: T001 - replace_in_file(args.filename, info) From 15154a93b7dd6e0b84e576a059a4c2b8d782e7cb Mon Sep 17 00:00:00 2001 From: benoit-cty <6603048+benoit-cty@users.noreply.github.com> Date: Fri, 17 May 2024 15:48:42 +0200 Subject: [PATCH 89/92] Exclude lint for .conda/meta.yaml --- .yamllint | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.yamllint b/.yamllint index 2883d60d..10b82a57 100644 --- a/.yamllint +++ b/.yamllint @@ -4,3 +4,6 @@ extends: relaxed rules: line-length: disable + +ignore: + - .conda/meta.yaml From cfda10281fb9b01da7d841165637313b2c81921b Mon Sep 17 00:00:00 2001 From: benoit-cty Date: Fri, 18 Oct 2024 10:27:11 +0200 Subject: [PATCH 90/92] Conda deploy and test in CI --- .github/workflows/deploy.yml | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 76a02ae7..2e77a117 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -68,3 +68,46 @@ jobs: run: twine upload dist/* --username __token__ --password ${{ secrets.PYPI_TOKEN }} - name: Publish a git tag run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" + + publish-to-conda: + runs-on: "ubuntu-latest" + needs: [ deploy ] + strategy: + fail-fast: false + steps: + - uses: conda-incubator/setup-miniconda@v3 + with: + auto-update-conda: true + python-version: "3.7.9" + # Add conda-forge for OpenFisca-Core + channels: conda-forge + activate-environment: true + - uses: actions/checkout@v4 + - name: Update meta.yaml + run: | + python3 -m pip install requests argparse + python3 .github/get_pypi_info.py -p OpenFisca-Country-Template + - name: Conda Config + run: | + conda install conda-build anaconda-client + conda info + conda config --set anaconda_upload yes + - name: Conda build + run: conda build --token ${{ secrets.ANACONDA_TOKEN }} --user openfisca .conda + + install-on-windows: + runs-on: "windows-latest" + needs: [ publish-to-conda ] + strategy: + fail-fast: false + steps: + - uses: conda-incubator/setup-miniconda@v3 + with: + auto-update-conda: true + python-version: "3.9.9" + # Add conda-forge for OpenFisca-Core + channels: conda-forge + activate-environment: true + - uses: actions/checkout@v4 + - name: Install with conda + run: conda install -c openfisca openfisca-country-template From f6219d020861999de5493c65447094ec8b993573 Mon Sep 17 00:00:00 2001 From: benoit-cty Date: Fri, 18 Oct 2024 10:33:03 +0200 Subject: [PATCH 91/92] [conda] Replace space in deps --- .conda/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.conda/meta.yaml b/.conda/meta.yaml index faf65698..c6cedd9c 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -26,7 +26,7 @@ requirements: - pip run: {% for req in pyproject.get('project').get('dependencies') %} - - {{ req }} + - {{ req | replace(" ", "") }} {% endfor %} test: From 5dc697d250b08769ad390c1ad3a5d7ae576b64c9 Mon Sep 17 00:00:00 2001 From: benoit-cty Date: Fri, 18 Oct 2024 11:21:57 +0200 Subject: [PATCH 92/92] doc --- .conda/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.conda/README.md b/.conda/README.md index 06cfcf98..8aee36cf 100644 --- a/.conda/README.md +++ b/.conda/README.md @@ -23,6 +23,8 @@ cd /openfisca # Check meta.yaml conda-build --check .conda # Build +conda install conda-verify +conda config --add channels defaults conda build -c openfisca -c conda-forge .conda ```