15
15
import site
16
16
import sys
17
17
import sysconfig
18
+ from pathlib import Path
18
19
from shutil import which
19
20
from subprocess import Popen
20
21
from typing import Any
@@ -37,7 +38,6 @@ def epilog(self) -> str | None:
37
38
@epilog .setter
38
39
def epilog (self , x : Any ) -> None :
39
40
"""Ignore epilog set in Parser.__init__"""
40
- pass
41
41
42
42
def argcomplete (self ) -> None :
43
43
"""Trigger auto-completion, if enabled"""
@@ -63,7 +63,7 @@ def jupyter_parser() -> JupyterParser:
63
63
"subcommand" , type = str , nargs = "?" , help = "the subcommand to launch"
64
64
)
65
65
# For argcomplete, supply all known subcommands
66
- subcommand_action .completer = lambda * args , ** kwargs : list_subcommands () # type: ignore[attr-defined]
66
+ subcommand_action .completer = lambda * args , ** kwargs : list_subcommands () # type: ignore[attr-defined] # noqa: ARG005
67
67
68
68
group .add_argument ("--config-dir" , action = "store_true" , help = "show Jupyter config dir" )
69
69
group .add_argument ("--data-dir" , action = "store_true" , help = "show Jupyter data dir" )
@@ -98,7 +98,7 @@ def list_subcommands() -> list[str]:
98
98
if name .startswith ("jupyter-" ):
99
99
if sys .platform .startswith ("win" ):
100
100
# remove file-extension on Windows
101
- name = os .path .splitext (name )[0 ] # noqa
101
+ name = os .path .splitext (name )[0 ] # noqa: PTH122, PLW2901
102
102
subcommand_tuples .add (tuple (name .split ("-" )[1 :]))
103
103
# build a set of subcommand strings, excluding subcommands whose parents are defined
104
104
subcommands = set ()
@@ -120,7 +120,7 @@ def _execvp(cmd: str, argv: list[str]) -> None:
120
120
cmd_path = which (cmd )
121
121
if cmd_path is None :
122
122
raise OSError ("%r not found" % cmd , errno .ENOENT )
123
- p = Popen ([cmd_path ] + argv [1 :]) # noqa
123
+ p = Popen ([cmd_path ] + argv [1 :]) # noqa: S603
124
124
# Don't raise KeyboardInterrupt in the parent process.
125
125
# Set this after spawning, to avoid subprocess inheriting handler.
126
126
import signal
@@ -129,7 +129,7 @@ def _execvp(cmd: str, argv: list[str]) -> None:
129
129
p .wait ()
130
130
sys .exit (p .returncode )
131
131
else :
132
- os .execvp (cmd , argv ) # noqa
132
+ os .execvp (cmd , argv ) # noqa: S606
133
133
134
134
135
135
def _jupyter_abspath (subcommand : str ) -> str :
@@ -177,13 +177,13 @@ def _path_with_self() -> list[str]:
177
177
path_list .append (bindir )
178
178
179
179
scripts = [sys .argv [0 ]]
180
- if os . path . islink (scripts [0 ]):
180
+ if Path (scripts [0 ]). is_symlink ( ):
181
181
# include realpath, if `jupyter` is a symlink
182
182
scripts .append (os .path .realpath (scripts [0 ]))
183
183
184
184
for script in scripts :
185
- bindir = os . path . dirname ( script )
186
- if os . path . isdir (bindir ) and os .access (script , os .X_OK ): # only if it's a script
185
+ bindir = str ( Path ( script ). parent )
186
+ if Path (bindir ). is_dir ( ) and os .access (script , os .X_OK ): # only if it's a script
187
187
# ensure executable's dir is on PATH
188
188
# avoids missing subcommands when jupyter is run via absolute path
189
189
path_list .insert (0 , bindir )
@@ -211,9 +211,8 @@ def _evaluate_argcomplete(parser: JupyterParser) -> list[str]:
211
211
# increment word from which to start handling arguments
212
212
increment_argcomplete_index ()
213
213
return cwords
214
- else :
215
- # Otherwise no subcommand, directly autocomplete and exit
216
- parser .argcomplete ()
214
+ # Otherwise no subcommand, directly autocomplete and exit
215
+ parser .argcomplete ()
217
216
except ImportError :
218
217
# traitlets >= 5.8 not available, just try to complete this without
219
218
# worrying about subcommands
@@ -222,7 +221,7 @@ def _evaluate_argcomplete(parser: JupyterParser) -> list[str]:
222
221
raise AssertionError (msg )
223
222
224
223
225
- def main () -> None : # noqa
224
+ def main () -> None :
226
225
"""The command entry point."""
227
226
parser = jupyter_parser ()
228
227
argv = sys .argv
0 commit comments