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
fixing module.__file__ is None in py3 #4669
fixing module.__file__ is None in py3 #4669
Conversation
conans/client/loader.py
Outdated
try: | ||
folder = os.path.dirname(module.__file__) | ||
except (AttributeError, TypeError): # Namespace packages py3 module.__file__ | ||
folder = module.__path__._path[0] | ||
except AttributeError: # some module doesn't have __file__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this except is for the module.__path__._path[0]
? The comment is not very clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR solves the problem reported by the user, but it is also introducing a test I do not agree with: test_helpers_python_library
.
That test requires a sys.path.append(temp)
to work, and it won't be a real use case of any recipe file. That use-case makes sense with a python module installed in the system, and I'm not sure about those global/static variables inside a library, maybe the logging
package is the only one library with global state (and in that case, following the philosophy of Conan, we should promote the self.output
in the recipe or even the conans.utils.log.logger
, which in fact is shared among all recipes).
Nevertheless I agree with this PR, it fixes an issue, but I think we should have a look to some other corner cases proposed in #4664.
That is valid and currently used by companies. Pure python. About the global state, not so important but indeed a performance issue. |
Yes, it is a valid use case, @lasote, but there are two things that are incompatible when loading dynamically python files:
I think that both use cases are licit, but if I have to choose, I prefer reproducibility and consistency over sharing a global variable (and being afraid of not being using the one I pretended to use). |
The The problem comes with modules that do not belong to recipes, like globally installed python libraries. These cannot be put under |
Yes, this PR is implementing that behavior too, you are true, it is doing the same I was proposing in #4664 and #4641 (plus the global thing). Great! 👍 |
Changelog: Bugfix: Solve problem with loading recipe python files in Python 3.7 because of
module.__file__ = None
Docs: omit
closes #4636
close #4641
@PYVERS: Macos@py27, Windows@py36, Linux@py27, py34