D8352: extensions: don't crash if __file__ not defined

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

D8352: extensions: don't crash if __file__ not defined

valentin.gatienbaron (Valentin Gatien-Baron)
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This attribute isn't present in PyOxidizer when loading modules
  from memory.
 
  Before, this code was crashing under PyOxidizer. After, it simply
  yields unexpected results. This still isn't great (we need a better
  mechanism to discover extensions when modules aren't loaded from
  the filesystem). But it is strictly better since we no longer
  get tracebacks.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8352

AFFECTED FILES
  mercurial/extensions.py

CHANGE DETAILS

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -706,6 +706,10 @@
     '''find paths of disabled extensions. returns a dict of {name: path}'''
     import hgext
 
+    # __file__ not always present.
+    if not util.safehasattr(hgext, "__file__"):
+        return {}
+
     extpath = os.path.dirname(
         os.path.abspath(pycompat.fsencode(hgext.__file__))
     )



To: indygreg, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

D8352: extensions: don't crash if __file__ not defined

valentin.gatienbaron (Valentin Gatien-Baron)
This revision now requires changes to proceed.
marmoute added inline comments.
marmoute requested changes to this revision.

INLINE COMMENTS

> extensions.py:709
>  
> +    # __file__ not always present.
> +    if not util.safehasattr(hgext, "__file__"):

Maybe mention that the result if "wrong" here? If I understand you commit message fine, this change does not make this code work as expected. It only prevent a crash. If I got this right, it would be useful to mention it in the comment.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8352/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8352

To: indygreg, #hg-reviewers, marmoute
Cc: marmoute, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel