openfisca / openfisca-core

OpenFisca core engine. See other repositories for countries-specific code & data.
https://openfisca.org
GNU Affero General Public License v3.0
169 stars 75 forks source link

Fix country and extension loading #1281

Open bonjourmauko opened 2 days ago

bonjourmauko commented 2 days ago

Hi there!

I really enjoy OpenFisca, but I recently encountered an issue.

Here is what I did:

I'm trying to deploy the country-template to conda. See: https://github.com/openfisca/country-template/pull/157

Here is what I expected to happen:

In the test phase, the country should be properly loaded, and the tests should run.

Whether the tests pass or not is not the issue, but the loading of the tax benefit system.

Here is what actually happened:

It fails. See: https://github.com/openfisca/country-template/actions/runs/11348459181/job/31562332866

ERROR:openfisca_core.taxbenefitsystems.tax_benefit_system:Unable to load OpenFisca variables from file "/home/runner/miniconda3/envs/openfisca/lib/python3.9/site-packages/openfisca_country_template/variables/taxes.py"
Traceback (most recent call last):
Traceback (most recent call last):
  File "/home/runner/miniconda3/envs/openfisca/bin/openfisca", line 10, in <module>
    sys.exit(main())
  File "/home/runner/miniconda3/envs/openfisca/lib/python3.9/site-packages/openfisca_core/scripts/openfisca_command.py", line 163, in main
    return sys.exit(main(parser))
  File "/home/runner/miniconda3/envs/openfisca/lib/python3.9/site-packages/openfisca_core/scripts/run_test.py", line 16, in main
    tax_benefit_system = build_tax_benefit_system(
  File "/home/runner/miniconda3/envs/openfisca/lib/python3.9/site-packages/openfisca_core/scripts/__init__.py", line 58, in build_tax_benefit_system
    tax_benefit_system = country_package.CountryTaxBenefitSystem()
  File "/home/runner/miniconda3/envs/openfisca/lib/python3.9/site-packages/openfisca_country_template/__init__.py", line 34, in __init__
    self.add_variables_from_directory(os.path.join(COUNTRY_DIR, "variables"))
  File "/home/runner/miniconda3/envs/openfisca/lib/python3.9/site-packages/openfisca_core/taxbenefitsystems/tax_benefit_system.py", line 285, in add_variables_from_directory
    self.add_variables_from_file(py_file)
  File "/home/runner/miniconda3/envs/openfisca/lib/python3.9/site-packages/openfisca_core/taxbenefitsystems/tax_benefit_system.py", line 230, in add_variables_from_file
    self.get_package_metadata()["location"],
  File "/home/runner/miniconda3/envs/openfisca/lib/python3.9/site-packages/openfisca_core/taxbenefitsystems/tax_benefit_system.py", line 534, in get_package_metadata
    "name": source_metadata.get("Name").lower(),
AttributeError: 'NoneType' object has no attribute 'lower'
  File "/home/runner/miniconda3/envs/openfisca/lib/python3.9/site-packages/openfisca_core/taxbenefitsystems/tax_benefit_system.py", line 230, in add_variables_from_file
    self.get_package_metadata()["location"],
  File "/home/runner/miniconda3/envs/openfisca/lib/python3.9/site-packages/openfisca_core/taxbenefitsystems/tax_benefit_system.py", line 534, in get_package_metadata
    "name": source_metadata.get("Name").lower(),
AttributeError: 'NoneType' object has no attribute 'lower'

Here is data (or links to it) that can help you reproduce this issue:

https://github.com/openfisca/openfisca-core/pull/1037 https://github.com/openfisca/openfisca-core/pull/1059 https://github.com/openfisca/openfisca-core/pull/1015

Context

I identify more as a:

bonjourmauko commented 2 days ago

Poke @benoit-cty

benoit-cty commented 2 days ago

Hello, If we look at https://github.com/openfisca/openfisca-core/blob/master/.conda/openfisca-country-template/recipe.yaml

We see :

package:
  name: ${{ name|lower }}

But name is not defined in this file.

Maybe we need to add {% set name = "OpenFisca-Country-Template" %}

But I'm not sure as your log output shows that he his trying to read setup.py to load the Name= from it.

Not related but it is possible to read from pyproject.toml instead of setup.py with

{% set pyproject = load_file_data('pyproject.toml') %}
  {% for req in pyproject.get('project').get('dependencies') %}
  - {{ req }}
  {% endfor %}