Return relative or absolute path name, whichever is shortest. Parameters ---------- path : str or None cwd : str or None Returns ------- str Relative path or absolute path based on current working directory
(path, cwd=None)
| 109 | |
| 110 | |
| 111 | def short_path(path, cwd=None): |
| 112 | """ |
| 113 | Return relative or absolute path name, whichever is shortest. |
| 114 | |
| 115 | Parameters |
| 116 | ---------- |
| 117 | path : str or None |
| 118 | cwd : str or None |
| 119 | |
| 120 | Returns |
| 121 | ------- |
| 122 | str |
| 123 | Relative path or absolute path based on current working directory |
| 124 | """ |
| 125 | if not isinstance(path, str): |
| 126 | return path |
| 127 | if cwd is None: |
| 128 | cwd = os.getcwd() |
| 129 | abspath = os.path.abspath(path) |
| 130 | relpath = os.path.relpath(path, cwd) |
| 131 | if len(abspath) <= len(relpath): |
| 132 | return abspath |
| 133 | return relpath |
| 134 | |
| 135 | |
| 136 | def find_names(module, names_dict): |
no test coverage detected
searching dependent graphs…