-
Notifications
You must be signed in to change notification settings - Fork 254
/
Copy pathvcs_dependency.py
128 lines (102 loc) · 3.03 KB
/
vcs_dependency.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from __future__ import annotations
from typing import Iterable
from poetry.core.packages.dependency import Dependency
class VCSDependency(Dependency):
"""
Represents a VCS dependency
"""
def __init__(
self,
name: str,
vcs: str,
source: str,
branch: str | None = None,
tag: str | None = None,
rev: str | None = None,
resolved_rev: str | None = None,
directory: str | None = None,
groups: Iterable[str] | None = None,
optional: bool = False,
develop: bool = False,
extras: Iterable[str] | None = None,
) -> None:
self._vcs = vcs
self._source = source
self._branch = branch
self._tag = tag
self._rev = rev
self._directory = directory
self._develop = develop
super().__init__(
name,
"*",
groups=groups,
optional=optional,
allows_prereleases=True,
source_type=self._vcs.lower(),
source_url=self._source,
source_reference=branch or tag or rev,
source_resolved_reference=resolved_rev,
source_subdirectory=directory,
extras=extras,
)
@property
def vcs(self) -> str:
return self._vcs
@property
def source(self) -> str:
return self._source
@property
def branch(self) -> str | None:
return self._branch
@property
def tag(self) -> str | None:
return self._tag
@property
def rev(self) -> str | None:
return self._rev
@property
def directory(self) -> str | None:
return self._directory
@property
def develop(self) -> bool:
return self._develop
@property
def reference(self) -> str:
reference = self._branch or self._tag or self._rev or ""
return reference
@property
def pretty_constraint(self) -> str:
if self._branch:
what = "branch"
version = self._branch
elif self._tag:
what = "tag"
version = self._tag
elif self._rev:
what = "rev"
version = self._rev
else:
return ""
return f"{what} {version}"
@property
def base_pep_508_name(self) -> str:
from poetry.core.vcs import git
requirement = self.pretty_name
parsed_url = git.ParsedUrl.parse(self._source)
if self.extras:
extras = ",".join(sorted(self.extras))
requirement += f"[{extras}]"
if parsed_url.protocol is not None:
requirement += f" @ {self._vcs}+{self._source}"
else:
requirement += f" @ {self._vcs}+ssh://{parsed_url.format()}"
if self.reference:
requirement += f"@{self.reference}"
if self._directory:
requirement += f"#subdirectory{self._directory}"
return requirement
def is_vcs(self) -> bool:
return True
def accepts_prereleases(self) -> bool:
return True