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)
| 2712 | return isinstance(x, str) and x.find(os.sep) >= 0 |
| 2713 | |
| 2714 | def _get_revised_path(given_path, argv0): |
| 2715 | """Ensures current directory is on returned path, and argv0 directory is not |
| 2716 | |
| 2717 | Exception: argv0 dir is left alone if it's also pydoc's directory. |
| 2718 | |
| 2719 | Returns a new path entry list, or None if no adjustment is needed. |
| 2720 | """ |
| 2721 | # Scripts may get the current directory in their path by default if they're |
| 2722 | # run with the -m switch, or directly from the current directory. |
| 2723 | # The interactive prompt also allows imports from the current directory. |
| 2724 | |
| 2725 | # Accordingly, if the current directory is already present, don't make |
| 2726 | # any changes to the given_path |
| 2727 | if '' in given_path or os.curdir in given_path or os.getcwd() in given_path: |
| 2728 | return None |
| 2729 | |
| 2730 | # Otherwise, add the current directory to the given path, and remove the |
| 2731 | # script directory (as long as the latter isn't also pydoc's directory. |
| 2732 | stdlib_dir = os.path.dirname(__file__) |
| 2733 | script_dir = os.path.dirname(argv0) |
| 2734 | revised_path = given_path.copy() |
| 2735 | if script_dir in given_path and not os.path.samefile(script_dir, stdlib_dir): |
| 2736 | revised_path.remove(script_dir) |
| 2737 | revised_path.insert(0, os.getcwd()) |
| 2738 | return revised_path |
| 2739 | |
| 2740 | |
| 2741 | # Note: the tests only cover _get_revised_path, not _adjust_cli_path itself |
searching dependent graphs…