Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b3498df

Browse files
committedApr 1, 2018
more numpy-docstring conversion
1 parent 7dc6d38 commit b3498df

File tree

2 files changed

+192
-109
lines changed

2 files changed

+192
-109
lines changed
 

‎libtmux/common.py

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,23 @@ def by(val, *args):
335335
return list(filter(by, self.children))
336336

337337
def get_by_id(self, id):
338-
"""Return object based on ``child_id_attribute``.
338+
"""
339+
Return object based on ``child_id_attribute``.
340+
341+
Parameters
342+
----------
343+
val : str
344+
345+
Returns
346+
-------
347+
object
339348
349+
Notes
350+
-----
340351
Based on `.get()`_ from `backbone.js`_.
341352
342353
.. _backbone.js: http://backbonejs.org/
343354
.. _.get(): http://backbonejs.org/#Collection-get
344-
345-
:param id:
346-
:type id: str
347-
:rtype: object
348-
349355
"""
350356
for child in self.children:
351357
if child[self.child_id_attribute] == id:
@@ -359,18 +365,26 @@ def get_by_id(self, id):
359365
def which(exe=None, default_paths=[
360366
'/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin'
361367
], append_env_path=True):
362-
"""Return path of bin. Python clone of /usr/bin/which.
363-
368+
"""
369+
Return path of bin. Python clone of /usr/bin/which.
370+
371+
Parameters
372+
----------
373+
exe : str
374+
Application to search PATHs for.
375+
default_path : list
376+
Paths to check inside of
377+
append_env_path : bool, optional
378+
Append list of directories to check in from PATH environment variable.
379+
Default True. Setting False only for testing / diagnosing.
380+
381+
Returns
382+
-------
383+
str
384+
385+
Notes
386+
-----
364387
from salt.util - https://www.github.com/saltstack/salt - license apache
365-
366-
:param exe: Application to search PATHs for.
367-
:type exe: str
368-
:param default_path: Application to search PATHs for.
369-
:type default_path: list
370-
:param append_env_path: Append PATHs in environmental variables.
371-
:type append_env_path: bool
372-
:rtype: str
373-
374388
"""
375389
def _is_executable_file_or_link(exe):
376390
# check for os.X_OK doesn't suffice because directory may executable
@@ -439,23 +453,35 @@ def get_version():
439453

440454

441455
def has_version(version):
442-
"""Return True if tmux version installed.
456+
"""
457+
Return affirmative if tmux version installed.
443458
444-
:param version: version, '1.8'
445-
:type version: str
446-
:returns: True if version matches
447-
:rtype: bool
459+
Parameters
460+
----------
461+
version : str
462+
version number, e.g. '1.8'
463+
464+
Returns
465+
-------
466+
bool :
467+
True if version matches
448468
"""
449469
return get_version() == LooseVersion(version)
450470

451471

452472
def has_gt_version(min_version):
453-
"""Return True if tmux version greater than minimum.
473+
"""
474+
Return affirmative if tmux version greater than minimum.
454475
455-
:param min_version: version, e.g. '1.8'
456-
:type min_version: str
457-
:returns: True if version above min_version
458-
:rtype: bool
476+
Parameters
477+
----------
478+
min_version : str
479+
tmux version, e.g. '1.8'
480+
481+
Returns
482+
-------
483+
bool :
484+
True if version above min_version
459485
"""
460486
return get_version() > LooseVersion(min_version)
461487

‎libtmux/session.py

Lines changed: 139 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,35 @@ def kill_session(self):
115115
raise exc.LibTmuxException(proc.stderr)
116116

117117
def switch_client(self):
118-
"""``$ tmux switch-client``.
118+
"""
119+
Switch client to this session.
120+
121+
Raises
122+
------
119123
120-
:param: target_session: str. note this accepts fnmatch(3).
121-
:raises: :exc:`exc.LibTmuxException`
124+
:exc:`exc.LibTmuxException`
122125
"""
123126
proc = self.cmd('switch-client', '-t%s' % self.id)
124127

125128
if proc.stderr:
126129
raise exc.LibTmuxException(proc.stderr)
127130

128131
def rename_session(self, new_name):
129-
"""Rename session and return new :class:`Session` object.
132+
"""
133+
Rename session and return new :class:`Session` object.
130134
131-
:param new_name: new session name
132-
:type new_name: str
133-
:raises: :exc:`exc.BadSessionName`
134-
:rtype: :class:`Session`
135+
Parameters
136+
----------
137+
new_name : str
138+
new session name
135139
140+
Returns
141+
-------
142+
:class:`Session`
143+
144+
Raises
145+
------
146+
:exc:`exc.BadSessionName`
136147
"""
137148
session_check_name(new_name)
138149

@@ -153,33 +164,35 @@ def new_window(self,
153164
attach=True,
154165
window_index='',
155166
window_shell=None):
156-
"""Return :class:`Window` from ``$ tmux new-window``.
167+
"""
168+
Return :class:`Window` from ``$ tmux new-window``.
157169
158170
By default, this will make the window active. For the new window
159171
to be created and not set to current, pass in ``attach=False``.
160172
161-
:param window_name: window name.
162-
:type window_name: str
163-
:param start_directory: specifies the working directory in which the
164-
new window is created.
165-
:type start_directory: str
166-
:param attach: make new window the current window after creating it,
167-
default True.
168-
:param window_index: create the new window at the given index position.
169-
Default is empty string which will create the window in the next
170-
available position.
171-
:type window_index: str
172-
:param window_shell: execute a command on starting the window. The
173-
window will close when the command exits.
174-
NOTE: When this command exits the window will close. This feature
175-
is useful for long-running processes where the closing of the
176-
window upon completion is desired.
177-
:type window_command: str
178-
:param type: bool
179-
:rtype: :class:`Window`
180-
173+
Parameters
174+
----------
175+
window_name : str, optional
176+
start_directory : str, optional
177+
working directory in which the new window is created.
178+
attach : bool, optional
179+
make new window the current window after creating it, default True.
180+
window_index : str
181+
create the new window at the given index position. Default is empty
182+
string which will create the window in the next available position.
183+
window_shell : str
184+
execute a command on starting the window. The window will close
185+
when the command exits.
186+
187+
.. note::
188+
When this command exits the window will close. This feature is
189+
useful for long-running processes where the closing of the
190+
window upon completion is desired.
191+
192+
Returns
193+
-------
194+
:class:`Window`
181195
"""
182-
183196
wformats = ['session_name', 'session_id'] + formats.WINDOW_FORMATS
184197
tmux_formats = ['#{%s}' % f for f in wformats]
185198

@@ -229,14 +242,15 @@ def new_window(self,
229242
return window
230243

231244
def kill_window(self, target_window=None):
232-
"""``$ tmux kill-window``.
245+
"""Close a tmux window, and all panes inside it, ``$ tmux kill-window``
233246
234247
Kill the current window or the window at ``target-window``. removing it
235248
from any sessions to which it is linked.
236249
237-
:param target_window: the ``target window``.
238-
:type target_window: str
239-
250+
Parameters
251+
----------
252+
target_window : str, optional
253+
window to kill
240254
"""
241255

242256
if target_window:
@@ -270,8 +284,9 @@ def _windows(self):
270284
def list_windows(self):
271285
"""Return a list of :class:`Window` from the ``tmux(1)`` session.
272286
273-
:rtype: :class:`Window`
274-
287+
Returns
288+
-------
289+
:class:`Window`
275290
"""
276291
windows = [
277292
w for w in self._windows if w['session_id'] == self._session_id
@@ -289,10 +304,12 @@ def windows(self):
289304

290305
@property
291306
def attached_window(self):
292-
"""Return active :class:`Window` object.
293-
294-
:rtype: :class:`Window`
307+
"""
308+
Return active :class:`Window` object.
295309
310+
Returns
311+
-------
312+
:class:`Window`
296313
"""
297314
active_windows = []
298315
for window in self._windows:
@@ -313,15 +330,24 @@ def attached_window(self):
313330
raise exc.LibTmuxException('No Windows')
314331

315332
def select_window(self, target_window):
316-
"""Return :class:`Window` selected via ``$ tmux select-window``.
333+
"""
334+
Return :class:`Window` selected via ``$ tmux select-window``.
335+
336+
Parameters
337+
----------
338+
window : str
339+
``target_window`` also 'last-window' (``-l``), 'next-window'
340+
(``-n``), or 'previous-window' (``-p``)
317341
318-
:param: window: ``target_window`` also 'last-window' (``-l``),
319-
'next-window' (``-n``), or 'previous-window' (``-p``)
320-
:type window: integer
321-
:rtype: :class:`Window`
342+
Returns
343+
-------
344+
:class:`Window`
322345
323-
:todo: assure ``-l``, ``-n``, ``-p`` work.
346+
Notes
347+
-----
348+
.. todo::
324349
350+
assure ``-l``, ``-n``, ``-p`` work.
325351
"""
326352

327353
target = '-t%s' % target_window
@@ -339,21 +365,30 @@ def attached_pane(self):
339365

340366
return self.attached_window.attached_pane
341367

342-
def set_option(self, option, value, g=False):
343-
"""Set option ``$ tmux set-option <option> <value>``.
344-
345-
todo: needs tests
346-
347-
:param option: the window option. such as 'default-shell'.
348-
:type option: str
349-
:param value: window value. True/False will turn in 'on' and 'off'. You
350-
can also enter 'on' or 'off' directly.
351-
:type value: bool
352-
:param global: check for option globally across all servers (-g)
353-
:type global: bool
354-
:raises: :exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
355-
:exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
356-
368+
def set_option(self, option, value, _global=False):
369+
"""
370+
Set option ``$ tmux set-option <option> <value>``.
371+
372+
Parameters
373+
----------
374+
option : str
375+
the window option. such as 'default-shell'.
376+
value : str, int, or bool
377+
True/False will turn in 'on' and 'off'. You can also enter 'on' or
378+
'off' directly.
379+
_global : bool, optional
380+
check for option globally across all servers (-g)
381+
382+
Raises
383+
------
384+
:exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
385+
:exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
386+
387+
Notes
388+
-----
389+
.. todo::
390+
391+
Needs tests
357392
"""
358393

359394
if isinstance(value, bool) and value:
@@ -363,7 +398,7 @@ def set_option(self, option, value, g=False):
363398

364399
tmux_args = tuple()
365400

366-
if g:
401+
if _global:
367402
tmux_args += ('-g',)
368403

369404
tmux_args += (option, value,)
@@ -375,27 +410,37 @@ def set_option(self, option, value, g=False):
375410
if isinstance(proc.stderr, list) and len(proc.stderr):
376411
handle_option_error(proc.stderr[0])
377412

378-
def show_options(self, option=None, g=False):
379-
"""Return a dict of options for the window.
413+
def show_options(self, option=None, _global=False):
414+
"""
415+
Return a dict of options for the window.
380416
381417
For familiarity with tmux, the option ``option`` param forwards to pick
382418
a single option, forwarding to :meth:`Session.show_option`.
383419
384-
:param option: optional. show a single option.
385-
:type option: str
386-
:param g: Pass ``-g`` flag for global variable (server-wide)
387-
:type g: bool
388-
:rtype: :py:obj:`dict`
389-
420+
Parameters
421+
----------
422+
option : str, optional
423+
name of option, e.g. 'visual-silence'. Defaults to None, which
424+
returns all options.
425+
_global : bool, optional
426+
Pass ``-g`` flag for global variable (server-wide)
427+
428+
Returns
429+
-------
430+
:py:obj:`dict`
431+
432+
Notes
433+
-----
434+
Uses ``_global`` for keyword name instead of ``global`` to avoid
435+
colliding with reserved keyword.
390436
"""
391-
392437
tmux_args = tuple()
393438

394-
if g:
439+
if _global:
395440
tmux_args += ('-g',)
396441

397442
if option:
398-
return self.show_option(option, g=g)
443+
return self.show_option(option, _global=_global)
399444
else:
400445
tmux_args += ('show-options',)
401446
session_options = self.cmd(
@@ -412,24 +457,36 @@ def show_options(self, option=None, g=False):
412457

413458
return session_options
414459

415-
def show_option(self, option, g=False):
460+
def show_option(self, option, _global=False):
416461
"""Return a list of options for the window.
417462
418-
:todo: test and return True/False for on/off string
463+
Parameters
464+
----------
465+
option : str
466+
option name
467+
_global : bool, optional
468+
use global option scope, same as ``-g``
469+
470+
Returns
471+
-------
472+
str, int, or bool
473+
474+
Raises
475+
------
476+
:exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
477+
:exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
419478
420-
:param option: option to return.
421-
:type option: str
422-
:param global: check for option globally across all servers (-g)
423-
:type global: bool
424-
:rtype: str, int or bool
425-
:raises: :exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
426-
:exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
479+
Notes
480+
-----
481+
Uses ``_global`` for keyword name instead of ``global`` to avoid
482+
colliding with reserved keyword.
427483
484+
Test and return True/False for on/off string.
428485
"""
429486

430487
tmux_args = tuple()
431488

432-
if g:
489+
if _global:
433490
tmux_args += ('-g',)
434491

435492
tmux_args += (option,)

0 commit comments

Comments
 (0)
Please sign in to comment.