Validate required tools for the requested command.
(args)
| 126 | |
| 127 | |
| 128 | def _validate_environment_for_command(args) -> None: |
| 129 | """Validate required tools for the requested command.""" |
| 130 | print("\n" + "=" * 80) |
| 131 | print(" Environment Validation") |
| 132 | print("=" * 80 + "\n") |
| 133 | |
| 134 | # Define required tools for each command |
| 135 | command_requirements = { |
| 136 | "archive": ["git", "gpg"], |
| 137 | "sdist": ["git", "gpg", "flit"], |
| 138 | "wheel": ["git", "gpg", "flit", "node", "npm", "twine"], |
| 139 | "upload": ["git", "gpg", "svn"], |
| 140 | "all": ["git", "gpg", "flit", "node", "npm", "svn", "twine"], |
| 141 | "verify": ["git", "gpg", "twine"], |
| 142 | } |
| 143 | |
| 144 | required_tools = list(command_requirements.get(args.command, ["git", "gpg"])) |
| 145 | |
| 146 | # Drop gpg if user opted out of signing |
| 147 | if getattr(args, "skip_signing", False) and "gpg" in required_tools: |
| 148 | required_tools.remove("gpg") |
| 149 | |
| 150 | # Drop svn if user opted out of upload (svn is only used for upload) |
| 151 | if getattr(args, "no_upload", False) and "svn" in required_tools: |
| 152 | required_tools.remove("svn") |
| 153 | |
| 154 | # Check for RAT if needed |
| 155 | if hasattr(args, "check_licenses") or hasattr(args, "check_licenses_report"): |
| 156 | if getattr(args, "check_licenses", False) or getattr(args, "check_licenses_report", False): |
| 157 | required_tools.append("java") |
| 158 | if not getattr(args, "rat_jar", None): |
| 159 | _fail("--rat-jar is required when using --check-licenses") |
| 160 | |
| 161 | # Check each tool |
| 162 | missing_tools = [] |
| 163 | print("Checking required tools:") |
| 164 | |
| 165 | for tool in required_tools: |
| 166 | if shutil.which(tool) is None: |
| 167 | missing_tools.append(tool) |
| 168 | print(f" ✗ '{tool}' not found") |
| 169 | else: |
| 170 | print(f" ✓ '{tool}' found") |
| 171 | |
| 172 | if missing_tools: |
| 173 | print("\n❌ Missing required tools:") |
| 174 | for tool in missing_tools: |
| 175 | if tool == "flit": |
| 176 | print(f" • {tool}: Install with 'pip install flit'") |
| 177 | elif tool == "twine": |
| 178 | print(f" • {tool}: Install with 'pip install twine'") |
| 179 | elif tool in ["node", "npm"]: |
| 180 | print(f" • {tool}: Install from https://nodejs.org/") |
| 181 | else: |
| 182 | print(f" • {tool}") |
| 183 | sys.exit(1) |
| 184 | |
| 185 | print("\n✓ All required tools are available\n") |