diff --git a/.vimspector.json b/.vimspector.json index 4a9889e..7e50c43 100644 --- a/.vimspector.json +++ b/.vimspector.json @@ -9,6 +9,15 @@ "configuration": { "request": "attach" } + }, + "Python: Run current script": { + "adapter": "debugpy", + "configuration": { + "request": "launch", + "program": "${file}", + "args": [ "*${args:--update-gadget-config}" ], + "justMyCode#json": "${justMyCode:true}" + } } } } diff --git a/python3/vimspector/installer.py b/python3/vimspector/installer.py index ac0c266..36f7bec 100644 --- a/python3/vimspector/installer.py +++ b/python3/vimspector/installer.py @@ -57,32 +57,32 @@ def Print( *args, **kwargs ): print( *args, **kwargs ) -def CheckCall( *args, **kwargs ): - if options.quiet: - try: - subprocess.check_output( *args, stderr=subprocess.STDOUT, **kwargs ) - except subprocess.CalledProcessError as e: - print( e.output.decode( 'utf-8' ) ) - raise - else: - subprocess.check_call( *args, **kwargs ) +class MissingExecutable( Exception ): + pass -def PathToAnyWorkingPython3(): - # We can't rely on sys.executable because it's usually 'vim' (fixme, not with - # neovim?) +def GetPATHAsList(): paths = os.environ[ 'PATH' ].split( os.pathsep ) - if install.GetOS() == 'windows': paths.insert( 0, os.getcwd() ) - candidates = [ os.path.join( sys.exec_prefix, 'python.exe' ), - 'python.exe' ] - else: - candidates = [ os.path.join( sys.exec_prefix, 'bin', 'python3' ), - 'python3', - 'python' ] + return paths + + +def FindExecutable( executable: str, paths=None ): + if not paths: + paths = GetPATHAsList() + + if install.GetOS() == 'windows': + extensions = [ '.exe', '.bat', '.cmd' ] + else: + extensions = [ '' ] + + for extension in extensions: + if executable.endswith( extension ): + candidate = executable + else: + candidate = executable + extension - for candidate in candidates: for path in paths: filename = os.path.abspath( os.path.join( path, candidate ) ) if not os.path.isfile( filename ): @@ -92,6 +92,42 @@ def PathToAnyWorkingPython3(): return filename + raise MissingExecutable( f"Unable to find executable { executable } in path" ) + + + +def CheckCall( cmd, *args, **kwargs ): + cmd[ 0 ] = FindExecutable( cmd[ 0 ] ) + + if options.quiet: + try: + subprocess.check_output( cmd, *args, stderr=subprocess.STDOUT, **kwargs ) + except subprocess.CalledProcessError as e: + print( e.output.decode( 'utf-8' ) ) + raise + else: + subprocess.check_call( cmd, *args, **kwargs ) + + +def PathToAnyWorkingPython3(): + # We can't rely on sys.executable because it's usually 'vim' (fixme, not with + # neovim?) + paths = GetPATHAsList() + + if install.GetOS() == 'windows': + candidates = [ os.path.join( sys.exec_prefix, 'python.exe' ), + 'python.exe' ] + else: + candidates = [ os.path.join( sys.exec_prefix, 'bin', 'python3' ), + 'python3', + 'python' ] + + for candidate in candidates: + try: + return FindExecutable( candidate, paths=paths ) + except MissingExecutable: + pass + raise RuntimeError( "Unable to find a working python3" ) @@ -348,7 +384,7 @@ def InstallDebugpy( name, root, gadget ): def InstallTclProDebug( name, root, gadget ): - configure = [ './configure' ] + configure = [ 'sh', './configure' ] if install.GetOS() == 'macos': # Apple removed the headers from system frameworks because they are