Skip to content

Commit dc70773

Browse files
rod7760Fizzadar
authored andcommitted
Replace inst_vers_template with inst_vers_format_fn
1 parent f44cec7 commit dc70773

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/pyinfra/operations/util/packaging.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
from pyinfra.operations import files
1616

1717

18+
def default_inst_vers_format_fn(name: str, operator: str, version: str):
19+
return "{name}{operator}{version}".format(name=name, operator=operator, version=version)
20+
21+
1822
class PkgInfo(NamedTuple):
1923
name: str
2024
version: str
2125
operator: str
2226
url: str
23-
inst_vers_template: str = "{name}{operator}{version}"
27+
inst_vers_format_fn: Callable = default_inst_vers_format_fn
2428
"""
2529
The key packaging information needed: version, operator and url are optional.
2630
"""
@@ -38,7 +42,7 @@ def inst_vers(self) -> str:
3842
"""String that represents how a program can be installed.
3943
4044
- If self.url exists, then url is always returned.
41-
- If self.version exists, then inst_vers_template is used
45+
- If self.version exists, then inst_vers_format_fn is used
4246
to create the string. The default template is '{name}{operator}{version}'.
4347
- Otherwise, self.name is returned.
4448
@@ -49,12 +53,7 @@ def inst_vers(self) -> str:
4953
return shlex.quote(self.url)
5054

5155
if self.version:
52-
# assumes if version exists, then name and operator do
53-
return self.inst_vers_template.format(
54-
name=shlex.quote(self.name),
55-
operator=shlex.quote(self.operator),
56-
version=shlex.quote(self.version),
57-
)
56+
return shlex.quote(self.inst_vers_format_fn(self.name, self.operator, self.version))
5857
return shlex.quote(self.name)
5958

6059
@classmethod

0 commit comments

Comments
 (0)