| """ |
| Clean pip freeze output for HuggingFace Spaces deployment |
| Usage: python clean_requirements.py < raw_freeze.txt > requirements.txt |
| """ |
|
|
| import sys |
| import re |
|
|
| def clean_requirements(lines): |
| """Clean pip freeze output for deployment.""" |
| cleaned = [] |
| |
| for line in lines: |
| line = line.strip() |
| |
| |
| if not line or line.startswith('#'): |
| continue |
| |
| |
| if line.startswith('-e') or line.startswith('file://'): |
| print(f"# Skipped local package: {line}", file=sys.stderr) |
| continue |
| |
| |
| if 'git+' in line or '@' in line and 'git' in line: |
| print(f"# Skipped git package: {line}", file=sys.stderr) |
| continue |
| |
| |
| |
| line = re.sub(r'\+[a-z0-9]+', '', line) |
| |
| |
| |
| if ' @ ' in line: |
| |
| pkg_name = line.split(' @ ')[0].strip() |
| print(f"# Simplified: {line} -> {pkg_name}", file=sys.stderr) |
| |
| |
| cleaned.append(pkg_name) |
| continue |
| |
| cleaned.append(line) |
| |
| return cleaned |
|
|
| if __name__ == '__main__': |
| lines = sys.stdin.readlines() |
| cleaned = clean_requirements(lines) |
| |
| print("# Requirements generated from pip freeze") |
| print("# Cleaned for HuggingFace Spaces deployment\n") |
| |
| for line in sorted(set(cleaned)): |
| print(line) |