[Lldb-commits] [PATCH] D89295: [lldb] Add /Users/jonas to Python's sys.path

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 13 09:23:10 PDT 2020


JDevlieghere added a comment.

In D89295#2327905 <https://reviews.llvm.org/D89295#2327905>, @labath wrote:

> In D89295#2327767 <https://reviews.llvm.org/D89295#2327767>, @teemperor wrote:
>
>> In D89295#2327751 <https://reviews.llvm.org/D89295#2327751>, @kastiglione wrote:
>>
>>> For lldbinit files, and any file that gets `command source`'d, I think it would be useful if they could perform `command script import some/path/to/command.py`, where `some` is resolved relative to the dirname of the lldb file. For example, given an lldbinit file at `my/project/scripts/project.lldb`, it could load a python at `my/project/scripts/commands/my.py` by running `command script import commands/my.py`.
>>
>> +1, I think that would be useful. Not sure about the right way to implement this though (and whether we should make this implicit a relative path vs for example some kind of placeholder 'variable' or something like that).
>
> That would be kind of useful, but the thing which worries me about that is the sys.path packing it will cause. I don't think that sys.path modification should be taken lightly, as every new entry there creates an opportunity for creating ambiguous imports (being able to import one file through several paths). And a lot of "interesting" things can happen when a python module gets imported through multiple paths. I think it's bad enough that every "command script import" adds a new sys.path entry. I wouldn't want "command source" to do the same...

The way I started implementing it is that the CommandInterpreter keeps a stack of `FileSpec`s and when you do `command script import` it asks the current interpreter for the current one and passes it along. So rather than always adding a new sys.path entry when sourcing a file, we continue to insert two sys.path entries when doing a `command script import` when sourcing and still one otherwise. Does that sound like a reasonable compromise?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89295/new/

https://reviews.llvm.org/D89295



More information about the lldb-commits mailing list