From b5987675533e76ca0f051f4994ce6f68e1779967 Mon Sep 17 00:00:00 2001 From: VSlobolinskyi Date: Tue, 18 Mar 2025 18:19:24 +0200 Subject: [PATCH] Uncomment nvidia deps by deafult, update the script --- configure_gpu_deps.py | 53 ++++++++++++++++++++++++++++--------------- pyproject.toml | 16 ++++++------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/configure_gpu_deps.py b/configure_gpu_deps.py index a6f7a7b..8cf36d4 100644 --- a/configure_gpu_deps.py +++ b/configure_gpu_deps.py @@ -4,20 +4,20 @@ import re def process_lines(lines, target_gpu): """ - Process the lines of a file and uncomment the configuration block corresponding - to target_gpu ('nvidia' or 'amd') while leaving the other block commented. + Process lines from the pyproject.toml file. + In the GPU configuration blocks, uncomment lines if they belong to the target block, + and ensure lines in the non-target block are commented. """ output_lines = [] current_block = None # None, "nvidia", or "amd" - # Define regexes to detect the markers + # Regex patterns for block markers and separator lines. nvidia_marker = re.compile(r'---\s*NVIDIA GPU configuration\s*---', re.IGNORECASE) amd_marker = re.compile(r'---\s*AMD GPU configuration\s*---', re.IGNORECASE) - separator = re.compile(r'^#\s*-{5,}') # a commented separator line (at least 5 dashes) + separator = re.compile(r'^#\s*-{5,}') # a commented separator line for line in lines: - stripped = line.lstrip() - # Check for block start markers (they remain unchanged) + # Check if this line marks the beginning of a GPU config block. if nvidia_marker.search(line): current_block = "nvidia" output_lines.append(line) @@ -26,24 +26,41 @@ def process_lines(lines, target_gpu): current_block = "amd" output_lines.append(line) continue - # End of block when encountering a separator line + + # If we hit a separator line, then end the current block. if separator.match(line): current_block = None output_lines.append(line) continue - - # If we're in a GPU configuration block and the line is commented, process it - if current_block is not None and stripped.startswith("#"): - # Remove the first '#' and any following space if we are in the target block. - if current_block == target_gpu: - # Uncomment by removing the first '#' (preserve indentation) - # Using regex to remove a leading '#' with possible spaces - uncommented = re.sub(r'^(?P\s*)#\s?', r'\g', line) - output_lines.append(uncommented) - else: - # Leave the line commented for the non-target block + + # Process lines within a GPU configuration block. + if current_block is not None: + # Remove newline to check content. + stripped = line.rstrip("\n") + if stripped.strip() == "": output_lines.append(line) + continue + + # If this block is the target, ensure the line is uncommented. + if current_block == target_gpu: + # If the line is already uncommented, leave it. + if not stripped.lstrip().startswith("#"): + output_lines.append(line) + else: + # Remove the first occurrence of '#' with following space. + uncommented = re.sub(r'^(\s*)#\s?', r'\1', line) + output_lines.append(uncommented) + else: + # For the non-target block, ensure the line is commented. + if stripped.lstrip().startswith("#"): + # Already commented, leave as-is. + output_lines.append(line) + else: + # Add a '#' preserving the original indentation. + leading_space = re.match(r'^(\s*)', line).group(1) + output_lines.append(f"{leading_space}# {line.lstrip()}") else: + # Outside of any GPU config block, just add the line. output_lines.append(line) return output_lines diff --git a/pyproject.toml b/pyproject.toml index 6ac9ac8..8290789 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,14 +60,14 @@ av = "*" # --------------------------------------------------------------------------- # --- NVIDIA GPU configuration --- -# torch = [ -# { url = "https://download.pytorch.org/whl/cu118/torch-2.1.1+cu118-cp311-cp311-win_amd64.whl#sha256=d99be44487d3ed0f7e6ef5d6689a37fb4a2f2821a9e7b59e7e04002a876a667a", markers = "sys_platform == 'win32'" }, -# { url = "https://download.pytorch.org/whl/cu118/torch-2.1.1+cu118-cp311-cp311-linux_x86_64.whl#sha256=f3c0ba02b50d0021ff26f030e22d4c45965537cf91f322e52a65b8c58396f81c", markers = "sys_platform == 'linux'" } -# ] -# torchaudio = [ -# { url = "https://download.pytorch.org/whl/cu118/torchaudio-2.1.1+cu118-cp311-cp311-win_amd64.whl#sha256=79b5afa556063be18de4a1964339242301fe04e782e1030a22695257dd9afbd2", markers = "sys_platform == 'win32'" }, -# { url = "https://download.pytorch.org/whl/cu118/torchaudio-2.1.1+cu118-cp311-cp311-linux_x86_64.whl#sha256=2b077639f240176bb27e964e2e9b3a5c2a8d560a3a7bc1ffd0a024e81f2e10b4", markers = "sys_platform == 'linux'" } -# ] +torch = [ + { url = "https://download.pytorch.org/whl/cu118/torch-2.1.1+cu118-cp311-cp311-win_amd64.whl#sha256=d99be44487d3ed0f7e6ef5d6689a37fb4a2f2821a9e7b59e7e04002a876a667a", markers = "sys_platform == 'win32'" }, + { url = "https://download.pytorch.org/whl/cu118/torch-2.1.1+cu118-cp311-cp311-linux_x86_64.whl#sha256=f3c0ba02b50d0021ff26f030e22d4c45965537cf91f322e52a65b8c58396f81c", markers = "sys_platform == 'linux'" } +] +torchaudio = [ + { url = "https://download.pytorch.org/whl/cu118/torchaudio-2.1.1+cu118-cp311-cp311-win_amd64.whl#sha256=79b5afa556063be18de4a1964339242301fe04e782e1030a22695257dd9afbd2", markers = "sys_platform == 'win32'" }, + { url = "https://download.pytorch.org/whl/cu118/torchaudio-2.1.1+cu118-cp311-cp311-linux_x86_64.whl#sha256=2b077639f240176bb27e964e2e9b3a5c2a8d560a3a7bc1ffd0a024e81f2e10b4", markers = "sys_platform == 'linux'" } +] # --- AMD GPU configuration --- # torch = "2.4.1" # torchaudio = "2.4.1"