File tree Expand file tree Collapse file tree 2 files changed +27
-20
lines changed
Expand file tree Collapse file tree 2 files changed +27
-20
lines changed Original file line number Diff line number Diff line change 1919import posixpath
2020import collections
2121
22+ from .compat .py38 import relative_fix
2223from . import _adapters , _meta , _py39compat
2324from ._collections import FreezableDefaultDict , Pair
2425from ._compat import (
@@ -562,31 +563,14 @@ def _read_files_egginfo_installed(self):
562563 if not text or not subdir :
563564 return
564565
565- site_path = self .locate_file ('' ).resolve ()
566566 paths = (
567- self ._relative_to (
568- (subdir / name ).resolve (),
569- site_path ,
570- ).as_posix ()
567+ relative_fix ((subdir / name ).resolve ())
568+ .relative_to (self .locate_file ('' ).resolve (), walk_up = True )
569+ .as_posix ()
571570 for name in text .splitlines ()
572571 )
573572 return map ('"{}"' .format , paths )
574573
575- def _relative_to (self , path , root ):
576- """
577- Workaround for https://github.com/python/cpython/issues/67271 where ".."
578- isn't added by pathlib.Path.relative_to() when path is not
579- a subpath of root.
580-
581- One example of such a package is dask-labextension, which uses
582- jupyter-packaging to install JupyterLab javascript files outside
583- of site-packages.
584- """
585- try :
586- return path .relative_to (root )
587- except ValueError :
588- return pathlib .Path (os .path .relpath (path , root ))
589-
590574 def _read_files_egginfo_sources (self ):
591575 """
592576 Read SOURCES.txt and return lines in a similar CSV-parsable
Original file line number Diff line number Diff line change 1+ import os
2+ import pathlib
3+ import sys
4+ import types
5+
6+
7+ def wrap (path ):
8+ """
9+ Workaround for https://github.com/python/cpython/issues/67271 where ".."
10+ isn't added by pathlib.Path.relative_to() when path is not
11+ a subpath of root.
12+ One example of such a package is dask-labextension, which uses
13+ jupyter-packaging to install JupyterLab javascript files outside
14+ of site-packages.
15+ """
16+
17+ def relative_to (root , * , walk_up = False ):
18+ return pathlib .Path (os .path .relpath (path , root ))
19+
20+ return types .SimpleNamespace (relative_to = relative_to )
21+
22+
23+ relative_fix = wrap if sys .version_info < (3 , 9 ) else lambda x : x
You can’t perform that action at this time.
0 commit comments