projects/aports·blob master · refs

138 lines · 5.5 KiB

1Patch-Source: https://github.com/fabric/fabric/commit/7fa309db9dd5dac69079c1fb83b6f579555f7d53
2--
3From 7fa309db9dd5dac69079c1fb83b6f579555f7d53 Mon Sep 17 00:00:00 2001
4From: Jeff Forcier <[email protected]>
5Date: Fri, 3 Apr 2026 15:40:03 -0400
6Subject: [PATCH] Update some classes to handle Invoke 3.x changes
7
8---
9 fabric/connection.py | 32 +++++++++++++++-----------------
10 fabric/tasks.py | 15 +++++++++------
11 2 files changed, 24 insertions(+), 23 deletions(-)
12
13diff --git a/fabric/connection.py b/fabric/connection.py
14index 4d4c49b75..83f44b02e 100644
15--- a/fabric/connection.py
16+++ b/fabric/connection.py
17@@ -1,20 +1,20 @@
18+import socket
19 from contextlib import contextmanager
20 from io import StringIO
21 from threading import Event
22-import socket
23
24 from decorator import decorator
25 from invoke import Context
26 from invoke.exceptions import ThreadException
27 from paramiko.agent import AgentRequestHandler
28-from paramiko.client import SSHClient, AutoAddPolicy
29+from paramiko.client import AutoAddPolicy, SSHClient
30 from paramiko.config import SSHConfig
31 from paramiko.proxy import ProxyCommand
32
33 from .config import Config
34 from .exceptions import InvalidV1Env
35 from .transfer import Transfer
36-from .tunnels import TunnelManager, Tunnel
37+from .tunnels import Tunnel, TunnelManager
38
39
40 @decorator
41@@ -217,6 +217,7 @@ def __init__(
42 connect_timeout=None,
43 connect_kwargs=None,
44 inline_ssh_env=None,
45+ remainder=None,
46 ):
47 """
48 Set up a new object representing a server connection.
49@@ -353,6 +354,12 @@ def __init__(
50 affects remote commands, and thus, methods like `.run` and
51 `.sudo`.
52
53+ :param str remainder:
54+ Mirrors the same parameter from `invoke.context.Context` - is a
55+ method of informing called tasks that the CLI parser saw an
56+ explicitly marked "don't parse me" segment of text. See
57+ :ref:`remainder`.
58+
59 :raises ValueError:
60 if user or port values are given via both ``host`` shorthand *and*
61 their own arguments. (We `refuse the temptation to guess`_).
62@@ -372,7 +379,7 @@ def __init__(
63 # NOTE: parent __init__ sets self._config; for now we simply overwrite
64 # that below. If it's somehow problematic we would want to break parent
65 # __init__ up in a manner that is more cleanly overrideable.
66- super().__init__(config=config)
67+ super().__init__(config=config, remainder=remainder)
68
69 #: The .Config object referenced when handling default values (for e.g.
70 #: user or port, when not explicitly given) or deciding how to behave.
71@@ -548,9 +555,7 @@ def __repr__(self):
72 if isinstance(self.gateway, str):
73 val = "proxycommand"
74 bits.append(("gw", val))
75- return "<Connection {}>".format(
76- " ".join("{}={}".format(*x) for x in bits)
77- )
78+ return "<Connection {}>".format(" ".join("{}={}".format(*x) for x in bits))
79
80 def _identity(self):
81 # TODO: consider including gateway and maybe even other init kwargs?
82@@ -622,10 +627,7 @@ def open(self):
83 if key in self.connect_kwargs:
84 raise ValueError(err.format(key))
85 # These may be given one way or the other, but not both
86- if (
87- "timeout" in self.connect_kwargs
88- and self.connect_timeout is not None
89- ):
90+ if "timeout" in self.connect_kwargs and self.connect_timeout is not None:
91 raise ValueError(err.format("timeout"))
92 # No conflicts -> merge 'em together
93 kwargs = dict(
94@@ -741,9 +743,7 @@ def create_session(self):
95 return channel
96
97 def _remote_runner(self):
98- return self.config.runners.remote(
99- context=self, inline_env=self.inline_ssh_env
100- )
101+ return self.config.runners.remote(context=self, inline_env=self.inline_ssh_env)
102
103 @opens
104 def run(self, command, **kwargs):
105@@ -1110,6 +1110,4 @@ def callback(channel, src_addr_tup, dst_addr_tup):
106 for tunnel in tunnels:
107 tunnel.finished.set()
108 tunnel.join()
109- self.transport.cancel_port_forward(
110- address=remote_host, port=remote_port
111- )
112+ self.transport.cancel_port_forward(address=remote_host, port=remote_port)
113diff --git a/fabric/tasks.py b/fabric/tasks.py
114index acf89d0cb..a93f5f7af 100644
115--- a/fabric/tasks.py
116+++ b/fabric/tasks.py
117@@ -101,12 +101,15 @@ def clone_kwargs(self):
118 kwargs["init_kwargs"] = self.init_kwargs
119 return kwargs
120
121- def make_context(self, config):
122- kwargs = self.init_kwargs
123- # TODO: what about corner case of a decorator giving config in a hosts
124- # kwarg member?! For now let's stomp on it, and then if somebody runs
125- # into it, we can identify the use case & decide how best to deal.
126- kwargs["config"] = config
127+ def make_context(self, config, core_parse_result):
128+ # TODO: updating this for Invoke 3 exposes that we probs need to add
129+ # another intermediary subroutine so we can phrase our logic as
130+ # "parent's context-making kwargs fed to our context subclass".
131+ # TODO: or does it make sense to fold this into init_kwargs? I don't
132+ # entirely recall why Fabric grew that but Invoke itself did not.
133+ kwargs = dict(
134+ self.init_kwargs, config=config, remainder=core_parse_result.remainder
135+ )
136 return Connection(**kwargs)
137
138 def __repr__(self):