Afaik there's no way to do from future imports with the c api, and executing the statement with RunOneLine doesn't do it either, it has to be in the script because it's treated specially by the interpreter.<br><br>There might be a way to do it with some tricks that I didn't figure out last time.<br><br>If its any consolation, it would only be needed for shared/builtin formatters.  <br><br>I guess it would help to get a better understanding of what the problem is, if someone files a bug against me (or i can file it myself tomorrow) i can investigate after I finish PDB stuff.  <br><br>In the meantime having it in seems like the best option imo<br><div class="gmail_quote"><div dir="ltr">On Tue, Apr 5, 2016 at 5:54 PM Jim Ingham <<a href="mailto:jingham@apple.com">jingham@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Will this be necessary for everybody who uses "command script import" with Python 3?  If so, it would be really nice to do this work in "command script import" if possible.  Otherwise everybody will have to put this goo at the top of every .py file they write for formatters & breakpoint commands and the like.<br>
<br>
Jim<br>
<br>
<br>
> On Apr 5, 2016, at 5:30 PM, Zachary Turner via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Yea I wasn't sure if the . would be necessary or not.  If you write "from __future__ import absolute_import" at the top of each of these python files (foo.py and foo2.py or whatever they're called) then this should guarantee that the behavior is the same in both Python 2 and Python 3<br>
><br>
> On Tue, Apr 5, 2016 at 4:01 PM Adrian McCarthy <<a href="mailto:amccarth@google.com" target="_blank">amccarth@google.com</a>> wrote:<br>
> "error: module importing failed: Parent module '' not loaded, cannot perform relative import"<br>
><br>
> If you omit the dot (i.e., `from foo import foo2`), it appears to work, but I'm not sure that does the right thing.  I'll keep investigating.<br>
><br>
> On Tue, Apr 5, 2016 at 3:40 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
> Without the modification to sys.path<br>
><br>
> On Tue, Apr 5, 2016 at 3:39 PM Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
> Can you try to change "import foo2" to "from .foo import foo2"<br>
> On Tue, Apr 5, 2016 at 2:52 PM Adrian McCarthy <<a href="mailto:amccarth@google.com" target="_blank">amccarth@google.com</a>> wrote:<br>
> I've drilled down into the Python import statement.  It's in ScriptInterpreterPython::LoadScriptingModule.  The function inserts the diretory into sys.path and then issues a vanilla Python import statement.<br>
><br>
> I spoke with one of our local Python experts who said that this technique to specify the directory is probably unreliable, as the rules for where Python looks for modules has evolved.  The rules for both relative and absolute module paths changed from Python 2 to 3.<br>
><br>
> I'll revert the xfail if you want.  But this has been broken for quite a while (as has another test, which I'm looking into now).<br>
><br>
> On Tue, Apr 5, 2016 at 2:29 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
> I think we need some more information before we xfail this. It would help to drill down to either the python import statement or the PyImport_ImportModule C api call that actually does the import.<br>
><br>
> If you can get that, i can help come up with a fix. Just need to step through the execution of the command until you get to the python or c code that tries to do the import<br>
><br>
> On Tue, Apr 5, 2016 at 1:54 PM Adrian McCarthy via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br>
> Author: amccarth<br>
> Date: Tue Apr  5 15:49:09 2016<br>
> New Revision: 265461<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=265461&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=265461&view=rev</a><br>
> Log:<br>
> XFail TestImport.py on Windows because Python 3 import rules don't work that way.<br>
><br>
> Modified:<br>
>     lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py<br>
><br>
> Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py?rev=265461&r1=265460&r2=265461&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py?rev=265461&r1=265460&r2=265461&view=diff</a><br>
> ==============================================================================<br>
> --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py (original)<br>
> +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script/import/TestImport.py Tue Apr  5 15:49:09 2016<br>
> @@ -16,6 +16,7 @@ class ImportTestCase(TestBase):<br>
><br>
>      @add_test_categories(['pyapi'])<br>
>      @no_debug_info_test<br>
> +    @expectedFailureAll(oslist=["windows"], bugnumber="<a href="http://llvm.org/pr27227" rel="noreferrer" target="_blank">llvm.org/pr27227</a>: Python 3 import rules are different")<br>
>      def test_import_command(self):<br>
>          """Import some Python scripts by path and test them"""<br>
>          self.run_test()<br>
><br>
><br>
> _______________________________________________<br>
> lldb-commits mailing list<br>
> <a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
><br>
><br>
> _______________________________________________<br>
> lldb-commits mailing list<br>
> <a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
<br>
</blockquote></div>