Skip to content

Commit f97d954

Browse files
committed
pep257 for session
1 parent 90f34a7 commit f97d954

File tree

1 file changed

+41
-43
lines changed

1 file changed

+41
-43
lines changed

tmuxp/session.py

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222

2323
class Session(util.TmuxMappingObject, util.TmuxRelationalObject):
2424

25-
'''
26-
``tmux(1) session``.
25+
""":ref:`tmux(1)` session.
2726
2827
Holds :class:`Window` objects.
2928
30-
'''
29+
"""
3130

3231
childIdAttribute = 'window_id'
3332

@@ -74,7 +73,7 @@ def tmux(self, *args, **kwargs):
7473
return self.server.tmux(*args, **kwargs)
7574

7675
def attach_session(self, target_session=None):
77-
""" Return ``$ tmux attach-session`` aka alias: ``$ tmux attach``.
76+
"""Return ``$ tmux attach-session`` aka alias: ``$ tmux attach``.
7877
7978
:param: target_session: str. name of the session. fnmatch(3) works.
8079
@@ -85,33 +84,33 @@ def attach_session(self, target_session=None):
8584
raise Exception(proc.stderr)
8685

8786
def kill_session(self):
88-
'''
89-
``$ tmux kill-session``
87+
"""``$ tmux kill-session``."""
9088

91-
'''
9289
proc = self.tmux('kill-session', '-t%s' % self.get('session_id'))
9390

9491
if proc.stderr:
9592
raise Exception(proc.stderr)
9693

9794
def switch_client(self, target_session=None):
98-
'''
99-
``$ tmux kill-session``
95+
"""``$ tmux kill-session``.
10096
10197
:param: target_session: str. note this accepts fnmatch(3). 'asdf' will
10298
kill asdfasd
103-
'''
99+
100+
"""
104101
proc = self.tmux('switch-client', '-t%s' % self.get('session_id'))
105102

106103
if proc.stderr:
107104
raise Exception(proc.stderr)
108105

109106
def rename_session(self, new_name):
110-
'''rename session and return new :class:`Session` object
107+
"""Rename session and return new :class:`Session` object.
111108
112109
:param rename_session: new session name
113110
:type rename_session: string
114-
'''
111+
:rtype: :class:`Session`
112+
113+
"""
115114
new_name = pipes.quote(new_name)
116115
proc = self.tmux(
117116
'rename-session',
@@ -128,8 +127,7 @@ def new_window(self,
128127
window_name=None,
129128
start_directory=None,
130129
attach=True):
131-
'''
132-
``$ tmux new-window``
130+
"""Return :class:`Window` from ``$ tmux new-window``.
133131
134132
.. note::
135133
@@ -149,7 +147,9 @@ def new_window(self,
149147
:param attach: make new window the current window after creating it,
150148
default True.
151149
:param type: bool
152-
'''
150+
:rtype: :class:`Window`
151+
152+
"""
153153

154154
wformats = ['session_name', 'session_id'] + formats.WINDOW_FORMATS
155155
tmux_formats = ['#{%s}' % f for f in wformats]
@@ -197,15 +197,15 @@ def new_window(self,
197197
return window
198198

199199
def kill_window(self, target_window=None):
200-
'''
201-
``$ tmux kill-window``
200+
"""``$ tmux kill-window``.
202201
203202
Kill the current window or the window at ``target-window``. removing it
204203
from any sessions to which it is linked.
205204
206205
:param target_window: the ``target window``.
207206
:type target_window: string
208-
'''
207+
208+
"""
209209

210210
tmux_args = list()
211211

@@ -236,11 +236,11 @@ def _windows(self):
236236
return self._list_windows()
237237

238238
def list_windows(self):
239-
'''
240-
Return a list of :class:`Window` from the ``tmux(1)`` session.
239+
"""Return a list of :class:`Window` from the ``tmux(1)`` session.
241240
242241
:rtype: :class:`Window`
243-
'''
242+
243+
"""
244244
windows = [
245245
w for w in self._windows if w['session_id'] == self._session_id
246246
]
@@ -253,9 +253,11 @@ def windows(self):
253253
children = windows
254254

255255
def attached_window(self):
256-
'''
257-
Returns active :class:`Window` object.
258-
'''
256+
"""Returns active :class:`Window` object.
257+
258+
:rtype: :class:`Window`
259+
260+
"""
259261
active_windows = []
260262
for window in self._windows:
261263
if 'window_active' in window:
@@ -275,17 +277,16 @@ def attached_window(self):
275277
raise Exception('No Windows')
276278

277279
def select_window(self, target_window):
278-
'''
279-
``$ tmux select-window``
280+
""" Returns :class:`Window` selected via ``$ tmux select-window``.
280281
281282
:param: window: ``target_window`` also 'last-window' (``-l``),
282283
'next-window' (``-n``), or 'previous-window' (``-p``)
283284
:type window: integer
285+
:rtype: :class:`Window`
284286
285-
Returns the attached :class:`Window`.
287+
:todo: assure ``-l``, ``-n``, ``-p`` work.
286288
287-
Todo: assure ``-l``, ``-n``, ``-p`` work.
288-
'''
289+
"""
289290

290291
target = '-t%s' % target_window
291292

@@ -297,24 +298,21 @@ def select_window(self, target_window):
297298
return self.attached_window()
298299

299300
def attached_pane(self):
300-
'''
301-
Returns active :class:`Pane` object
302-
'''
301+
"""Return active :class:`Pane` object."""
302+
303303
return self.attached_window().attached_pane()
304304

305305
def set_option(self, option, value):
306-
'''
307-
wrapper for ``tmux(1)``::
308-
309-
$ tmux set-option <option> <value>
306+
"""Set option ``$ tmux set-option <option> <value>``.
310307
311308
todo: needs tests
312309
313310
:param option: the window option. such as 'default-shell'.
314311
:type option: string
315312
:param value: window value. True/False will turn in 'on' and 'off'.
316313
:type value: string or bool
317-
'''
314+
315+
"""
318316

319317
if isinstance(value, bool) and value:
320318
value = 'on'
@@ -331,16 +329,16 @@ def set_option(self, option, value):
331329
raise ValueError('tmux set-option stderr: %s' % process.stderr)
332330

333331
def show_options(self, option=None):
334-
'''
335-
return a dict of options for the window.
332+
"""Return a dict of options for the window.
336333
337334
For familiarity with tmux, the option ``option`` param forwards to pick
338335
a single option, forwarding to :meth:`Session.show_option`.
339336
340337
:param option: optional. show a single option.
341338
:type option: string
342339
:rtype: :py:obj:`dict`
343-
'''
340+
341+
"""
344342

345343
if option:
346344
return self.show_option(option)
@@ -360,15 +358,15 @@ def show_options(self, option=None):
360358
return session_options
361359

362360
def show_option(self, option):
363-
'''
364-
return a list of options for the window
361+
"""Return a list of options for the window.
365362
366363
todo: test and return True/False for on/off string
367364
368365
:param option: option to return.
369366
:type option: string
370367
:rtype: string, int or bool
371-
'''
368+
369+
"""
372370

373371
window_option = self.tmux(
374372
'show-options', option

0 commit comments

Comments
 (0)