Skip to content

Commit f91f258

Browse files
committed
chore(ruff): Manual fixes for shell
1 parent 49a9588 commit f91f258

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/tmuxp/shell.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import logging
88
import os
9+
import pathlib
910
import typing as t
1011

1112
logger = logging.getLogger(__name__)
@@ -106,7 +107,7 @@ def launch_ipython():
106107
ipython_arguments = extra_args or get_ipython_arguments()
107108
start_ipython(argv=ipython_arguments, user_ns=imported_objects)
108109

109-
return launch_ipython
110+
return launch_ipython # NOQA: TRY300
110111
except ImportError:
111112
# IPython < 0.11
112113
# Explicitly pass an empty list as arguments, because otherwise
@@ -130,7 +131,7 @@ def get_ptpython(options, vi_mode=False):
130131

131132
def launch_ptpython():
132133
imported_objects = get_launch_args(**options)
133-
history_filename = os.path.expanduser("~/.ptpython_history")
134+
history_filename = str(pathlib.Path("~/.ptpython_history").expanduser())
134135
embed(
135136
globals=imported_objects,
136137
history_filename=history_filename,
@@ -156,7 +157,7 @@ def get_ptipython(options, vi_mode=False):
156157

157158
def launch_ptipython():
158159
imported_objects = get_launch_args(**options)
159-
history_filename = os.path.expanduser("~/.ptpython_history")
160+
history_filename = str(pathlib.Path("~/.ptpython_history").expanduser())
160161
embed(
161162
user_ns=imported_objects,
162163
history_filename=history_filename,
@@ -169,13 +170,17 @@ def launch_ptipython():
169170

170171
def get_launch_args(**kwargs):
171172
import libtmux
173+
from libtmux.pane import Pane
174+
from libtmux.server import Server
175+
from libtmux.session import Session
176+
from libtmux.window import Window
172177

173178
return {
174179
"libtmux": libtmux,
175-
"Server": libtmux.Server,
176-
"Session": libtmux.Session,
177-
"Window": libtmux.Window,
178-
"Pane": libtmux.Pane,
180+
"Server": Server,
181+
"Session": Session,
182+
"Window": Window,
183+
"Pane": Pane,
179184
"server": kwargs.get("server"),
180185
"session": kwargs.get("session"),
181186
"window": kwargs.get("window"),
@@ -208,15 +213,16 @@ def get_code(use_pythonrc, imported_objects):
208213
# We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
209214
# conventions and get $PYTHONSTARTUP first then .pythonrc.py.
210215
if use_pythonrc:
216+
PYTHONSTARTUP = os.environ.get("PYTHONSTARTUP")
211217
for pythonrc in {
212-
os.environ.get("PYTHONSTARTUP"),
213-
os.path.expanduser("~/.pythonrc.py"),
218+
*([pathlib.Path(PYTHONSTARTUP)] if PYTHONSTARTUP is not None else []),
219+
pathlib.Path("~/.pythonrc.py").expanduser(),
214220
}:
215221
if not pythonrc:
216222
continue
217-
if not os.path.isfile(pythonrc):
223+
if not pythonrc.is_file():
218224
continue
219-
with open(pythonrc) as handle:
225+
with pythonrc.open() as handle:
220226
pythonrc_code = handle.read()
221227
# Match the behavior of the cpython shell where an error in
222228
# PYTHONSTARTUP prints an exception and continues.

0 commit comments

Comments
 (0)