Uncomment nvidia deps by deafult, update the script

This commit is contained in:
VSlobolinskyi 2025-03-18 18:19:24 +02:00
parent fea77c0b96
commit b598767553
2 changed files with 43 additions and 26 deletions

View File

@ -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<indent>\s*)#\s?', r'\g<indent>', 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

View File

@ -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"