mirror of
https://github.com/python/cpython.git
synced 2025-11-01 14:11:41 +00:00
gh-113174: Sync with importlib_metadata 7.0 (#113175)
* Sync with importlib_metadata 7.0.0 * Add blurb * Update docs to reflect changes. * Link datamodel docs for object.__getitem__ Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> * Add what's new for removed __getattr__ * Link datamodel docs for object.__getitem__ Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> * Add exclamation point, as that seems to be used for other classes. --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
6b70c3dc5a
commit
2d91409c69
10 changed files with 267 additions and 146 deletions
|
|
@ -1,17 +1,18 @@
|
|||
# from jaraco.path 3.5
|
||||
# from jaraco.path 3.7
|
||||
|
||||
import functools
|
||||
import pathlib
|
||||
from typing import Dict, Union
|
||||
|
||||
try:
|
||||
from typing import Protocol, runtime_checkable
|
||||
except ImportError: # pragma: no cover
|
||||
# Python 3.7
|
||||
from typing_extensions import Protocol, runtime_checkable # type: ignore
|
||||
from typing import Dict, Protocol, Union
|
||||
from typing import runtime_checkable
|
||||
|
||||
|
||||
FilesSpec = Dict[str, Union[str, bytes, 'FilesSpec']] # type: ignore
|
||||
class Symlink(str):
|
||||
"""
|
||||
A string indicating the target of a symlink.
|
||||
"""
|
||||
|
||||
|
||||
FilesSpec = Dict[str, Union[str, bytes, Symlink, 'FilesSpec']] # type: ignore
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
|
|
@ -28,6 +29,9 @@ def write_text(self, content, **kwargs):
|
|||
def write_bytes(self, content):
|
||||
... # pragma: no cover
|
||||
|
||||
def symlink_to(self, target):
|
||||
... # pragma: no cover
|
||||
|
||||
|
||||
def _ensure_tree_maker(obj: Union[str, TreeMaker]) -> TreeMaker:
|
||||
return obj if isinstance(obj, TreeMaker) else pathlib.Path(obj) # type: ignore
|
||||
|
|
@ -51,12 +55,16 @@ def build(
|
|||
... "__init__.py": "",
|
||||
... },
|
||||
... "baz.py": "# Some code",
|
||||
... }
|
||||
... "bar.py": Symlink("baz.py"),
|
||||
... },
|
||||
... "bing": Symlink("foo"),
|
||||
... }
|
||||
>>> target = getfixture('tmp_path')
|
||||
>>> build(spec, target)
|
||||
>>> target.joinpath('foo/baz.py').read_text(encoding='utf-8')
|
||||
'# Some code'
|
||||
>>> target.joinpath('bing/bar.py').read_text(encoding='utf-8')
|
||||
'# Some code'
|
||||
"""
|
||||
for name, contents in spec.items():
|
||||
create(contents, _ensure_tree_maker(prefix) / name)
|
||||
|
|
@ -79,8 +87,8 @@ def _(content: str, path):
|
|||
|
||||
|
||||
@create.register
|
||||
def _(content: str, path):
|
||||
path.write_text(content, encoding='utf-8')
|
||||
def _(content: Symlink, path):
|
||||
path.symlink_to(content)
|
||||
|
||||
|
||||
class Recording:
|
||||
|
|
@ -107,3 +115,6 @@ def write_text(self, content, **kwargs):
|
|||
|
||||
def mkdir(self, **kwargs):
|
||||
return
|
||||
|
||||
def symlink_to(self, target):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue