Skip to content

Commit f35bd43

Browse files
committed
pyupgrade:
pip install pyupgrade autoflake; \ pyupgrade --py37 tests/**/*.py docs/**/*.py tmuxp/**/*.py; \ poetry run autoflake tests/**/*.py docs/**/*.py tmuxp/**/*.py -i --ignore-init-module-imports; \ make black isort
1 parent 27bb59c commit f35bd43

12 files changed

+40
-57
lines changed

docs/_ext/aafig.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get_basename(text, options, prefix="aafig"):
4848
del options["format"]
4949
hashkey = text + str(options)
5050
id = sha(hashkey.encode("utf-8")).hexdigest()
51-
return "%s-%s" % (prefix, id)
51+
return f"{prefix}-{id}"
5252

5353

5454
class AafigError(SphinxError):
@@ -135,7 +135,7 @@ def render_aafig_images(app, doctree):
135135
img["uri"] = fname
136136
# FIXME: find some way to avoid this hack in aafigure
137137
if extra:
138-
(width, height) = [x.split('"')[1] for x in extra.split()]
138+
(width, height) = (x.split('"')[1] for x in extra.split())
139139
if "width" not in img:
140140
img["width"] = width
141141
if "height" not in img:
@@ -151,7 +151,7 @@ def render_aafigure(app, text, options):
151151
raise AafigError("aafigure module not installed")
152152

153153
fname = get_basename(text, options)
154-
fname = "%s.%s" % (get_basename(text, options), options["format"])
154+
fname = "{}.{}".format(get_basename(text, options), options["format"])
155155
if app.builder.format == "html":
156156
# HTML
157157
imgpath = relative_uri(app.builder.env.docname, "_images")
@@ -177,7 +177,7 @@ def render_aafigure(app, text, options):
177177
f = None
178178
try:
179179
try:
180-
f = open(metadata_fname, "r")
180+
f = open(metadata_fname)
181181
extra = f.read()
182182
except Exception:
183183
raise AafigError()

docs/conf.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@
100100
latex_documents = [
101101
(
102102
"index",
103-
"{0}.tex".format(about["__package_name__"]),
104-
"{0} Documentation".format(about["__title__"]),
103+
"{}.tex".format(about["__package_name__"]),
104+
"{} Documentation".format(about["__title__"]),
105105
about["__author__"],
106106
"manual",
107107
)
@@ -111,7 +111,7 @@
111111
(
112112
"index",
113113
about["__package_name__"],
114-
"{0} Documentation".format(about["__title__"]),
114+
"{} Documentation".format(about["__title__"]),
115115
about["__author__"],
116116
1,
117117
)
@@ -120,8 +120,8 @@
120120
texinfo_documents = [
121121
(
122122
"index",
123-
"{0}".format(about["__package_name__"]),
124-
"{0} Documentation".format(about["__title__"]),
123+
"{}".format(about["__package_name__"]),
124+
"{} Documentation".format(about["__title__"]),
125125
about["__author__"],
126126
about["__package_name__"],
127127
about["__description__"],
@@ -196,14 +196,14 @@ def linkcode_resolve(domain, info): # NOQA: C901
196196
fn = relpath(fn, start=dirname(tmuxp.__file__))
197197

198198
if "dev" in about["__version__"]:
199-
return "%s/blob/master/%s/%s%s" % (
199+
return "{}/blob/master/{}/{}{}".format(
200200
about["__github__"],
201201
about["__package_name__"],
202202
fn,
203203
linespec,
204204
)
205205
else:
206-
return "%s/blob/v%s/%s/%s%s" % (
206+
return "{}/blob/v{}/{}/{}{}".format(
207207
about["__github__"],
208208
about["__version__"],
209209
about["__package_name__"],

tests/conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def session(server):
7878
"""
7979
try:
8080
server.switch_client(session.get("session_id"))
81-
pass
8281
except exc.LibTmuxException:
8382
# server.attach_session(session.get('session_id'))
8483
pass

tests/test_cli.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
try:
66
from unittest.mock import MagicMock
77
except ImportError:
8-
from mock import MagicMock
8+
from unittest.mock import MagicMock
99

1010
import pytest
1111

@@ -435,7 +435,7 @@ def test_load_log_file(cli_args, tmpdir, monkeypatch):
435435
monkeypatch.setenv("HOME", str(tmpdir))
436436

437437
with tmpdir.as_cwd():
438-
print("tmpdir: {0}".format(tmpdir))
438+
print(f"tmpdir: {tmpdir}")
439439
runner = CliRunner()
440440

441441
# If autoconfirm (-y) no need to prompt y
@@ -1030,7 +1030,7 @@ def test_ls_cli(monkeypatch, tmpdir):
10301030
stems = [os.path.splitext(f)[0] for f in filenames if f not in ignored_filenames]
10311031

10321032
for filename in filenames:
1033-
location = tmpdir.join(".tmuxp/{}".format(filename))
1033+
location = tmpdir.join(f".tmuxp/{filename}")
10341034
if filename.endswith("/"):
10351035
location.ensure_dir()
10361036
else:

tests/test_workspacebuilder.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def assertIsMissing(cmd, hist):
182182
if assertCase(sent_cmd, history_cmd):
183183
correct = True
184184
break
185-
assert correct, "Unknown sent command: [%s] in %s" % (sent_cmd, assertCase)
185+
assert correct, f"Unknown sent command: [{sent_cmd}] in {assertCase}"
186186

187187

188188
def test_session_options(session):
@@ -215,11 +215,11 @@ def test_global_options(session):
215215

216216
def test_global_session_env_options(session, monkeypatch):
217217
visual_silence = "on"
218-
monkeypatch.setenv(str("VISUAL_SILENCE"), str(visual_silence))
218+
monkeypatch.setenv("VISUAL_SILENCE", str(visual_silence))
219219
repeat_time = 738
220-
monkeypatch.setenv(str("REPEAT_TIME"), str(repeat_time))
220+
monkeypatch.setenv("REPEAT_TIME", str(repeat_time))
221221
main_pane_height = 8
222-
monkeypatch.setenv(str("MAIN_PANE_HEIGHT"), str(main_pane_height))
222+
monkeypatch.setenv("MAIN_PANE_HEIGHT", str(main_pane_height))
223223

224224
yaml_config = loadfixture("workspacebuilder/env_var_options.yaml")
225225
s = session
@@ -321,14 +321,14 @@ def test_window_shell(session):
321321

322322
for w, wconf in builder.iter_create_windows(s):
323323
if "window_shell" in wconf:
324-
assert wconf["window_shell"] == str("top")
324+
assert wconf["window_shell"] == "top"
325325

326326
while retry():
327327
session.server._update_windows()
328328
if w["window_name"] != "top":
329329
break
330330

331-
assert w.name != str("top")
331+
assert w.name != "top"
332332

333333

334334
def test_environment_variables(session):

tmuxp/_compat.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf8 -*-
21
# flake8: NOQA
32
import sys
43

tmuxp/cli.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _validate_choices(options):
143143
def func(value):
144144
if value not in options:
145145
raise click.BadParameter(
146-
"Possible choices are: {0}.".format(", ".join(options))
146+
"Possible choices are: {}.".format(", ".join(options))
147147
)
148148
return value
149149

@@ -188,7 +188,7 @@ def set_layout_hook(session, hook_name):
188188
# unfortunately, select-layout won't work unless
189189
# we've literally selected the window at least once
190190
# with the client
191-
hook_cmd.append("selectw -t {}".format(window.id))
191+
hook_cmd.append(f"selectw -t {window.id}")
192192
# edit: removed -t, or else it won't respect main-pane-w/h
193193
hook_cmd.append("selectl")
194194
hook_cmd.append("selectw -p")
@@ -199,7 +199,7 @@ def set_layout_hook(session, hook_name):
199199
target_session=session.id, hook_name=hook_name
200200
)
201201
)
202-
hook_cmd.append("selectw -t {}".format(attached_window.id))
202+
hook_cmd.append(f"selectw -t {attached_window.id}")
203203

204204
# join the hook's commands with semicolons
205205
hook_cmd = "{}".format("; ".join(hook_cmd))
@@ -236,7 +236,7 @@ def is_pure_name(path):
236236

237237
class ConfigPath(click.Path):
238238
def __init__(self, config_dir=None, *args, **kwargs):
239-
super(ConfigPath, self).__init__(*args, **kwargs)
239+
super().__init__(*args, **kwargs)
240240
self.config_dir = config_dir
241241

242242
def convert(self, value, param, ctx):
@@ -245,7 +245,7 @@ def convert(self, value, param, ctx):
245245
config_dir = config_dir()
246246

247247
value = scan_config(value, config_dir=config_dir)
248-
return super(ConfigPath, self).convert(value, param, ctx)
248+
return super().convert(value, param, ctx)
249249

250250

251251
def scan_config_argument(ctx, param, value, config_dir=None):
@@ -264,7 +264,7 @@ def scan_config_argument(ctx, param, value, config_dir=None):
264264
value = scan_config(value, config_dir=config_dir)
265265

266266
elif isinstance(value, tuple):
267-
value = tuple([scan_config(v, config_dir=config_dir) for v in value])
267+
value = tuple(scan_config(v, config_dir=config_dir) for v in value)
268268

269269
return value
270270

@@ -346,7 +346,7 @@ def scan_config(config, config_dir=None):
346346
candidates = [
347347
x
348348
for x in [
349-
"%s%s" % (join(config_dir, config), ext)
349+
f"{join(config_dir, config)}{ext}"
350350
for ext in VALID_CONFIG_DIR_FILE_EXTENSIONS
351351
]
352352
if exists(x)
@@ -421,8 +421,8 @@ def load_plugins(sconf):
421421
except Exception as error:
422422
click.echo(
423423
click.style("[Plugin Error] ", fg="red")
424-
+ "Couldn't load {0}\n".format(plugin)
425-
+ click.style("{0}".format(error), fg="yellow")
424+
+ f"Couldn't load {plugin}\n"
425+
+ click.style(f"{error}", fg="yellow")
426426
)
427427
sys.exit(1)
428428

@@ -985,7 +985,7 @@ def command_freeze(
985985
save_to = os.path.abspath(
986986
os.path.join(
987987
get_config_dir(),
988-
"%s.%s" % (sconf.get("session_name"), config_format or "yaml"),
988+
"{}.{}".format(sconf.get("session_name"), config_format or "yaml"),
989989
)
990990
)
991991
dest_prompt = click.prompt(
@@ -1135,7 +1135,6 @@ def command_load(
11351135
@cli.group(name="import")
11361136
def import_config_cmd():
11371137
"""Import a teamocil/tmuxinator config."""
1138-
pass
11391138

11401139

11411140
def import_config(configfile, importfunc):
@@ -1229,7 +1228,7 @@ def command_convert(confirmed, config):
12291228
to_filetype = "json"
12301229
else:
12311230
raise click.BadParameter(
1232-
"Unknown filetype: %s (valid: [.json, .yaml, .yml])" % (ext,)
1231+
f"Unknown filetype: {ext} (valid: [.json, .yaml, .yml])"
12331232
)
12341233

12351234
configparser = kaptan.Kaptan()
@@ -1240,7 +1239,7 @@ def command_convert(confirmed, config):
12401239
newconfig = configparser.export(to_filetype, indent=2, **export_kwargs)
12411240

12421241
if not confirmed:
1243-
if click.confirm("convert to <%s> to %s?" % (config, to_filetype)):
1242+
if click.confirm(f"convert to <{config}> to {to_filetype}?"):
12441243
if click.confirm("Save config to %s?" % newfile):
12451244
confirmed = True
12461245

@@ -1260,9 +1259,7 @@ def command_edit_config(config):
12601259
call([sys_editor, config])
12611260

12621261

1263-
@cli.command(
1264-
name="ls", short_help="List configured sessions in {}.".format(get_config_dir())
1265-
)
1262+
@cli.command(name="ls", short_help=f"List configured sessions in {get_config_dir()}.")
12661263
def command_ls():
12671264
tmuxp_dir = get_config_dir()
12681265
if os.path.exists(tmuxp_dir) and os.path.isdir(tmuxp_dir):

tmuxp/exc.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,25 @@ class TmuxpException(Exception):
1111

1212
"""Base Exception for Tmuxp Errors."""
1313

14-
pass
15-
1614

1715
class ConfigError(TmuxpException):
1816

1917
"""Error parsing tmuxp configuration dict."""
2018

21-
pass
22-
2319

2420
class EmptyConfigException(ConfigError):
2521

2622
"""Configuration is empty."""
2723

28-
pass
29-
3024

3125
class TmuxpPluginException(TmuxpException):
3226

3327
"""Base Exception for Tmuxp Errors."""
3428

35-
pass
36-
3729

3830
class BeforeLoadScriptNotExists(OSError):
3931
def __init__(self, *args, **kwargs):
40-
super(BeforeLoadScriptNotExists, self).__init__(*args, **kwargs)
32+
super().__init__(*args, **kwargs)
4133

4234
self.strerror = "before_script file '%s' doesn't exist." % self.strerror
4335

tmuxp/log.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def format(self, record):
9494
try:
9595
record.message = record.getMessage()
9696
except Exception as e:
97-
record.message = "Bad message (%r): %r" % (e, record.__dict__)
97+
record.message = f"Bad message ({e!r}): {record.__dict__!r}"
9898

9999
date_format = "%H:%m:%S"
100100
record.asctime = time.strftime(date_format, self.converter(record.created))

tmuxp/plugin.py

-5
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ def before_workspace_builder(self, session):
156156
session : :class:`libtmux.Session`
157157
session to hook into
158158
"""
159-
pass
160159

161160
def on_window_create(self, window):
162161
"""
@@ -169,7 +168,6 @@ def on_window_create(self, window):
169168
window: :class:`libtmux.Window`
170169
window to hook into
171170
"""
172-
pass
173171

174172
def after_window_finished(self, window):
175173
"""
@@ -184,7 +182,6 @@ def after_window_finished(self, window):
184182
window: :class:`libtmux.Window`
185183
window to hook into
186184
"""
187-
pass
188185

189186
def before_script(self, session):
190187
"""
@@ -213,7 +210,6 @@ def before_script(self, session):
213210
session : :class:`libtmux.Session`
214211
session to hook into
215212
"""
216-
pass
217213

218214
def reattach(self, session):
219215
"""
@@ -224,4 +220,3 @@ def reattach(self, session):
224220
session : :class:`libtmux.Session`
225221
session to hook into
226222
"""
227-
pass

tmuxp/shell.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ def get_code(use_pythonrc, imported_objects):
200200
# We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
201201
# conventions and get $PYTHONSTARTUP first then .pythonrc.py.
202202
if use_pythonrc:
203-
for pythonrc in set(
204-
[os.environ.get("PYTHONSTARTUP"), os.path.expanduser("~/.pythonrc.py")]
205-
):
203+
for pythonrc in {
204+
os.environ.get("PYTHONSTARTUP"),
205+
os.path.expanduser("~/.pythonrc.py"),
206+
}:
206207
if not pythonrc:
207208
continue
208209
if not os.path.isfile(pythonrc):

tmuxp/workspacebuilder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
logger = logging.getLogger(__name__)
1919

2020

21-
class WorkspaceBuilder(object):
21+
class WorkspaceBuilder:
2222

2323
"""
2424
Load workspace from session :py:obj:`dict`.

0 commit comments

Comments
 (0)