py311.py 608 B

12345678910111213141516171819202122
  1. import os
  2. import pathlib
  3. import sys
  4. import types
  5. def wrap(path): # pragma: no cover
  6. """
  7. Workaround for https://github.com/python/cpython/issues/84538
  8. to add backward compatibility for walk_up=True.
  9. An example affected package is dask-labextension, which uses
  10. jupyter-packaging to install JupyterLab javascript files outside
  11. of site-packages.
  12. """
  13. def relative_to(root, *, walk_up=False):
  14. return pathlib.Path(os.path.relpath(path, root))
  15. return types.SimpleNamespace(relative_to=relative_to)
  16. relative_fix = wrap if sys.version_info < (3, 12) else lambda x: x