Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multiple extensions with similar file names #11

Closed
guillett opened this issue Apr 12, 2018 · 1 comment
Closed

Using multiple extensions with similar file names #11

guillett opened this issue Apr 12, 2018 · 1 comment

Comments

@guillett
Copy link
Member

guillett commented Apr 12, 2018

Last week, I was in France countryside and I pair-programmed to code a local benefit.

I did not manage to show our product with all the extensions activated because I had an exception when loading the French tax benefit system.

To demo the issue, I created guillett/test_openfisca_extensions.

I managed to investigate the issue today and I think I found the culprit line.

openfisca_core/taxbenefitsystems.py:152

    def add_variables_from_file(self, file_path):
        """
        Adds all OpenFisca variables contained in a given file to the tax and benefit system.
        """
        try:
            file_name = path.splitext(path.basename(file_path))[0]
            module_name = '{}_{}'.format(id(self), file_name)  # If two tax and benefit systems load the same module, the second one should not replace the first one. Hence this unique module name.
            module_directory = path.dirname(file_path)
            try:
                module = load_module(module_name, *find_module(file_name, [module_directory]))
            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
            potential_variables = [getattr(module, item) for item in dir(module) if not item.startswith('__')]
            for pot_variable in potential_variables:
                # We only want to get the module classes defined in this module (not imported)
                if isclass(pot_variable) and \
                        issubclass(pot_variable, Variable) and \
                        pot_variable.__module__.endswith(module_name): #   <----------- THIS LINE HERE
                    self.add_variable(pot_variable)
        except:
            log.error(u'Unable to load OpenFisca variables from file "{}"'.format(file_path))
raise

pot_variable.__module__.endswith(module_name)

If two modules have the same names (ie. two files) that will fail.

I managed to replicate this issue with less complexity (ie. only with the country-template package).

Edit: Two enters instead of one…

@guillett
Copy link
Member Author

Superseeded by openfisca/openfisca-core#642.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant