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)
| 2808 | return isinstance(x, str) and x.find(os.sep) >= 0 |
| 2809 | |
| 2810 | def _get_revised_path(given_path, argv0): |
| 2811 | """Ensures current directory is on returned path, and argv0 directory is not |
| 2812 | |
| 2813 | Exception: argv0 dir is left alone if it's also pydoc's directory. |
| 2814 | |
| 2815 | Returns a new path entry list, or None if no adjustment is needed. |
| 2816 | """ |
| 2817 | # Scripts may get the current directory in their path by default if they're |
| 2818 | # run with the -m switch, or directly from the current directory. |
| 2819 | # The interactive prompt also allows imports from the current directory. |
| 2820 | |
| 2821 | # Accordingly, if the current directory is already present, don't make |
| 2822 | # any changes to the given_path |
| 2823 | if '' in given_path or os.curdir in given_path or os.getcwd() in given_path: |
| 2824 | return None |
| 2825 | |
| 2826 | # Otherwise, add the current directory to the given path, and remove the |
| 2827 | # script directory (as long as the latter isn't also pydoc's directory. |
| 2828 | stdlib_dir = os.path.dirname(__file__) |
| 2829 | script_dir = os.path.dirname(argv0) |
| 2830 | revised_path = given_path.copy() |
| 2831 | if script_dir in given_path and not os.path.samefile(script_dir, stdlib_dir): |
| 2832 | revised_path.remove(script_dir) |
| 2833 | revised_path.insert(0, os.getcwd()) |
| 2834 | return revised_path |
| 2835 | |
| 2836 | |
| 2837 | # Note: the tests only cover _get_revised_path, not _adjust_cli_path itself |
no test coverage detected