OpenFisca-Core-test 46.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. openfisca_core/__init__.py +0 -0
  2. openfisca_core/commons/__init__.py +18 -0
  3. openfisca_core/commons/dummy.py +25 -0
  4. openfisca_core/commons/formulas.py +121 -0
  5. openfisca_core/commons/misc.py +109 -0
  6. openfisca_core/commons/py.typed +0 -0
  7. openfisca_core/commons/rates.py +114 -0
  8. openfisca_core/commons/tests/__init__.py +0 -0
  9. openfisca_core/commons/tests/test_dummy.py +9 -0
  10. openfisca_core/commons/tests/test_formulas.py +75 -0
  11. openfisca_core/commons/tests/test_rates.py +26 -0
  12. openfisca_core/data_storage/__init__.py +7 -0
  13. openfisca_core/data_storage/in_memory_storage.py +198 -0
  14. openfisca_core/data_storage/on_disk_storage.py +307 -0
  15. openfisca_core/data_storage/types.py +14 -0
  16. openfisca_core/entities/__init__.py +23 -0
  17. openfisca_core/entities/_core_entity.py +217 -0
  18. openfisca_core/entities/_description.py +55 -0
  19. openfisca_core/entities/entity.py +60 -0
  20. openfisca_core/entities/group_entity.py +123 -0
  21. openfisca_core/entities/helpers.py +165 -0
  22. openfisca_core/entities/py.typed +0 -0
  23. openfisca_core/entities/role.py +92 -0
  24. openfisca_core/entities/tests/__init__.py +0 -0
  25. openfisca_core/entities/tests/test_entity.py +10 -0
  26. openfisca_core/entities/tests/test_group_entity.py +70 -0
  27. openfisca_core/entities/tests/test_role.py +11 -0
  28. openfisca_core/entities/types.py +44 -0
  29. openfisca_core/errors/__init__.py +64 -0
  30. openfisca_core/errors/cycle_error.py +2 -0
  31. openfisca_core/errors/empty_argument_error.py +39 -0
  32. openfisca_core/errors/nan_creation_error.py +2 -0
  33. openfisca_core/errors/parameter_not_found_error.py +16 -0
  34. openfisca_core/errors/parameter_parsing_error.py +18 -0
  35. openfisca_core/errors/period_mismatch_error.py +9 -0
  36. openfisca_core/errors/situation_parsing_error.py +26 -0
  37. openfisca_core/errors/spiral_error.py +2 -0
  38. openfisca_core/errors/variable_name_config_error.py +2 -0
  39. openfisca_core/errors/variable_not_found_error.py +29 -0
  40. openfisca_core/experimental/__init__.py +9 -0
  41. openfisca_core/experimental/_errors.py +5 -0
  42. openfisca_core/experimental/_memory_config.py +41 -0
  43. openfisca_core/formula_helpers.py +9 -0
  44. openfisca_core/holders/__init__.py +33 -0
  45. openfisca_core/holders/helpers.py +93 -0
  46. openfisca_core/holders/holder.py +328 -0
  47. openfisca_core/holders/tests/__init__.py +0 -0
  48. openfisca_core/holders/tests/test_helpers.py +134 -0
  49. openfisca_core/holders/types.py +3 -0
  50. openfisca_core/indexed_enums/__init__.py +18 -0
  51. openfisca_core/indexed_enums/_enum_type.py +79 -0
  52. openfisca_core/indexed_enums/_errors.py +35 -0
  53. openfisca_core/indexed_enums/_guards.py +209 -0
  54. openfisca_core/indexed_enums/_utils.py +180 -0
  55. openfisca_core/indexed_enums/config.py +6 -0
  56. openfisca_core/indexed_enums/enum.py +218 -0
  57. openfisca_core/indexed_enums/enum_array.py +316 -0
  58. openfisca_core/indexed_enums/py.typed +0 -0
  59. openfisca_core/indexed_enums/tests/__init__.py +0 -0
  60. openfisca_core/indexed_enums/tests/test_enum.py +135 -0
  61. openfisca_core/indexed_enums/tests/test_enum_array.py +30 -0
  62. openfisca_core/indexed_enums/types.py +49 -0
  63. openfisca_core/memory_config.py +9 -0
  64. openfisca_core/model_api.py +71 -0
  65. openfisca_core/parameters/__init__.py +71 -0
  66. openfisca_core/parameters/at_instant_like.py +17 -0
  67. openfisca_core/parameters/config.py +55 -0
  68. openfisca_core/parameters/helpers.py +106 -0
  69. openfisca_core/parameters/parameter.py +217 -0
  70. openfisca_core/parameters/parameter_at_instant.py +75 -0
  71. openfisca_core/parameters/parameter_node.py +176 -0
  72. openfisca_core/parameters/parameter_node_at_instant.py +57 -0
  73. openfisca_core/parameters/parameter_scale.py +121 -0
  74. openfisca_core/parameters/parameter_scale_bracket.py +7 -0
  75. openfisca_core/parameters/values_history.py +5 -0
  76. openfisca_core/parameters/vectorial_parameter_node_at_instant.py +179 -0
  77. openfisca_core/periods/__init__.py +77 -0
  78. openfisca_core/periods/_errors.py +28 -0
  79. openfisca_core/periods/_parsers.py +122 -0
  80. openfisca_core/periods/config.py +20 -0
  81. openfisca_core/periods/date_unit.py +110 -0
  82. openfisca_core/periods/helpers.py +314 -0
  83. openfisca_core/periods/instant_.py +226 -0
  84. openfisca_core/periods/period_.py +919 -0
  85. openfisca_core/periods/py.typed +0 -0
  86. openfisca_core/periods/tests/__init__.py +0 -0
  87. openfisca_core/periods/tests/helpers/__init__.py +0 -0
  88. openfisca_core/periods/tests/helpers/test_helpers.py +65 -0
  89. openfisca_core/periods/tests/helpers/test_instant.py +73 -0
  90. openfisca_core/periods/tests/helpers/test_period.py +134 -0
  91. openfisca_core/periods/tests/test_instant.py +32 -0
  92. openfisca_core/periods/tests/test_parsers.py +129 -0
  93. openfisca_core/periods/tests/test_period.py +283 -0
  94. openfisca_core/populations/__init__.py +64 -0
  95. openfisca_core/populations/_core_population.py +454 -0
  96. openfisca_core/populations/_errors.py +65 -0
  97. openfisca_core/populations/group_population.py +326 -0
  98. openfisca_core/populations/population.py +142 -0
  99. openfisca_core/populations/tests/__init__.py +0 -0
  100. openfisca_core/populations/tests/test_members_position.py +116 -0
  101. openfisca_core/populations/types.py +110 -0
  102. openfisca_core/projectors/__init__.py +39 -0
  103. openfisca_core/projectors/entity_to_person_projector.py +12 -0
  104. openfisca_core/projectors/first_person_to_entity_projector.py +13 -0
  105. openfisca_core/projectors/helpers.py +139 -0
  106. openfisca_core/projectors/projector.py +38 -0
  107. openfisca_core/projectors/typing.py +27 -0
  108. openfisca_core/projectors/unique_role_to_entity_projector.py +14 -0
  109. openfisca_core/rates.py +9 -0
  110. openfisca_core/reforms/__init__.py +24 -0
  111. openfisca_core/reforms/in_yaml_test_reform.py +28 -0
  112. openfisca_core/reforms/reform.py +86 -0
  113. openfisca_core/scripts/__init__.py +106 -0
  114. openfisca_core/scripts/__pycache__/__init__.cpython-310-pytest-8.3.3.pyc +0 -0
  115. openfisca_core/scripts/__pycache__/__init__.cpython-310-pytest-8.4.2.pyc +0 -0
  116. openfisca_core/scripts/__pycache__/__init__.cpython-310.pyc +0 -0
  117. openfisca_core/scripts/__pycache__/__init__.cpython-311-pytest-8.3.3.pyc +0 -0
  118. openfisca_core/scripts/__pycache__/__init__.cpython-311-pytest-8.4.2.pyc +0 -0
  119. openfisca_core/scripts/__pycache__/__init__.cpython-311.pyc +0 -0
  120. openfisca_core/scripts/__pycache__/__init__.cpython-312-pytest-8.4.2.pyc +0 -0
  121. openfisca_core/scripts/__pycache__/__init__.cpython-312.pyc +0 -0
  122. openfisca_core/scripts/__pycache__/__init__.cpython-313-pytest-8.3.3.pyc +0 -0
  123. openfisca_core/scripts/__pycache__/__init__.cpython-313-pytest-8.4.2.pyc +0 -0
  124. openfisca_core/scripts/__pycache__/__init__.cpython-313.pyc +0 -0
  125. openfisca_core/scripts/__pycache__/find_placeholders.cpython-311.pyc +0 -0
  126. openfisca_core/scripts/__pycache__/find_placeholders.cpython-313.pyc +0 -0
  127. openfisca_core/scripts/__pycache__/measure_numpy_condition_notations.cpython-311.pyc +0 -0
  128. openfisca_core/scripts/__pycache__/measure_numpy_condition_notations.cpython-313.pyc +0 -0
  129. openfisca_core/scripts/__pycache__/measure_performances.cpython-311.pyc +0 -0
  130. openfisca_core/scripts/__pycache__/measure_performances.cpython-313.pyc +0 -0
  131. openfisca_core/scripts/__pycache__/measure_performances_fancy_indexing.cpython-311.pyc +0 -0
  132. openfisca_core/scripts/__pycache__/measure_performances_fancy_indexing.cpython-313.pyc +0 -0
  133. openfisca_core/scripts/__pycache__/openfisca_command.cpython-310.pyc +0 -0
  134. openfisca_core/scripts/__pycache__/openfisca_command.cpython-311.pyc +0 -0
  135. openfisca_core/scripts/__pycache__/openfisca_command.cpython-312.pyc +0 -0
  136. openfisca_core/scripts/__pycache__/openfisca_command.cpython-313.pyc +0 -0
  137. openfisca_core/scripts/__pycache__/remove_fuzzy.cpython-311.pyc +0 -0
  138. openfisca_core/scripts/__pycache__/remove_fuzzy.cpython-313.pyc +0 -0
  139. openfisca_core/scripts/__pycache__/run_test.cpython-310.pyc +0 -0
  140. openfisca_core/scripts/__pycache__/run_test.cpython-311.pyc +0 -0
  141. openfisca_core/scripts/__pycache__/run_test.cpython-312.pyc +0 -0
  142. openfisca_core/scripts/__pycache__/run_test.cpython-313.pyc +0 -0
  143. openfisca_core/scripts/__pycache__/simulation_generator.cpython-311.pyc +0 -0
  144. openfisca_core/scripts/__pycache__/simulation_generator.cpython-313.pyc +0 -0
  145. openfisca_core/scripts/assets/__init__.py +0 -0
  146. openfisca_core/scripts/assets/__pycache__/__init__.cpython-311.pyc +0 -0
  147. openfisca_core/scripts/assets/__pycache__/__init__.cpython-313.pyc +0 -0
  148. openfisca_core/scripts/assets/index.html +140 -0
  149. openfisca_core/scripts/find_placeholders.py +51 -0
  150. openfisca_core/scripts/measure_numpy_condition_notations.py +137 -0
  151. openfisca_core/scripts/measure_performances.py +291 -0
  152. openfisca_core/scripts/measure_performances_fancy_indexing.py +89 -0
  153. openfisca_core/scripts/migrations/__init__.py +0 -0
  154. openfisca_core/scripts/migrations/__pycache__/__init__.cpython-311.pyc +0 -0
  155. openfisca_core/scripts/migrations/__pycache__/__init__.cpython-313.pyc +0 -0
  156. openfisca_core/scripts/migrations/__pycache__/v24_to_25.cpython-311.pyc +0 -0
  157. openfisca_core/scripts/migrations/__pycache__/v24_to_25.cpython-313.pyc +0 -0
  158. openfisca_core/scripts/migrations/v16_2_to_v17/__init__.py +0 -0
  159. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/__init__.cpython-311.pyc +0 -0
  160. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/__init__.cpython-313.pyc +0 -0
  161. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_country_template.cpython-311.pyc +0 -0
  162. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_country_template.cpython-313.pyc +0 -0
  163. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_extension_template.cpython-311.pyc +0 -0
  164. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_extension_template.cpython-313.pyc +0 -0
  165. openfisca_core/scripts/migrations/v16_2_to_v17/legislation.xsd +102 -0
  166. openfisca_core/scripts/migrations/v16_2_to_v17/xml_to_yaml_country_template.py +30 -0
  167. openfisca_core/scripts/migrations/v16_2_to_v17/xml_to_yaml_extension_template.py +26 -0
  168. openfisca_core/scripts/migrations/v24_to_25.py +156 -0
  169. openfisca_core/scripts/openfisca_command.py +192 -0
  170. openfisca_core/scripts/remove_fuzzy.py +213 -0
  171. openfisca_core/scripts/run_test.py +51 -0
  172. openfisca_core/scripts/simulation_generator.py +90 -0
  173. openfisca_core/simulation_builder.py +16 -0
  174. openfisca_core/simulations/__init__.py +45 -0
  175. openfisca_core/simulations/_build_default_simulation.py +158 -0
  176. openfisca_core/simulations/_build_from_variables.py +230 -0
  177. openfisca_core/simulations/_type_guards.py +298 -0
  178. openfisca_core/simulations/helpers.py +111 -0
  179. openfisca_core/simulations/simulation.py +618 -0
  180. openfisca_core/simulations/simulation_builder.py +855 -0
  181. openfisca_core/simulations/typing.py +203 -0
  182. openfisca_core/taxbenefitsystems/__init__.py +26 -0
  183. openfisca_core/taxbenefitsystems/tax_benefit_system.py +584 -0
  184. openfisca_core/taxscales/__init__.py +35 -0
  185. openfisca_core/taxscales/abstract_rate_tax_scale.py +41 -0
  186. openfisca_core/taxscales/abstract_tax_scale.py +53 -0
  187. openfisca_core/taxscales/amount_tax_scale_like.py +55 -0
  188. openfisca_core/taxscales/helpers.py +44 -0
  189. openfisca_core/taxscales/linear_average_rate_tax_scale.py +76 -0
  190. openfisca_core/taxscales/marginal_amount_tax_scale.py +34 -0
  191. openfisca_core/taxscales/marginal_rate_tax_scale.py +286 -0
  192. openfisca_core/taxscales/rate_tax_scale_like.py +214 -0
  193. openfisca_core/taxscales/single_amount_tax_scale.py +32 -0
  194. openfisca_core/taxscales/tax_scale_like.py +65 -0
  195. openfisca_core/tools/__init__.py +94 -0
  196. openfisca_core/tools/parallel_plugin.py +55 -0
  197. openfisca_core/tools/simulation_dumper.py +137 -0
  198. openfisca_core/tools/test_runner.py +802 -0
  199. openfisca_core/tracers/__init__.py +40 -0
  200. openfisca_core/tracers/computation_log.py +196 -0
  201. openfisca_core/tracers/flat_trace.py +87 -0
  202. openfisca_core/tracers/full_tracer.py +172 -0
  203. openfisca_core/tracers/performance_log.py +133 -0
  204. openfisca_core/tracers/simple_tracer.py +64 -0
  205. openfisca_core/tracers/trace_node.py +121 -0
  206. openfisca_core/tracers/tracing_parameter_node_at_instant.py +81 -0
  207. openfisca_core/types.py +548 -0
  208. openfisca_core/variables/__init__.py +26 -0
  209. openfisca_core/variables/config.py +53 -0
  210. openfisca_core/variables/helpers.py +67 -0
  211. openfisca_core/variables/tests/__init__.py +0 -0
  212. openfisca_core/variables/tests/test_definition_period.py +43 -0
  213. openfisca_core/variables/variable.py +474 -0
  214. openfisca_core/warnings/__init__.py +25 -0
  215. openfisca_core/warnings/libyaml_warning.py +2 -0
  216. openfisca_core/warnings/tempfile_warning.py +2 -0
  217. openfisca_core_test-46.0.0.data/data/share/openfisca/openfisca-core/CHANGELOG.md +4209 -0
  218. openfisca_core_test-46.0.0.data/data/share/openfisca/openfisca-core/README.md +152 -0
  219. openfisca_core_test-46.0.0.dist-info/METADATA +194 -0
  220. openfisca_core_test-46.0.0.dist-info/RECORD +237 -0
  221. openfisca_core_test-46.0.0.dist-info/WHEEL +5 -0
  222. openfisca_core_test-46.0.0.dist-info/entry_points.txt +3 -0
  223. openfisca_core_test-46.0.0.dist-info/licenses/LICENSE +661 -0
  224. openfisca_core_test-46.0.0.dist-info/top_level.txt +2 -0
  225. openfisca_web_api/__init__.py +0 -0
  226. openfisca_web_api/app.py +226 -0
  227. openfisca_web_api/errors.py +11 -0
  228. openfisca_web_api/handlers.py +90 -0
  229. openfisca_web_api/loader/__init__.py +22 -0
  230. openfisca_web_api/loader/entities.py +28 -0
  231. openfisca_web_api/loader/parameters.py +122 -0
  232. openfisca_web_api/loader/spec.py +168 -0
  233. openfisca_web_api/loader/tax_benefit_system.py +27 -0
  234. openfisca_web_api/loader/variables.py +121 -0
  235. openfisca_web_api/openAPI.yml +434 -0
  236. openfisca_web_api/scripts/__init__.py +0 -0
  237. openfisca_web_api/scripts/serve.py +99 -0
@@ -0,0 +1,102 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3
+
4
+ <xs:element name="NODE" type="nodeType"/>
5
+
6
+ <xs:group name="valuesHistory">
7
+ <xs:sequence>
8
+ <xs:choice maxOccurs="unbounded">
9
+ <xs:element name="VALUE" type="valueType"/>
10
+ <xs:element name="END" type="endType"/>
11
+ <xs:element name="PLACEHOLDER" type="placeholderType"/>
12
+ </xs:choice>
13
+ </xs:sequence>
14
+ </xs:group>
15
+
16
+ <xs:complexType name="nodeType">
17
+ <xs:sequence>
18
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
19
+ <xs:element name="NODE" type="nodeType"/>
20
+ <xs:element name="CODE" type="codeType"/>
21
+ <xs:element name="BAREME" type="baremeType"/>
22
+ </xs:choice>
23
+ </xs:sequence>
24
+ <xs:attribute name="code" type="xs:string" use="required"/>
25
+ <xs:attribute name="description" type="xs:string"/>
26
+ <xs:attribute name="origin" type="xs:string"/>
27
+ <xs:attribute name="reference" type="xs:string"/>
28
+ </xs:complexType>
29
+
30
+ <xs:complexType name="codeType">
31
+ <xs:group ref="valuesHistory"/>
32
+ <xs:attribute name="code" type="xs:string" use="required"/>
33
+ <xs:attribute name="description" type="xs:string"/>
34
+ <xs:attribute name="format" type="xs:string"/>
35
+ <xs:attribute name="origin" type="xs:string"/>
36
+ <xs:attribute name="type" type="xs:string"/>
37
+ <xs:attribute name="conflicts" type="xs:string"/>
38
+ <xs:attribute name="reference" type="xs:string"/>
39
+ </xs:complexType>
40
+
41
+ <xs:complexType name="endType">
42
+ <xs:attribute name="deb" type="xs:date" use="required"/>
43
+ <xs:attribute name="reference" type="xs:string"/>
44
+ </xs:complexType>
45
+
46
+ <xs:complexType name="valueType">
47
+ <xs:attribute name="deb" type="xs:date" use="required"/>
48
+ <xs:attribute name="valeur" type="xs:float" use="required"/>
49
+ <xs:attribute name="reference" type="xs:string"/>
50
+ </xs:complexType>
51
+
52
+ <xs:complexType name="baremeType">
53
+ <xs:sequence>
54
+ <xs:element name="TRANCHE" type="trancheType" minOccurs="0" maxOccurs="unbounded"/>
55
+ </xs:sequence>
56
+ <xs:attribute name="code" type="xs:string" use="required"/>
57
+ <xs:attribute name="description" type="xs:string"/>
58
+ <xs:attribute name="origin" type="xs:string"/>
59
+ <xs:attribute name="type" type="xs:string"/>
60
+ <xs:attribute name="conflicts" type="xs:string"/>
61
+ <xs:attribute name="option" type="xs:string"/>
62
+ <xs:attribute name="reference" type="xs:string"/>
63
+ </xs:complexType>
64
+
65
+ <xs:complexType name="trancheType">
66
+ <xs:all>
67
+ <xs:element name="ASSIETTE" type="assietteType" minOccurs="0"/>
68
+ <xs:element name="SEUIL" type="seuilType"/>
69
+ <xs:element name="TAUX" type="tauxType" minOccurs="0"/>
70
+ <xs:element name="MONTANT" type="montantType" minOccurs="0"/>
71
+ </xs:all>
72
+ <xs:attribute name="code" type="xs:string"/>
73
+ <xs:attribute name="reference" type="xs:string"/>
74
+ </xs:complexType>
75
+
76
+ <xs:complexType name="assietteType">
77
+ <xs:group ref="valuesHistory"/>
78
+ <xs:attribute name="reference" type="xs:string"/>
79
+ </xs:complexType>
80
+
81
+ <xs:complexType name="tauxType">
82
+ <xs:group ref="valuesHistory"/>
83
+ <xs:attribute name="reference" type="xs:string"/>
84
+ </xs:complexType>
85
+
86
+ <xs:complexType name="montantType">
87
+ <xs:group ref="valuesHistory"/>
88
+ <xs:attribute name="reference" type="xs:string"/>
89
+ </xs:complexType>
90
+
91
+ <xs:complexType name="seuilType">
92
+ <xs:group ref="valuesHistory"/>
93
+ <xs:attribute name="conflicts" type="xs:string"/>
94
+ <xs:attribute name="reference" type="xs:string"/>
95
+ </xs:complexType>
96
+
97
+ <xs:complexType name="placeholderType">
98
+ <xs:attribute name="deb" type="xs:date" use="required"/>
99
+ <xs:attribute name="reference" type="xs:string"/>
100
+ </xs:complexType>
101
+
102
+ </xs:schema>
@@ -0,0 +1,30 @@
1
+ """xml_to_yaml_country_template.py : Parse XML parameter files for Country-Template and convert them to YAML files. Comments are NOT transformed.
2
+
3
+ Usage :
4
+ `python xml_to_yaml_country_template.py output_dir`
5
+ or just (output is written in a directory called `yaml_parameters`):
6
+ `python xml_to_yaml_country_template.py`
7
+ """
8
+
9
+ import os
10
+ import sys
11
+
12
+ from openfisca_country_template import COUNTRY_DIR, CountryTaxBenefitSystem
13
+
14
+ from . import xml_to_yaml
15
+
16
+ tax_benefit_system = CountryTaxBenefitSystem()
17
+
18
+ target_path = sys.argv[1] if len(sys.argv) > 1 else "yaml_parameters"
19
+
20
+ param_dir = os.path.join(COUNTRY_DIR, "parameters")
21
+ param_files = [
22
+ "benefits.xml",
23
+ "general.xml",
24
+ "taxes.xml",
25
+ ]
26
+ legislation_xml_info_list = [
27
+ (os.path.join(param_dir, param_file), []) for param_file in param_files
28
+ ]
29
+
30
+ xml_to_yaml.write_parameters(legislation_xml_info_list, target_path)
@@ -0,0 +1,26 @@
1
+ """xml_to_yaml_extension_template.py : Parse XML parameter files for Extension-Template and convert them to YAML files. Comments are NOT transformed.
2
+
3
+ Usage :
4
+ `python xml_to_yaml_extension_template.py output_dir`
5
+ or just (output is written in a directory called `yaml_parameters`):
6
+ `python xml_to_yaml_extension_template.py`
7
+ """
8
+
9
+ import os
10
+ import sys
11
+
12
+ import openfisca_extension_template
13
+
14
+ from . import xml_to_yaml
15
+
16
+ target_path = sys.argv[1] if len(sys.argv) > 1 else "yaml_parameters"
17
+
18
+ param_dir = os.path.dirname(openfisca_extension_template.__file__)
19
+ param_files = [
20
+ "parameters.xml",
21
+ ]
22
+ legislation_xml_info_list = [
23
+ (os.path.join(param_dir, param_file), []) for param_file in param_files
24
+ ]
25
+
26
+ xml_to_yaml.write_parameters(legislation_xml_info_list, target_path)
@@ -0,0 +1,156 @@
1
+ # flake8: noqa T001
2
+
3
+ import argparse
4
+ import glob
5
+ import os
6
+
7
+ from ruamel.yaml import YAML
8
+ from ruamel.yaml.comments import CommentedSeq
9
+
10
+ from openfisca_core.scripts import (
11
+ add_tax_benefit_system_arguments,
12
+ build_tax_benefit_system,
13
+ )
14
+
15
+ yaml = YAML()
16
+ yaml.default_flow_style = False
17
+ yaml.width = 4096
18
+
19
+ TEST_METADATA = {
20
+ "period",
21
+ "name",
22
+ "reforms",
23
+ "only_variables",
24
+ "ignore_variables",
25
+ "absolute_error_margin",
26
+ "relative_error_margin",
27
+ "description",
28
+ "keywords",
29
+ }
30
+
31
+
32
+ def build_parser():
33
+ parser = argparse.ArgumentParser()
34
+ parser.add_argument(
35
+ "path",
36
+ help="paths (files or directories) of tests to execute",
37
+ nargs="+",
38
+ )
39
+ return add_tax_benefit_system_arguments(parser)
40
+
41
+
42
+ class Migrator:
43
+ def __init__(self, tax_benefit_system) -> None:
44
+ self.tax_benefit_system = tax_benefit_system
45
+ self.entities_by_plural = {
46
+ entity.plural: entity for entity in self.tax_benefit_system.entities
47
+ }
48
+
49
+ def migrate(self, path) -> None:
50
+ if isinstance(path, list):
51
+ for item in path:
52
+ self.migrate(item)
53
+ return
54
+
55
+ if os.path.isdir(path):
56
+ yaml_paths = glob.glob(os.path.join(path, "*.yaml"))
57
+ subdirectories = glob.glob(os.path.join(path, "*/"))
58
+
59
+ for yaml_path in yaml_paths:
60
+ self.migrate(yaml_path)
61
+
62
+ for subdirectory in subdirectories:
63
+ self.migrate(subdirectory)
64
+
65
+ return
66
+
67
+ with open(path) as yaml_file:
68
+ tests = yaml.safe_load(yaml_file)
69
+ if isinstance(tests, CommentedSeq):
70
+ migrated_tests = [self.convert_test(test) for test in tests]
71
+ else:
72
+ migrated_tests = self.convert_test(tests)
73
+
74
+ with open(path, "w") as yaml_file:
75
+ yaml.dump(migrated_tests, yaml_file)
76
+
77
+ def convert_test(self, test):
78
+ if test.get("output"):
79
+ # This test is already converted, ignoring it
80
+ return test
81
+ result = {}
82
+ outputs = test.pop("output_variables")
83
+ inputs = test.pop("input_variables", {})
84
+ for key, value in test.items():
85
+ if key in TEST_METADATA:
86
+ result[key] = value
87
+ else:
88
+ inputs[key] = value
89
+ result["input"] = self.convert_inputs(inputs)
90
+ result["output"] = outputs
91
+ return result
92
+
93
+ def convert_inputs(self, inputs):
94
+ first_key = next(iter(inputs.keys()), None)
95
+ if first_key not in self.entities_by_plural:
96
+ return inputs
97
+ results = {}
98
+ for entity_plural, entities_description in inputs.items():
99
+ entity = self.entities_by_plural[entity_plural]
100
+ if not isinstance(entities_description, (CommentedSeq, list)):
101
+ entities_description = [entities_description]
102
+ if not entity.is_person and len(entities_description) == 1:
103
+ results[entity.key] = remove_id(entities_description[0])
104
+ continue
105
+ results[entity_plural] = self.convert_entities(entity, entities_description)
106
+
107
+ return self.generate_missing_entities(results)
108
+
109
+ def convert_entities(self, entity, entities_description):
110
+ return {
111
+ entity_description.get("id", f"{entity.key}_{index}"): remove_id(
112
+ entity_description,
113
+ )
114
+ for index, entity_description in enumerate(entities_description)
115
+ }
116
+
117
+ def generate_missing_entities(self, inputs):
118
+ for entity in self.tax_benefit_system.entities:
119
+ if entity.plural in inputs or entity.key in inputs:
120
+ continue
121
+ persons = inputs[self.tax_benefit_system.person_entity.plural]
122
+ if len(persons) == 1:
123
+ person_id = next(iter(persons))
124
+ inputs[entity.key] = {
125
+ entity.roles[0].plural or entity.roles[0].key: [person_id],
126
+ }
127
+ else:
128
+ inputs[entity.plural] = {
129
+ f"{entity.key}_{index}": {
130
+ entity.roles[0].plural or entity.roles[0].key: [person_id],
131
+ }
132
+ for index, person_id in enumerate(persons.keys())
133
+ }
134
+ return inputs
135
+
136
+
137
+ def remove_id(input_dict):
138
+ return {key: value for (key, value) in input_dict.items() if key != "id"}
139
+
140
+
141
+ def main() -> None:
142
+ parser = build_parser()
143
+ args = parser.parse_args()
144
+ paths = [os.path.abspath(path) for path in args.path]
145
+
146
+ tax_benefit_system = build_tax_benefit_system(
147
+ args.country_package,
148
+ args.extensions,
149
+ args.reforms,
150
+ )
151
+
152
+ Migrator(tax_benefit_system).migrate(paths)
153
+
154
+
155
+ if __name__ == "__main__":
156
+ main()
@@ -0,0 +1,192 @@
1
+ import argparse
2
+ import sys
3
+ import warnings
4
+ from importlib.metadata import version
5
+
6
+ from openfisca_core.scripts import add_tax_benefit_system_arguments
7
+
8
+ """
9
+ Define the `openfisca` command line interface.
10
+ """
11
+
12
+
13
+ def get_parser():
14
+ parser = argparse.ArgumentParser()
15
+ parser.add_argument(
16
+ "--version",
17
+ action="version",
18
+ version=f"OpenFisca-Core {version('OpenFisca-Core')}",
19
+ )
20
+
21
+ subparsers = parser.add_subparsers(help="Available commands", dest="command")
22
+ subparsers.required = (
23
+ True # Can be added as an argument of add_subparsers in Python 3
24
+ )
25
+
26
+ def build_serve_parser(parser):
27
+ # Define OpenFisca modules configuration
28
+ parser = add_tax_benefit_system_arguments(parser)
29
+
30
+ # Define server configuration
31
+ parser.add_argument(
32
+ "-p",
33
+ "--port",
34
+ action="store",
35
+ help="port to serve on (use --bind to specify host and port)",
36
+ type=int,
37
+ )
38
+ parser.add_argument(
39
+ "--tracker-url",
40
+ action="store",
41
+ help="tracking service url",
42
+ type=str,
43
+ )
44
+ parser.add_argument(
45
+ "--tracker-idsite",
46
+ action="store",
47
+ help="tracking service id site",
48
+ type=int,
49
+ )
50
+ parser.add_argument(
51
+ "--tracker-token",
52
+ action="store",
53
+ help="tracking service authentication token",
54
+ type=str,
55
+ )
56
+ parser.add_argument(
57
+ "--welcome-message",
58
+ action="store",
59
+ help="welcome message users will get when visiting the API root",
60
+ type=str,
61
+ )
62
+ parser.add_argument(
63
+ "-f",
64
+ "--configuration-file",
65
+ action="store",
66
+ help="configuration file",
67
+ type=str,
68
+ )
69
+
70
+ return parser
71
+
72
+ parser_serve = subparsers.add_parser("serve", help="Run the OpenFisca Web API")
73
+ parser_serve = build_serve_parser(parser_serve)
74
+
75
+ def build_test_parser(parser):
76
+ parser.add_argument(
77
+ "path",
78
+ help="paths (files or directories) of tests to execute",
79
+ nargs="+",
80
+ )
81
+ parser = add_tax_benefit_system_arguments(parser)
82
+ parser.add_argument(
83
+ "-n",
84
+ "--name_filter",
85
+ default=None,
86
+ help="partial name of tests to execute. Only tests with the given name_filter in their name, file name, or keywords will be run.",
87
+ )
88
+ parser.add_argument(
89
+ "-p",
90
+ "--pdb",
91
+ action="store_true",
92
+ default=False,
93
+ help="drop into debugger on failures or errors",
94
+ )
95
+ parser.add_argument(
96
+ "--performance-graph",
97
+ "--performance",
98
+ action="store_true",
99
+ default=False,
100
+ help="output a performance graph in a 'performance_graph.html' file",
101
+ )
102
+ parser.add_argument(
103
+ "--performance-tables",
104
+ action="store_true",
105
+ default=False,
106
+ help="output performance CSV tables",
107
+ )
108
+ parser.add_argument(
109
+ "-v",
110
+ "--verbose",
111
+ action="store_true",
112
+ default=False,
113
+ help="increase output verbosity. If specified, output the entire calculation trace.",
114
+ )
115
+ parser.add_argument(
116
+ "-a",
117
+ "--aggregate",
118
+ action="store_true",
119
+ default=False,
120
+ help="increase output verbosity to aggregate. If specified, output the avg, max, and min values of the calculation trace. This flag has no effect without --verbose.",
121
+ )
122
+ parser.add_argument(
123
+ "-d",
124
+ "--max-depth",
125
+ type=int,
126
+ default=sys.maxsize,
127
+ help="set maximal verbosity depth. If specified, output the calculation trace up to the provided depth. This flag has no effect without --verbose.",
128
+ )
129
+ parser.add_argument(
130
+ "-o",
131
+ "--only-variables",
132
+ nargs="*",
133
+ default=None,
134
+ help="variables to test. If specified, only test the given variables.",
135
+ )
136
+ parser.add_argument(
137
+ "-i",
138
+ "--ignore-variables",
139
+ nargs="*",
140
+ default=None,
141
+ help="variables to ignore. If specified, do not test the given variables.",
142
+ )
143
+ parser.add_argument(
144
+ "--in-parallel",
145
+ action="store_true",
146
+ default=False,
147
+ help="run tests in parallel",
148
+ )
149
+ parser.add_argument(
150
+ "--num-workers",
151
+ type=int,
152
+ default=0,
153
+ help="number of parallel workers (default: CPU count - 1)",
154
+ )
155
+ parser.add_argument(
156
+ "--ignore-default",
157
+ action="store_true",
158
+ default=False,
159
+ help="in verbose mode, do not display variables that have their default value",
160
+ )
161
+
162
+ return parser
163
+
164
+ parser_test = subparsers.add_parser("test", help="Run OpenFisca YAML tests")
165
+ parser_test = build_test_parser(parser_test)
166
+
167
+ return parser
168
+
169
+
170
+ def main():
171
+ if sys.argv[0].endswith("openfisca-run-test"):
172
+ sys.argv[0:1] = ["openfisca", "test"]
173
+ message = "The 'openfisca-run-test' command has been deprecated in favor of 'openfisca test' since version 25.0, and will be removed in the future."
174
+ warnings.warn(message, Warning, stacklevel=2)
175
+
176
+ parser = get_parser()
177
+
178
+ args, _ = parser.parse_known_args()
179
+
180
+ if args.command == "serve":
181
+ from openfisca_web_api.scripts.serve import main
182
+
183
+ return sys.exit(main(parser))
184
+ if args.command == "test":
185
+ from openfisca_core.scripts.run_test import main
186
+
187
+ return sys.exit(main(parser))
188
+ return None
189
+
190
+
191
+ if __name__ == "__main__":
192
+ sys.exit(main())