Skip to content

Commit

Permalink
Merge pull request #11 from openfisca/migration
Browse files Browse the repository at this point in the history
Pin core version
  • Loading branch information
benjello authored Nov 14, 2024
2 parents f6603e1 + f0cd2c9 commit cc4b535
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 138 deletions.
13 changes: 7 additions & 6 deletions .github/pyproject_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand All @@ -18,17 +18,18 @@ 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)
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)
# '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:
Expand All @@ -50,7 +51,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'])
Expand All @@ -71,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
Expand Down
2 changes: 1 addition & 1 deletion .github/test-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
93 changes: 0 additions & 93 deletions .github/workflows/tax-benefit.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/validate_yaml.yml

This file was deleted.

6 changes: 4 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,5 +30,3 @@

## 0.8.0
* Migrate to openfisca-core 12.0.3 syntax


Empty file.
55 changes: 55 additions & 0 deletions openfisca_tunisia_pension/scripts/check_path_length.py
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 9 additions & 15 deletions openfisca_tunisia_pension/variables/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -19,10 +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] >=43, <44',
'openfisca-core[web-api] ==41.5.3',
'openfisca-core[web-api] >=41.5.0, <41.5.3',
'scipy >= 0.12',
]

Expand Down
1 change: 1 addition & 0 deletions tests/formulas/pension_rsna.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
2013: 12000
2014: 12000
output:
trimestres_valides: 50
salaire_reference_rsna: 12000
pension_rsna: 5400
1 change: 1 addition & 0 deletions tests/formulas/salaire_reference_rsna.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@
2013: 12000
2014: 12000
output:
trimestres_valides: 50
salaire_reference_rsna: 12000

0 comments on commit cc4b535

Please sign in to comment.