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)
| 155 | |
| 156 | |
| 157 | def short_path(path, cwd=None): |
| 158 | """ |
| 159 | Return relative or absolute path name, whichever is shortest. |
| 160 | |
| 161 | Parameters |
| 162 | ---------- |
| 163 | path : str or None |
| 164 | cwd : str or None |
| 165 | |
| 166 | Returns |
| 167 | ------- |
| 168 | str |
| 169 | Relative path or absolute path based on current working directory |
| 170 | """ |
| 171 | if not isinstance(path, str): |
| 172 | return path |
| 173 | if cwd is None: |
| 174 | cwd = os.getcwd() |
| 175 | abspath = os.path.abspath(path) |
| 176 | relpath = os.path.relpath(path, cwd) |
| 177 | if len(abspath) <= len(relpath): |
| 178 | return abspath |
| 179 | return relpath |
| 180 | |
| 181 | |
| 182 | def find_names(module, names_dict): |
no test coverage detected