1515import site
1616import sys
1717import sysconfig
18+ from pathlib import Path
1819from shutil import which
1920from subprocess import Popen
2021from typing import Any
@@ -37,7 +38,6 @@ def epilog(self) -> str | None:
3738 @epilog .setter
3839 def epilog (self , x : Any ) -> None :
3940 """Ignore epilog set in Parser.__init__"""
40- pass
4141
4242 def argcomplete (self ) -> None :
4343 """Trigger auto-completion, if enabled"""
@@ -63,7 +63,7 @@ def jupyter_parser() -> JupyterParser:
6363 "subcommand" , type = str , nargs = "?" , help = "the subcommand to launch"
6464 )
6565 # 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
6767
6868 group .add_argument ("--config-dir" , action = "store_true" , help = "show Jupyter config dir" )
6969 group .add_argument ("--data-dir" , action = "store_true" , help = "show Jupyter data dir" )
@@ -98,7 +98,7 @@ def list_subcommands() -> list[str]:
9898 if name .startswith ("jupyter-" ):
9999 if sys .platform .startswith ("win" ):
100100 # remove file-extension on Windows
101- name = os .path .splitext (name )[0 ] # noqa
101+ name = os .path .splitext (name )[0 ] # noqa: PTH122, PLW2901
102102 subcommand_tuples .add (tuple (name .split ("-" )[1 :]))
103103 # build a set of subcommand strings, excluding subcommands whose parents are defined
104104 subcommands = set ()
@@ -120,7 +120,7 @@ def _execvp(cmd: str, argv: list[str]) -> None:
120120 cmd_path = which (cmd )
121121 if cmd_path is None :
122122 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
124124 # Don't raise KeyboardInterrupt in the parent process.
125125 # Set this after spawning, to avoid subprocess inheriting handler.
126126 import signal
@@ -129,7 +129,7 @@ def _execvp(cmd: str, argv: list[str]) -> None:
129129 p .wait ()
130130 sys .exit (p .returncode )
131131 else :
132- os .execvp (cmd , argv ) # noqa
132+ os .execvp (cmd , argv ) # noqa: S606
133133
134134
135135def _jupyter_abspath (subcommand : str ) -> str :
@@ -177,13 +177,13 @@ def _path_with_self() -> list[str]:
177177 path_list .append (bindir )
178178
179179 scripts = [sys .argv [0 ]]
180- if os . path . islink (scripts [0 ]):
180+ if Path (scripts [0 ]). is_symlink ( ):
181181 # include realpath, if `jupyter` is a symlink
182182 scripts .append (os .path .realpath (scripts [0 ]))
183183
184184 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
187187 # ensure executable's dir is on PATH
188188 # avoids missing subcommands when jupyter is run via absolute path
189189 path_list .insert (0 , bindir )
@@ -211,9 +211,8 @@ def _evaluate_argcomplete(parser: JupyterParser) -> list[str]:
211211 # increment word from which to start handling arguments
212212 increment_argcomplete_index ()
213213 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 ()
217216 except ImportError :
218217 # traitlets >= 5.8 not available, just try to complete this without
219218 # worrying about subcommands
@@ -222,7 +221,7 @@ def _evaluate_argcomplete(parser: JupyterParser) -> list[str]:
222221 raise AssertionError (msg )
223222
224223
225- def main () -> None : # noqa
224+ def main () -> None :
226225 """The command entry point."""
227226 parser = jupyter_parser ()
228227 argv = sys .argv
0 commit comments