From 16489685141dc991806c49c85453bcd6310a9f51 Mon Sep 17 00:00:00 2001 From: Dan Lipsa Date: Tue, 7 Feb 2023 14:04:14 -0500 Subject: Windows: Fix spack.bat handling of env commands (#35143) This PR enables the successful execution of the spack binary cache tutorial on Windows. It assumes gnupg and file are available (they can be installed with choco). * Fix handling of args with quotes in spack.bat * `file` utility can be installed on Windows (e.g. with choco): update error message accordingly --- lib/spack/llnl/util/filesystem.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 8581081e48..b39a17b52a 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -23,7 +23,7 @@ from llnl.util import tty from llnl.util.lang import dedupe, memoized from llnl.util.symlink import islink, symlink -from spack.util.executable import CommandNotFoundError, Executable, which +from spack.util.executable import Executable, which from spack.util.path import path_to_os_path, system_path_filter is_windows = _platform == "win32" @@ -117,13 +117,7 @@ def path_contains_subdirectory(path, root): @memoized def file_command(*args): """Creates entry point to `file` system command with provided arguments""" - try: - file_cmd = which("file", required=True) - except CommandNotFoundError as e: - if is_windows: - raise CommandNotFoundError("`file` utility is not available on Windows") - else: - raise e + file_cmd = which("file", required=True) for arg in args: file_cmd.add_default_arg(arg) return file_cmd @@ -134,7 +128,11 @@ def _get_mime_type(): """Generate method to call `file` system command to aquire mime type for a specified path """ - return file_command("-b", "-h", "--mime-type") + if is_windows: + # -h option (no-dereference) does not exist in Windows + return file_command("-b", "--mime-type") + else: + return file_command("-b", "-h", "--mime-type") @memoized -- cgit v1.2.3-70-g09d2