Skip to content

Commit

Permalink
Merge pull request #1090 from openfisca/issue1053
Browse files Browse the repository at this point in the history
Remove calls to deprecated imp module
  • Loading branch information
benjello committed Dec 29, 2021
2 parents 601a397 + c3bd472 commit 9deaa60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

### 35.7.5 [#1090](https://github.com/openfisca/openfisca-core/pull/1090)

#### Technical changes

- Remove calls to deprecated imp module

### 35.7.4 [#1083](https://github.com/openfisca/openfisca-core/pull/1083)

#### Technical changes
Expand Down
10 changes: 6 additions & 4 deletions openfisca_core/taxbenefitsystems/tax_benefit_system.py
Expand Up @@ -5,9 +5,9 @@
import logging
import os
import pkg_resources
import sys
import traceback
import typing
from imp import find_module, load_module

from openfisca_core import commons, periods, variables
from openfisca_core.entities import Entity
Expand Down Expand Up @@ -188,11 +188,13 @@ def add_variables_from_file(self, file_path):
# As Python remembers loaded modules by name, in order to prevent collisions, we need to make sure that:
# - Files with the same name, but located in different directories, have a different module names. Hence the file path hash in the module name.
# - The same file, loaded by different tax and benefit systems, has distinct module names. Hence the `id(self)` in the module name.
module_name = '{}_{}_{}'.format(id(self), hash(os.path.abspath(file_path)), file_name)
module_name = f"{id(self)}_{hash(os.path.abspath(file_path))}_{file_name}"

module_directory = os.path.dirname(file_path)
try:
module = load_module(module_name, *find_module(file_name, [module_directory]))
spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
except NameError as e:
logging.error(str(e) + ": if this code used to work, this error might be due to a major change in OpenFisca-Core. Checkout the changelog to learn more: <https://github.com/openfisca/openfisca-core/blob/master/CHANGELOG.md>")
raise
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -41,7 +41,7 @@

setup(
name = 'OpenFisca-Core',
version = '35.7.4',
version = '35.7.5',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.org',
classifiers = [
Expand Down

0 comments on commit 9deaa60

Please sign in to comment.