10
10
import re
11
11
import subprocess
12
12
import sys
13
+ import typing as t
13
14
from distutils .version import LooseVersion
14
15
15
16
from . import exc
@@ -374,10 +375,16 @@ def get_by_id(self, id):
374
375
375
376
376
377
def which (
377
- exe = None ,
378
- default_paths = ["/bin" , "/sbin" , "/usr/bin" , "/usr/sbin" , "/usr/local/bin" ],
379
- append_env_path = True ,
380
- ):
378
+ exe : str ,
379
+ default_paths : t .List [str ] = [
380
+ "/bin" ,
381
+ "/sbin" ,
382
+ "/usr/bin" ,
383
+ "/usr/sbin" ,
384
+ "/usr/local/bin" ,
385
+ ],
386
+ append_env_path : bool = True ,
387
+ ) -> t .Optional [str ]:
381
388
"""
382
389
Return path of bin. Python clone of /usr/bin/which.
383
390
@@ -401,7 +408,7 @@ def which(
401
408
from salt.util - https://www.github.com/saltstack/salt - license apache
402
409
"""
403
410
404
- def _is_executable_file_or_link (exe ) :
411
+ def _is_executable_file_or_link (exe : str ) -> bool :
405
412
# check for os.X_OK doesn't suffice because directory may executable
406
413
return os .access (exe , os .X_OK ) and (os .path .isfile (exe ) or os .path .islink (exe ))
407
414
@@ -434,7 +441,7 @@ def _is_executable_file_or_link(exe):
434
441
return None
435
442
436
443
437
- def get_version ():
444
+ def get_version () -> LooseVersion :
438
445
"""
439
446
Return tmux version.
440
447
@@ -471,7 +478,7 @@ def get_version():
471
478
return LooseVersion (version )
472
479
473
480
474
- def has_version (version ) :
481
+ def has_version (version : str ) -> bool :
475
482
"""
476
483
Return affirmative if tmux version installed.
477
484
@@ -488,7 +495,7 @@ def has_version(version):
488
495
return get_version () == LooseVersion (version )
489
496
490
497
491
- def has_gt_version (min_version ) :
498
+ def has_gt_version (min_version : str ) -> bool :
492
499
"""
493
500
Return affirmative if tmux version greater than minimum.
494
501
@@ -505,7 +512,7 @@ def has_gt_version(min_version):
505
512
return get_version () > LooseVersion (min_version )
506
513
507
514
508
- def has_gte_version (min_version ) :
515
+ def has_gte_version (min_version : str ) -> bool :
509
516
"""
510
517
Return True if tmux version greater or equal to minimum.
511
518
@@ -522,7 +529,7 @@ def has_gte_version(min_version):
522
529
return get_version () >= LooseVersion (min_version )
523
530
524
531
525
- def has_lte_version (max_version ) :
532
+ def has_lte_version (max_version : str ) -> bool :
526
533
"""
527
534
Return True if tmux version less or equal to minimum.
528
535
@@ -539,7 +546,7 @@ def has_lte_version(max_version):
539
546
return get_version () <= LooseVersion (max_version )
540
547
541
548
542
- def has_lt_version (max_version ) :
549
+ def has_lt_version (max_version : str ) -> bool :
543
550
"""
544
551
Return True if tmux version less than minimum.
545
552
@@ -556,7 +563,7 @@ def has_lt_version(max_version):
556
563
return get_version () < LooseVersion (max_version )
557
564
558
565
559
- def has_minimum_version (raises = True ):
566
+ def has_minimum_version (raises : bool = True ) -> bool :
560
567
"""
561
568
Return if tmux meets version requirement. Version >1.8 or above.
562
569
@@ -598,7 +605,7 @@ def has_minimum_version(raises=True):
598
605
return True
599
606
600
607
601
- def session_check_name (session_name ):
608
+ def session_check_name (session_name : str ):
602
609
"""
603
610
Raises exception session name invalid, modeled after tmux function.
604
611
@@ -627,7 +634,7 @@ def session_check_name(session_name):
627
634
)
628
635
629
636
630
- def handle_option_error (error ):
637
+ def handle_option_error (error : str ):
631
638
"""Raises exception if error in option command found.
632
639
633
640
In tmux 3.0, show-option and show-window-otion return invalid option instead of
@@ -664,7 +671,7 @@ def handle_option_error(error):
664
671
raise exc .OptionError (error ) # Raise generic option error
665
672
666
673
667
- def get_libtmux_version ():
674
+ def get_libtmux_version () -> LooseVersion :
668
675
"""Return libtmux version is a PEP386 compliant format.
669
676
670
677
Returns
0 commit comments