##// END OF EJS Templates
Merge pull request #13559 from bucknerns/fix_path_loop_with_tests...
Matthias Bussonnier -
r27576:da607ae8 merge
parent child Browse files
Show More
@@ -758,6 +758,33 b' class InteractiveShell(SingletonConfigurable):'
758 # the appropriate time.
758 # the appropriate time.
759 self.display_trap = DisplayTrap(hook=self.displayhook)
759 self.display_trap = DisplayTrap(hook=self.displayhook)
760
760
761 @staticmethod
762 def get_path_links(p: Path):
763 """Gets path links including all symlinks
764
765 Examples
766 --------
767 In [1]: from IPython.core.interactiveshell import InteractiveShell
768
769 In [2]: import sys, pathlib
770
771 In [3]: paths = InteractiveShell.get_path_links(pathlib.Path(sys.executable))
772
773 In [4]: len(paths) == len(set(paths))
774 Out[4]: True
775
776 In [5]: bool(paths)
777 Out[5]: True
778 """
779 paths = [p]
780 while p.is_symlink():
781 new_path = Path(os.readlink(p))
782 if not new_path.is_absolute():
783 new_path = p.parent / new_path
784 p = new_path
785 paths.append(p)
786 return paths
787
761 def init_virtualenv(self):
788 def init_virtualenv(self):
762 """Add the current virtualenv to sys.path so the user can import modules from it.
789 """Add the current virtualenv to sys.path so the user can import modules from it.
763 This isn't perfect: it doesn't use the Python interpreter with which the
790 This isn't perfect: it doesn't use the Python interpreter with which the
@@ -783,10 +810,7 b' class InteractiveShell(SingletonConfigurable):'
783 # stdlib venv may symlink sys.executable, so we can't use realpath.
810 # stdlib venv may symlink sys.executable, so we can't use realpath.
784 # but others can symlink *to* the venv Python, so we can't just use sys.executable.
811 # but others can symlink *to* the venv Python, so we can't just use sys.executable.
785 # So we just check every item in the symlink tree (generally <= 3)
812 # So we just check every item in the symlink tree (generally <= 3)
786 paths = [p]
813 paths = self.get_path_links(p)
787 while p.is_symlink():
788 p = Path(os.readlink(p))
789 paths.append(p.resolve())
790
814
791 # In Cygwin paths like "c:\..." and '\cygdrive\c\...' are possible
815 # In Cygwin paths like "c:\..." and '\cygdrive\c\...' are possible
792 if p_venv.parts[1] == "cygdrive":
816 if p_venv.parts[1] == "cygdrive":
General Comments 0
You need to be logged in to leave comments. Login now