From 5fb6f076a08a50917b07dc309796a42d217d4ad3 Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 13:19:44 +0100 Subject: [PATCH 01/15] Pin core version --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 811b049..0c77b08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,6 @@ requires-python = ">= 3.9" dependencies = [ 'bottleneck >=1.3.2,<=2.0.0', 'numpy >=1.24.3, <2', - # 'openfisca-core[web-api] >=43, <44', 'openfisca-core[web-api] ==41.5.3', 'scipy >= 0.12', ] From 9c582e0bdedaaacd5c8228fa6e39d71d0b66d43d Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 13:33:16 +0100 Subject: [PATCH 02/15] Clean --- openfisca_tunisia_pension/variables/data.py | 24 ++++++++------------- pyproject.toml | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/openfisca_tunisia_pension/variables/data.py b/openfisca_tunisia_pension/variables/data.py index c2942d8..51a2ebc 100644 --- a/openfisca_tunisia_pension/variables/data.py +++ b/openfisca_tunisia_pension/variables/data.py @@ -2,19 +2,12 @@ from openfisca_tunisia_pension.entities import Individu -# raic -> raci -# Socio-economic data -# Donnée d'entrée de la simulation à fournir à partir d'une enquète ou -# à générer avec un générateur de cas type - - -class date_naissance(Variable): - value_type = date - default_value = date(1970, 1, 1) +class age(Variable): + value_type = int entity = Individu - label = 'Date de naissance' - definition_period = ETERNITY + label = 'Âge' + definition_period = YEAR class salaire(Variable): @@ -24,11 +17,12 @@ class salaire(Variable): definition_period = YEAR -class age(Variable): - value_type = int +class date_naissance(Variable): + value_type = date + default_value = date(1970, 1, 1) entity = Individu - label = 'Âge' - definition_period = YEAR + label = 'Date de naissance' + definition_period = ETERNITY class trimestres_valides(Variable): diff --git a/pyproject.toml b/pyproject.toml index 0c77b08..133cb48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "OpenFisca-Tunisia-Pension" -version = "2.0.0" +version = "2.0.1" description = "OpenFisca Rules as Code model for Tunisia pensions." readme = "README.md" keywords = ["microsimulation", "tax", "benefit", "pension", "rac", "rules-as-code", "tunisia"] From cc46c75cb23aced2ba6ac3c7505d9d336ebe1397 Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 13:50:42 +0100 Subject: [PATCH 03/15] Adjust pyprojetc.toml --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 133cb48..5c00e9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,9 +19,9 @@ classifiers = [ ] requires-python = ">= 3.9" dependencies = [ - 'bottleneck >=1.3.2,<=2.0.0', + 'bottleneck >=1.4.2,<2.0.0', 'numpy >=1.24.3, <2', - 'openfisca-core[web-api] ==41.5.3', + 'openfisca-core[web-api] >=41.5.0,<41.5.3', 'scipy >= 0.12', ] From 2a24bcf0f58d525947346da21cccf9e8c5ef3516 Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 14:25:02 +0100 Subject: [PATCH 04/15] Fix package name --- .github/pyproject_version.py | 4 ++-- .github/test-api.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/pyproject_version.py b/.github/pyproject_version.py index 5da7842..965a997 100644 --- a/.github/pyproject_version.py +++ b/.github/pyproject_version.py @@ -18,7 +18,7 @@ def get_versions(): openfisca_tunisia_pension = None with open('./pyproject.toml', 'r') as file: content = file.read() - # Extract the version of openfisca_tunisia-pension + # Extract the version of openfisca_tunisia_pension version_match = re.search(r'^version\s*=\s*"([\d.]*)"', content, re.MULTILINE) if version_match: openfisca_tunisia_pension = version_match.group(1) @@ -50,7 +50,7 @@ def replace_in_file(filepath: str, info: dict): # Replace with info from pyproject.toml if PACKAGE_VERSION not in meta: raise Exception(f'{PACKAGE_VERSION=} not found in {filepath}') - meta = meta.replace(PACKAGE_VERSION, info['openfisca_tunisia-pension']) + meta = meta.replace(PACKAGE_VERSION, info['openfisca_tunisia_pension']) if CORE_VERSION not in meta: raise Exception(f'{CORE_VERSION=} not found in {filepath}') meta = meta.replace(CORE_VERSION, info['openfisca_core_api']) diff --git a/.github/test-api.sh b/.github/test-api.sh index e7101b2..8494f57 100755 --- a/.github/test-api.sh +++ b/.github/test-api.sh @@ -3,7 +3,7 @@ PORT=5000 ENDPOINT=spec -openfisca serve --country-package openfisca_tunisia-pension --port $PORT --workers 1 & +openfisca serve --country-package openfisca_tunisia_pension --port $PORT --workers 1 & server_pid=$! curl --retry-connrefused --retry 10 --retry-delay 5 --fail http://127.0.0.1:$PORT/$ENDPOINT | python -m json.tool > /dev/null From 95f005c10c808ae3f576af6a8a2d679d0ec3a8b3 Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 14:26:12 +0100 Subject: [PATCH 05/15] Add missing script --- openfisca_tunisia_pension/scripts/__init__.py | 0 .../scripts/check_path_length.py | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 openfisca_tunisia_pension/scripts/__init__.py create mode 100644 openfisca_tunisia_pension/scripts/check_path_length.py diff --git a/openfisca_tunisia_pension/scripts/__init__.py b/openfisca_tunisia_pension/scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openfisca_tunisia_pension/scripts/check_path_length.py b/openfisca_tunisia_pension/scripts/check_path_length.py new file mode 100644 index 0000000..cf8b127 --- /dev/null +++ b/openfisca_tunisia_pension/scripts/check_path_length.py @@ -0,0 +1,55 @@ +''' +EN: Look into folders to check path length and return an error if a too long path is found. +Also write too long path in a file. + +FR: Ce script sert à estimer la longueur des chemins d'arborescence des paramètres, +afin de ne pas avoir de chemins > 150 caractères (incompatible Windows). +Il est à utiliser avant de contribuer à l'harmonisation +''' + + +import os +import logging + + +logging.basicConfig(level=logging.INFO) + + +def extract_paths_too_long(root_dir): + ''' + Look into folders to check path length and return True if a too long path is found. + ''' + path_too_long_detected = False + maxlen = 0 + root_dir = root_dir.rstrip(os.sep) + + with open('path_too_long_list.txt', 'w') as outfile: + for path, dirs, files in os.walk(root_dir): + relative_path = path[len(root_dir) + 1:] + for dir in dirs: + if dir.startswith('.'): + # Ignore hidden directories. + dirs.remove(dir) + for file in files: + if file.startswith('.'): + # Ignore hidden files. + continue + relative_file_path = os.path.join(relative_path, file) + maxlen = max(maxlen, len(relative_file_path)) + if len(relative_file_path) > 150: + path_too_long_detected = True + logging.error(f'Path too long of {len(relative_file_path)-150} characters : {relative_file_path}') + outfile.write('{} here: {}\n'.format( + len(relative_file_path), + relative_file_path, + )) + logging.info(f'Max length found : {maxlen} characters.') + return path_too_long_detected + + +country_dir = os.path.dirname((os.path.dirname(os.path.abspath(__file__)))) +parameters_dir = os.path.join(country_dir, 'parameters') +if extract_paths_too_long(parameters_dir): + # Return code 1 to indicate an error. Default is 0. + exit(1) +# If no path are too long, the default return is 0: no error. From 50c87a72d40e37a93d0a04479b6c5b86876d5464 Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 14:31:31 +0100 Subject: [PATCH 06/15] Trigger YAML test modification --- tests/formulas/pension_rsna.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/formulas/pension_rsna.yaml b/tests/formulas/pension_rsna.yaml index 543aaf5..f2fe4e4 100644 --- a/tests/formulas/pension_rsna.yaml +++ b/tests/formulas/pension_rsna.yaml @@ -46,5 +46,6 @@ 2013: 12000 2014: 12000 output: + trimestres_valides: 50 salaire_reference_rsna: 12000 pension_rsna: 5400 From 54e60938889e81a3d21e1440bba02d5b9be54742 Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 14:31:39 +0100 Subject: [PATCH 07/15] Again --- tests/formulas/salaire_reference_rsna.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/formulas/salaire_reference_rsna.yaml b/tests/formulas/salaire_reference_rsna.yaml index a763fd9..02a8ff7 100644 --- a/tests/formulas/salaire_reference_rsna.yaml +++ b/tests/formulas/salaire_reference_rsna.yaml @@ -46,4 +46,5 @@ 2013: 12000 2014: 12000 output: + trimestres_valides: 50 salaire_reference_rsna: 12000 From 3e682c3cc97c49c3cbf69c7b79ffd7364b20abcc Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 14:40:16 +0100 Subject: [PATCH 08/15] Reduce the numbers of nodes for testing --- .github/workflows/workflow.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index bc7f483..c77b638 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -118,8 +118,10 @@ jobs: matrix: # Set N number of parallel jobs to run tests on. Here we use 10 jobs # Remember to update ci_node_index below to 0..N-1 - ci_node_total: [ 10 ] - ci_node_index: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] + ci_node_total: [ 2 ] + ci_node_index: [ 0, 1 ] + # ci_node_total: [ 10 ] + # ci_node_index: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] openfisca-dependencies: [minimal, maximal] steps: - name: Checkout From db8d7579d47743485d2825e371d7a641badaa60c Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 14:45:26 +0100 Subject: [PATCH 09/15] Try to improve pyproject --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5c00e9c..1d41981 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,9 +19,9 @@ classifiers = [ ] requires-python = ">= 3.9" dependencies = [ - 'bottleneck >=1.4.2,<2.0.0', + 'bottleneck >=1.4.2, <2.0.0', 'numpy >=1.24.3, <2', - 'openfisca-core[web-api] >=41.5.0,<41.5.3', + 'openfisca-core[web-api] >=41.5.0, <41.5.3', 'scipy >= 0.12', ] From 4c1b6fdbbc4c122555c210258a52baab587531fa Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 14:59:32 +0100 Subject: [PATCH 10/15] Fix get_version --- .github/pyproject_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pyproject_version.py b/.github/pyproject_version.py index 965a997..ff7f51c 100644 --- a/.github/pyproject_version.py +++ b/.github/pyproject_version.py @@ -6,7 +6,7 @@ logging.basicConfig(level=logging.INFO, format='%(message)s') PACKAGE_VERSION = 'X.X.X' -CORE_VERSION = '>=43,<44' +CORE_VERSION = '>=41.5.0,<41.5.3' NUMPY_VERSION = '>=1.24.3,<2' From 85cf524877aa77c72dff9479101f5c3f966c9189 Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 15:30:07 +0100 Subject: [PATCH 11/15] Fix pypi version getter --- .github/pyproject_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pyproject_version.py b/.github/pyproject_version.py index ff7f51c..cd8aa9c 100644 --- a/.github/pyproject_version.py +++ b/.github/pyproject_version.py @@ -25,7 +25,7 @@ def get_versions(): else: raise Exception('Package version not found in pyproject.toml') # Extract dependencies - version = re.search(r'openfisca-core\[web-api\]\s*(>=\s*[\d\.]*,\s*<\d*)"', content, re.MULTILINE) + version = re.search(r'openfisca-core\[web-api\]\s*((?:==|>=)\s*[\d\.]+(?:\s*,\s*<\s*\d+)?)"', content, re.MULTILINE) if version: openfisca_core_api = version.group(1) version = re.search(r'numpy\s*(>=\s*[\d\.]*,\s*<\d*)"', content, re.MULTILINE) From e8448769cd7268b45371475d557d912bd2e6a938 Mon Sep 17 00:00:00 2001 From: benoit-cty Date: Thu, 14 Nov 2024 15:28:49 +0100 Subject: [PATCH 12/15] Handle more versioning --- .github/pyproject_version.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/pyproject_version.py b/.github/pyproject_version.py index cd8aa9c..1c47484 100644 --- a/.github/pyproject_version.py +++ b/.github/pyproject_version.py @@ -25,10 +25,11 @@ def get_versions(): else: raise Exception('Package version not found in pyproject.toml') # Extract dependencies - version = re.search(r'openfisca-core\[web-api\]\s*((?:==|>=)\s*[\d\.]+(?:\s*,\s*<\s*\d+)?)"', content, re.MULTILINE) + version = re.search(r'openfisca-core\[web-api\]\s*((?:==|>=)\s*[\d\.]+(?:\s*,\s*<\s*\d+)?)', content, re.MULTILINE) if version: openfisca_core_api = version.group(1) - version = re.search(r'numpy\s*(>=\s*[\d\.]*,\s*<\d*)"', content, re.MULTILINE) + # 'numpy >=1.24.3, <2', + version = re.search(r'numpy\s*(>=\s*[\d\.]*,\s*<\d*)', content, re.MULTILINE) if version: numpy = version.group(1) if not openfisca_core_api or not numpy: From 9169d8301c5a09ed11671627b9e55802455bed40 Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 15:53:14 +0100 Subject: [PATCH 13/15] Fix typo --- .github/pyproject_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pyproject_version.py b/.github/pyproject_version.py index 1c47484..0e3cdcd 100644 --- a/.github/pyproject_version.py +++ b/.github/pyproject_version.py @@ -72,7 +72,7 @@ def replace_in_file(filepath: str, info: dict): info = get_versions() file = args.filename if args.only_package_version: - print(f'{info["openfisca_tunisia-pension"]}') # noqa: T201 + print(f'{info["openfisca_tunisia_pension"]}') # noqa: T201 exit() logging.info('Versions :') print(info) # noqa: T201 From 97c0d37728c527a182ad2f2d59c7ba7de9bfb90c Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 15:59:00 +0100 Subject: [PATCH 14/15] Bump changelog --- CHANGELOG.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73e42f7..48b2a3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### 2.0.1 [#11](https://github.com/openfisca/openfisca-tunisia-pension/pull/11) + +* Amélioration technique. +* Détails : + - Utilise variables au lieu de model. + - Utilise github actions et pyproject.toml. + ### 2.0.0 * Migrate to openfisca-core v24 syntax @@ -23,5 +30,3 @@ ## 0.8.0 * Migrate to openfisca-core 12.0.3 syntax - - From f0cd2c99526529d21c6b5b87398ef9c1f2eb18a0 Mon Sep 17 00:00:00 2001 From: Mahdi Ben Jelloul Date: Thu, 14 Nov 2024 17:07:54 +0100 Subject: [PATCH 15/15] Remove validating parameters --- .github/workflows/tax-benefit.yml | 93 ----------------------------- .github/workflows/validate_yaml.yml | 15 ----- 2 files changed, 108 deletions(-) delete mode 100644 .github/workflows/tax-benefit.yml delete mode 100644 .github/workflows/validate_yaml.yml diff --git a/.github/workflows/tax-benefit.yml b/.github/workflows/tax-benefit.yml deleted file mode 100644 index 6bf03cf..0000000 --- a/.github/workflows/tax-benefit.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: Validate, integrate & deploy to tax-benefit.org - -on: - - push - - workflow_dispatch - -jobs: - validate_yaml: - uses: tax-benefit/actions/.github/workflows/validate_yaml.yml@v2.1.0 - with: - parameters_path: "openfisca_tunisia/parameters" - secrets: - token: ${{ secrets.CONTROL_CENTER_TOKEN }} - - deploy_parameters: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Clone Legislation Parameters Explorer - run: git clone https://git.leximpact.dev/leximpact/legislation-parameters-explorer.git - - name: Install Node.js version LTS - uses: actions/setup-node@v4 - with: - node-version: 'lts/*' - - name: Install viewer dependencies - run: npm install - working-directory: legislation-parameters-explorer/packages/viewer - - name: Configure viewer - run: | - rm -f .env - cat > .env << EOF - # Customizations to apply to the site (theme, URLs…) - CUSTOMIZATION="openfisca" - - DBNOMICS_DATASET_CODE="openfisca_tunisia" - DBNOMICS_PROVIDER_CODE="OpenFisca" - DBNOMICS_URL="https://db.nomics.world/" - - EDITOR_URL="https://editor.parameters.tn.tax-benefit.org/" - - EXPORT_CSV=true - EXPORT_JSON=false - EXPORT_XLSX=true - - # Path of directory containing legislation parameters of country - PARAMETERS_DIR="../../../openfisca_tunisia/parameters/" - - # Description of parameters remote repository - PARAMETERS_AUTHOR_EMAIL="editor.parameters.tn@tax-benefit.org" - PARAMETERS_AUTHOR_NAME="Éditeur des paramètres d'OpenFisca-Tunisia" - PARAMETERS_BRANCH="main" - PARAMETERS_FORGE_DOMAIN_NAME="github.com" - PARAMETERS_FORGE_TYPE="GitHub" - PARAMETERS_GROUP="openfisca" - PARAMETERS_PROJECT="openfisca-tunisia-pension" - PARAMETERS_PROJECT_DIR="openfisca_tunisia/parameters" - - SHOW_LAST_BREADCRUMB_ITEM = false - - TABLE_OF_CONTENTS_DIR="../../../openfisca_tunisia/tables/" - - TITLE="OpenFisca-Tunisia - الجباية المفتوحة تونس" - - # Path of file containing units used by French legislation parameters - UNITS_FILE_PATH="../../../openfisca_tunisia/units.yaml" - EOF - working-directory: legislation-parameters-explorer/packages/viewer - - name: Initialize .svelte-kit directory of viewer - run: npx svelte-kit sync - working-directory: legislation-parameters-explorer/packages/viewer - - name: Generate data of viewer - run: npx tsx src/scripts/generate_data.ts - working-directory: legislation-parameters-explorer/packages/viewer - - name: Build viewer - run: npm run build - working-directory: legislation-parameters-explorer/packages/viewer - - name: Configure ssh for deployment to server - uses: tanmancan/action-setup-ssh-agent-key@1.0.0 - with: - ssh-auth-sock: /tmp/my_auth.sock - ssh-private-key: ${{ secrets.PARAMETERS_EXPLORER_SSH_PRIVATE_KEY }} - ssh-public-key: ${{ secrets.PARAMETERS_EXPLORER_SSH_KNOWN_HOSTS }} - - name: Deploy to Server using rsync - run: rsync -az --delete -e "ssh -J ssh-proxy@parameters.tn.tax-benefit.org:2222" build/ parameters.tn.tax-benefit.org@10.131.0.2:public_html/ - working-directory: legislation-parameters-explorer/packages/viewer - - deploy_simulator: - uses: tax-benefit/actions/.github/workflows/deploy.yml@v2.1.0 - with: - python_package: "openfisca_tunisia" - secrets: - token: ${{ secrets.CONTROL_CENTER_TOKEN }} diff --git a/.github/workflows/validate_yaml.yml b/.github/workflows/validate_yaml.yml deleted file mode 100644 index ac97c47..0000000 --- a/.github/workflows/validate_yaml.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Validate YAML - -on: - push: - workflow_dispatch: - pull_request: - types: [opened, reopened] - -jobs: - validate_yaml: - uses: tax-benefit/actions/.github/workflows/validate_yaml.yml@v1 - with: - parameters_path: "openfisca_tunisia/parameters" - secrets: - token: ${{ secrets.CONTROL_CENTER_TOKEN }}