Repository: openfisca/country-template (language: python)

Issue:
Training upgrade
* Technical improvement.
* Major change
* Impacted periods: all.
* Impacted areas: all
* Details:
  - Improvements to `bootstrap.sh` to improve experience for first time users:
    - remove the need to set `COUNTRY_NAME` and `REPOSITORY_URL` before running.
    - provide a confirmation option/exit script option before changes are made
    - allow for hypens and spaces appropriately
    - set `master` branch to `main` by default
    - print to console the commit actions along with description
  - Change `CONTRIBUTING.md` to allow for improved text replacements
    - Replace reference to `master` with `main`
  - Change `Makefile`
    - Remove reference to `OpenFisca France` replace with new repository name
    - replace argument `-e` with longer form `--editable` to aid newcomers
    - add new formating commands for `isort`, `pyupgrade` and `yamllint`
  - Author default `pyproject.toml` based on the older `setup.py` and `setup.cfg`
    - Set version to 7.0.0
    - Add in `[project.urls]`: `Homepage`, `Repository`, `Documentation`, `Issues` and `Changelog`
    - Add in `[project.optional-dependencies]`: new dependancies `isort`, `pyupgrade` and `yamllint`
    - Add `[tool.pytest.ini_options]` with filterwarnings set to `"error"`
    - Add `[tool.pylint.messages_control]` from `setup.cfg` but in long form for readability
    - Add `[tool.isort]` section
  - Add `.flake8` and `.yamllint` to project root as these projects do not support `pyproject.toml` format
  - Alter `README.md` to allow for improved text replacements
    - Remove commands (line 21) for `export COUNTRY_NAME=France` and `export REPOSITORY_URL=...` due to bootstrap.sh improvements
    - Adjust (Line 28) from `git push origin master` to `git push origin main`
    - General changes to support change to bootstrap flow
  - Remove `setup.py` and `setup.cfg`
  - Update `.github/*.sh` and `.github/workflows/workflow.yaml` files to reference `main` instead of `master`
  - Fix linting issues in:
    - `openfisca_country_template/texts/social_security_contribution.yaml`
    - `openfisca_country_template/texts/situations/income_tax.yaml`
    - `openfisca_country_template/variables/demographics.py`
    - `openfisca_country_template/variables/taxes.py`
  - Alter `CHANGELOG.md`, add example entry and alter `bootstrap.sh` to strip out country-template entries. This resolves [issue 116](https://github.com/openfisca/country-template/issues/116).

- - - -

Note that this has been tested against OpenFisca-core and requires corresponding [pull request](https://github.com/openfisca/openfisca-core/pull/1208) to pass the OpenFisca-core test suite. 

If this is approved, it is the intention to upgrade the documentation surrounding OpenFisca which will likely include the *.md files in this repository and result in a subsequent PR.

Training upgrade
* Technical improvement.
* Major change
* Impacted periods: all.
* Impacted areas: all
* Details:
  - Improvements to `bootstrap.sh` to improve experience for first time users:
    - remove the need to set `COUNTRY_NAME` and `REPOSITORY_URL` before running.
    - provide a confirmation option/exit script option before changes are made
    - allow for hypens and spaces appropriately
    - set `master` branch to `main` by default
    - print to console the commit actions along with description
  - Change `CONTRIBUTING.md` to allow for improved text replacements
    - Replace reference to `master` with `main`
  - Change `Makefile`
    - Remove reference to `OpenFisca France` replace with new repository name
    - replace argument `-e` with longer form `--editable` to aid newcomers
    - add new formating commands for `isort`, `pyupgrade` and `yamllint`
  - Author default `pyproject.toml` based on the older `setup.py` and `setup.cfg`
    - Set version to 7.0.0
    - Add in `[project.urls]`: `Homepage`, `Repository`, `Documentation`, `Issues` and `Changelog`
    - Add in `[project.optional-dependencies]`: new dependancies `isort`, `pyupgrade` and `yamllint`
    - Add `[tool.pytest.ini_options]` with filterwarnings set to `"error"`
    - Add `[tool.pylint.messages_control]` from `setup.cfg` but in long form for readability
    - Add `[tool.isort]` section
  - Add `.flake8` and `.yamllint` to project root as these projects do not support `pyproject.toml` format
  - Alter `README.md` to allow for improved text replacements
    - Remove commands (line 21) for `export COUNTRY_NAME=France` and `export REPOSITORY_URL=...` due to bootstrap.sh improvements
    - Adjust (Line 28) from `git push origin master` to `git push origin main`
    - General changes to support change to bootstrap flow
  - Remove `setup.py` and `setup.cfg`
  - Update `.github/*.sh` and `.github/workflows/workflow.yaml` files to reference `main` instead of `master`
  - Fix linting issues in:
    - `openfisca_country_template/texts/social_security_contribution.yaml`
    - `openfisca_country_template/texts/situations/income_tax.yaml`
    - `openfisca_country_template/variables/demographics.py`
    - `openfisca_country_template/variables/taxes.py`
  - Alter `CHANGELOG.md`, add example entry and alter `bootstrap.sh` to strip out country-template entries. This resolves [issue 116](https://github.com/openfisca/country-template/issues/116).

- - - -

Note that this has been tested against OpenFisca-core and requires corresponding [pull request](https://github.com/openfisca/openfisca-core/pull/1208) to pass the OpenFisca-core test suite. 

If this is approved, it is the intention to upgrade the documentation surrounding OpenFisca which will likely include the *.md files in this repository and result in a subsequent PR.



Discussion / hints:
Note: after merging, we'll need to switch the main branch from `master` to `main`.
Did you see https://github.com/openfisca/country-template/issues/109? Could it be (have been) helpful?
Note: after merging, we'll need to switch the main branch from `master` to `main`.
Did you see https://github.com/openfisca/country-template/issues/109? Could it be (have been) helpful?

Fix patch:
diff --git a/.github/has-functional-changes.sh b/.github/has-functional-changes.sh
index 61a232da..01db9ee5 100755
--- a/.github/has-functional-changes.sh
+++ b/.github/has-functional-changes.sh
@@ -2,7 +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
+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
diff --git a/.github/is-version-number-acceptable.sh b/.github/is-version-number-acceptable.sh
index 605f8373..0c86be5b 100755
--- a/.github/is-version-number-acceptable.sh
+++ b/.github/is-version-number-acceptable.sh
@@ -12,16 +12,22 @@ 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 [[ ! $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:"
     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
+    exit 2
 fi
 
 if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md
diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh
index b27a8925..b7456772 100755
--- a/.github/lint-changed-python-files.sh
+++ b/.github/lint-changed-python-files.sh
@@ -2,10 +2,10 @@
 
 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 $last_tagged_commit -- "*.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/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
diff --git a/bootstrap.sh b/bootstrap.sh
index 477af7d7..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
 
@@ -104,7 +105,9 @@ git rm bootstrap.sh > /dev/null 2>&1
 git add .
 git commit --no-gpg-sign --message "$second_commit_message" --author='OpenFisca Bot <bot@openfisca.org>' --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"


Test patch:
diff --git a/.github/lint-changed-yaml-tests.sh b/.github/lint-changed-yaml-tests.sh
index 6c0124c8..9e2ab562 100755
--- a/.github/lint-changed-yaml-tests.sh
+++ b/.github/lint-changed-yaml-tests.sh
@@ -2,10 +2,10 @@
 
 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 $last_tagged_commit -- "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