@@ -49,7 +49,9 @@ trait LanguageImpl {
4949 store : & Store ,
5050 reporter : & HookInstallReporter ,
5151 ) -> Result < InstalledHook > ;
52+
5253 async fn check_health ( & self , info : & InstallInfo ) -> Result < ( ) > ;
54+
5355 async fn run (
5456 & self ,
5557 hook : & InstalledHook ,
@@ -227,40 +229,35 @@ impl Language {
227229}
228230
229231/// Try to extract metadata from the given hook entry if possible.
230- ///
231- /// Currently, only PEP 723 inline metadata for `python` hooks is supported.
232- /// First part of `entry` must be a file path to the Python script.
233- /// Effectively, we are implementing a new `python-script` language which works like `script`.
234- /// But we don't want to introduce a new language just for this for now.
235232pub ( crate ) async fn extract_metadata_from_entry ( hook : & mut Hook ) -> Result < ( ) > {
236- // Only support `python` hooks for now.
237- if hook. language == Language :: Python {
238- return python:: extract_pep723_metadata ( hook) . await ;
233+ match hook. language {
234+ Language :: Python => python:: extract_pep723_metadata ( hook) . await ,
235+ Language :: Golang => golang:: extract_go_mod_metadata ( hook) . await ,
236+ _ => Ok ( ( ) ) ,
239237 }
240-
241- Ok ( ( ) )
242238}
243239
244- pub ( crate ) fn resolve_command ( mut cmds : Vec < String > , env_path : Option < & OsStr > ) -> Vec < String > {
245- let cmd = & cmds[ 0 ] ;
246- let exe_path = match which:: which_in ( cmd, env_path, & * CWD ) {
240+ /// Resolve the actual process invocation, honoring shebangs and PATH lookups.
241+ pub ( crate ) fn resolve_command ( mut cmds : Vec < String > , paths : Option < & OsStr > ) -> Vec < String > {
242+ let candidate = & cmds[ 0 ] ;
243+ let resolved_binary = match which:: which_in ( candidate, paths, & * CWD ) {
247244 Ok ( p) => p,
248- Err ( _) => PathBuf :: from ( cmd ) ,
245+ Err ( _) => PathBuf :: from ( candidate ) ,
249246 } ;
250- trace ! ( "Resolved command: {}" , exe_path . display( ) ) ;
247+ trace ! ( "Resolved command: {}" , resolved_binary . display( ) ) ;
251248
252- if let Ok ( mut interpreter ) = parse_shebang ( & exe_path ) {
253- trace ! ( "Found shebang: {:?}" , interpreter ) ;
249+ if let Ok ( mut shebang_argv ) = parse_shebang ( & resolved_binary ) {
250+ trace ! ( "Found shebang: {:?}" , shebang_argv ) ;
254251 // Resolve the interpreter path, convert "python3" to "python3.exe" on Windows
255- if let Ok ( p) = which:: which_in ( & interpreter [ 0 ] , env_path , & * CWD ) {
256- interpreter [ 0 ] = p. to_string_lossy ( ) . to_string ( ) ;
257- trace ! ( "Resolved interpreter: {}" , & interpreter [ 0 ] ) ;
252+ if let Ok ( p) = which:: which_in ( & shebang_argv [ 0 ] , paths , & * CWD ) {
253+ shebang_argv [ 0 ] = p. to_string_lossy ( ) . to_string ( ) ;
254+ trace ! ( "Resolved interpreter: {}" , & shebang_argv [ 0 ] ) ;
258255 }
259- interpreter . push ( exe_path . to_string_lossy ( ) . to_string ( ) ) ;
260- interpreter . extend_from_slice ( & cmds[ 1 ..] ) ;
261- interpreter
256+ shebang_argv . push ( resolved_binary . to_string_lossy ( ) . to_string ( ) ) ;
257+ shebang_argv . extend_from_slice ( & cmds[ 1 ..] ) ;
258+ shebang_argv
262259 } else {
263- cmds[ 0 ] = exe_path . to_string_lossy ( ) . to_string ( ) ;
260+ cmds[ 0 ] = resolved_binary . to_string_lossy ( ) . to_string ( ) ;
264261 cmds
265262 }
266263}
0 commit comments