5from typing
import Any, Dict, Iterable, Optional, Type, TypeVar, Union
9 "DirectUrlValidationError",
17DIRECT_URL_METADATA_NAME =
"direct_url.json"
18ENV_VAR_RE =
re.compile(
r"^\$\{[A-Za-z0-9-_]+\}(:\$\{[A-Za-z0-9-_]+\})?$")
26 d: Dict[str, Any], expected_type: Type[T], key: str, default: Optional[T] =
None
28 """Get value from dictionary and verify expected type."""
33 raise DirectUrlValidationError(
34 "{!r} has unexpected type for {} (expected {})".format(
35 value, key, expected_type
42 d: Dict[str, Any], expected_type: Type[T], key: str, default: Optional[T] =
None
44 value =
_get(d, expected_type, key, default)
51 infos = [info
for info
in infos
if info
is not None]
54 "missing one of archive_info, dir_info, vcs_info"
58 "more than one of archive_info, dir_info, vcs_info"
60 assert infos[0]
is not None
65 """Make dict excluding None values."""
66 return {k: v
for k, v
in kwargs.items()
if v
is not None}
76 requested_revision: Optional[str] =
None,
83 def _from_dict(cls, d: Optional[Dict[str, Any]]) -> Optional[
"VcsInfo"]:
89 requested_revision=
_get(d, str,
"requested_revision"),
101 name =
"archive_info"
105 hash: Optional[str] =
None,
106 hashes: Optional[Dict[str, str]] =
None,
113 def hash(self) -> Optional[str]:
117 def hash(self, value: Optional[str]) ->
None:
118 if value
is not None:
125 f
"invalid archive_info.hash format: {value!r}"
128 self.
hashes = {hash_name: hash_value}
129 elif hash_name
not in self.
hashes:
131 self.
hashes[hash_name] = hash_value
135 def _from_dict(cls, d: Optional[Dict[str, Any]]) -> Optional[
"ArchiveInfo"]:
138 return cls(hash=
_get(d, str,
"hash"), hashes=
_get(d, dict,
"hashes"))
149 editable: bool =
False,
154 def _from_dict(cls, d: Optional[Dict[str, Any]]) -> Optional[
"DirInfo"]:
163InfoType = Union[ArchiveInfo, DirInfo, VcsInfo]
171 subdirectory: Optional[str] =
None,
178 if "@" not in netloc:
183 and self.
info.vcs ==
"git"
184 and user_pass ==
"git"
189 return netloc_no_user_pass
193 """url with user:password part removed unless it is formed with
194 environment variables as specified in PEP 610, or it is ``git``
195 in the case of a git URL.
211 subdirectory=
_get(d, str,
"subdirectory"),
226 res[self.
info.name] = self.
info._to_dict()
None hash(self, Optional[str] value)
Dict[str, Any] _to_dict(self)
Optional["ArchiveInfo"] _from_dict(cls, Optional[Dict[str, Any]] d)
None __init__(self, Optional[str] hash=None, Optional[Dict[str, str]] hashes=None)
None __init__(self, bool editable=False)
Optional["DirInfo"] _from_dict(cls, Optional[Dict[str, Any]] d)
Dict[str, Any] _to_dict(self)
None __init__(self, str url, InfoType info, Optional[str] subdirectory=None)
str _remove_auth_from_netloc(self, str netloc)
bool is_local_editable(self)
Dict[str, Any] to_dict(self)
"DirectUrl" from_dict(cls, Dict[str, Any] d)
"DirectUrl" from_json(cls, str s)
Dict[str, Any] _to_dict(self)
None __init__(self, str vcs, str commit_id, Optional[str] requested_revision=None)
Optional["VcsInfo"] _from_dict(cls, Optional[Dict[str, Any]] d)
Dict[str, Any] _filter_none(**Any kwargs)
T _get_required(Dict[str, Any] d, Type[T] expected_type, str key, Optional[T] default=None)
Optional[T] _get(Dict[str, Any] d, Type[T] expected_type, str key, Optional[T] default=None)
"InfoType" _exactly_one_of(Iterable[Optional["InfoType"]] infos)