MCPcopy Index your code
hub / github.com/RustPython/RustPython / _get_revised_path

Function _get_revised_path

Lib/pydoc.py:2762–2786  ·  view source on GitHub ↗

Ensures current directory is on returned path, and argv0 directory is not Exception: argv0 dir is left alone if it's also pydoc's directory. Returns a new path entry list, or None if no adjustment is needed.

(given_path, argv0)

Source from the content-addressed store, hash-verified

2760 return isinstance(x, str) and x.find(os.sep) >= 0
2761
2762def _get_revised_path(given_path, argv0):
2763 """Ensures current directory is on returned path, and argv0 directory is not
2764
2765 Exception: argv0 dir is left alone if it's also pydoc's directory.
2766
2767 Returns a new path entry list, or None if no adjustment is needed.
2768 """
2769 # Scripts may get the current directory in their path by default if they're
2770 # run with the -m switch, or directly from the current directory.
2771 # The interactive prompt also allows imports from the current directory.
2772
2773 # Accordingly, if the current directory is already present, don't make
2774 # any changes to the given_path
2775 if '' in given_path or os.curdir in given_path or os.getcwd() in given_path:
2776 return None
2777
2778 # Otherwise, add the current directory to the given path, and remove the
2779 # script directory (as long as the latter isn't also pydoc's directory.
2780 stdlib_dir = os.path.dirname(__file__)
2781 script_dir = os.path.dirname(argv0)
2782 revised_path = given_path.copy()
2783 if script_dir in given_path and not os.path.samefile(script_dir, stdlib_dir):
2784 revised_path.remove(script_dir)
2785 revised_path.insert(0, os.getcwd())
2786 return revised_path
2787
2788
2789# Note: the tests only cover _get_revised_path, not _adjust_cli_path itself

Calls 4

samefileMethod · 0.80
copyMethod · 0.45
removeMethod · 0.45
insertMethod · 0.45