-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move _relative_to compatibility to a compat module.
- Loading branch information
Showing
2 changed files
with
27 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
import pathlib | ||
import sys | ||
import types | ||
|
||
|
||
def wrap(path): | ||
""" | ||
Workaround for https://github.com/python/cpython/issues/67271 where ".." | ||
isn't added by pathlib.Path.relative_to() when path is not | ||
a subpath of root. | ||
One example of such a package is dask-labextension, which uses | ||
jupyter-packaging to install JupyterLab javascript files outside | ||
of site-packages. | ||
""" | ||
|
||
def relative_to(root, *, walk_up=False): | ||
return pathlib.Path(os.path.relpath(path, root)) | ||
|
||
return types.SimpleNamespace(relative_to=relative_to) | ||
|
||
|
||
relative_fix = wrap if sys.version_info < (3, 9) else lambda x: x |