Skip to content

Commit ee38253

Browse files
committed
Merge branch 'click-7'
Click 7.0 support. Fixes #428, #430
2 parents 73cfb72 + 50d13e0 commit ee38253

File tree

4 files changed

+26
-31
lines changed

4 files changed

+26
-31
lines changed

Pipfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "pypi"
66
[dev-packages]
77
kaptan = ">=0.5.7"
88
libtmux = "==0.8.0"
9-
click = "<7"
9+
click = ">=7<8"
1010
colorama = "==0.3.9"
1111
docutils = "==0.14"
1212
alagitpull = "==0.0.21"
@@ -24,7 +24,7 @@ tmuxp = {path = ".", editable = true}
2424
[packages]
2525
kaptan = ">=0.5.7"
2626
libtmux = "==0.8.0"
27-
click = "<7"
27+
click = ">=7<8"
2828
colorama = "==0.3.9"
2929

3030
[requires]

requirements/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kaptan>=0.5.7
22
libtmux==0.8.0
3-
click<7
3+
click>=7<8
44
colorama==0.3.9

tests/test_cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ def test_scan_config_arg(homedir, configdir, projectdir, monkeypatch):
222222
runner = CliRunner()
223223

224224
@click.command()
225-
@click.argument(
226-
'config', click.Path(exists=True), nargs=-1, callback=cli.scan_config_argument
227-
)
225+
@click.argument('config', type=cli.ConfigPath(exists=True), nargs=-1)
228226
def config_cmd(config):
229227
click.echo(config)
230228

@@ -463,7 +461,8 @@ def test_import_tmuxinator(cli_args, inputs, tmpdir, monkeypatch):
463461

464462
with tmpdir.as_cwd():
465463
runner = CliRunner()
466-
runner.invoke(cli.cli, cli_args, input=''.join(inputs))
464+
out = runner.invoke(cli.cli, cli_args, input=''.join(inputs))
465+
print(out.output)
467466
assert tmpdir.join('la.yaml').check()
468467

469468

@@ -510,20 +509,21 @@ def test_validate_choices():
510509
assert validate('choice3')
511510

512511

513-
def test_create_scan_config_arg(tmpdir):
512+
def test_pass_config_dir_ClickPath(tmpdir):
514513
configdir = tmpdir.join('myconfigdir')
515514
configdir.mkdir()
516515
user_config_name = 'myconfig'
517516
user_config = configdir.join('%s.yaml' % user_config_name).ensure()
518517

519518
expect = str(configdir.join('myconfig.yaml'))
520-
my_scan_config = cli._create_scan_config_argument(str(configdir))
521519

522520
runner = CliRunner()
523521

524522
@click.command()
525523
@click.argument(
526-
'config', click.Path(exists=True), nargs=-1, callback=my_scan_config
524+
'config',
525+
type=cli.ConfigPath(exists=True, config_dir=(str(configdir))),
526+
nargs=-1,
527527
)
528528
def config_cmd(config):
529529
click.echo(config)

tmuxp/cli.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,18 @@ def is_pure_name(path):
196196
)
197197

198198

199-
def _create_scan_config_argument(config_dir):
200-
"""For finding configurations in tmuxinator/teamocil"""
199+
class ConfigPath(click.Path):
200+
def __init__(self, config_dir=None, *args, **kwargs):
201+
super(ConfigPath, self).__init__(*args, **kwargs)
202+
self.config_dir = config_dir
201203

202-
def func(ctx, param, value):
203-
return scan_config_argument(ctx, param, value, config_dir)
204+
def convert(self, value, param, ctx):
205+
config_dir = self.config_dir
206+
if callable(config_dir):
207+
config_dir = config_dir()
204208

205-
return func
209+
value = scan_config(value, config_dir=config_dir)
210+
return super(ConfigPath, self).convert(value, param, ctx)
206211

207212

208213
def scan_config_argument(ctx, param, value, config_dir=None):
@@ -719,25 +724,23 @@ def command_freeze(session_name, socket_name, socket_path):
719724

720725
@cli.command(name='load', short_help='Load tmuxp workspaces.')
721726
@click.pass_context
722-
@click.argument(
723-
'config', click.Path(exists=True), nargs=-1, callback=scan_config_argument
724-
)
727+
@click.argument('config', type=ConfigPath(exists=True), nargs=-1)
725728
@click.option('-S', 'socket_path', help='pass-through for tmux -S')
726729
@click.option('-L', 'socket_name', help='pass-through for tmux -L')
727730
@click.option('--yes', '-y', 'answer_yes', help='yes', is_flag=True)
728731
@click.option(
729732
'-d', 'detached', help='Load the session without attaching it', is_flag=True
730733
)
731734
@click.option(
732-
'-2',
733735
'colors',
736+
'-2',
734737
flag_value=256,
735738
default=True,
736739
help='Force tmux to assume the terminal supports 256 colours.',
737740
)
738741
@click.option(
739-
'-8',
740742
'colors',
743+
'-8',
741744
flag_value=88,
742745
help='Like -2, but indicates that the terminal supports 88 colours.',
743746
)
@@ -854,10 +857,7 @@ def import_config(configfile, importfunc):
854857
name='teamocil', short_help='Convert and import a teamocil config.'
855858
)
856859
@click.argument(
857-
'configfile',
858-
click.Path(exists=True),
859-
nargs=1,
860-
callback=_create_scan_config_argument(get_teamocil_dir),
860+
'configfile', type=ConfigPath(exists=True, config_dir=get_teamocil_dir), nargs=1
861861
)
862862
def command_import_teamocil(configfile):
863863
"""Convert a teamocil config from CONFIGFILE to tmuxp format and import
@@ -870,10 +870,7 @@ def command_import_teamocil(configfile):
870870
name='tmuxinator', short_help='Convert and import a tmuxinator config.'
871871
)
872872
@click.argument(
873-
'configfile',
874-
click.Path(exists=True),
875-
nargs=1,
876-
callback=_create_scan_config_argument(get_tmuxinator_dir),
873+
'configfile', type=ConfigPath(exists=True, config_dir=get_tmuxinator_dir), nargs=1
877874
)
878875
def command_import_tmuxinator(configfile):
879876
"""Convert a tmuxinator config from CONFIGFILE to tmuxp format and import
@@ -882,9 +879,7 @@ def command_import_tmuxinator(configfile):
882879

883880

884881
@cli.command(name='convert')
885-
@click.argument(
886-
'config', click.Path(exists=True), nargs=1, callback=scan_config_argument
887-
)
882+
@click.argument('config', type=ConfigPath(exists=True), nargs=1)
888883
def command_convert(config):
889884
"""Convert a tmuxp config between JSON and YAML."""
890885

0 commit comments

Comments
 (0)