-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_pypi.py
More file actions
190 lines (154 loc) Β· 5.64 KB
/
setup_pypi.py
File metadata and controls
190 lines (154 loc) Β· 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
"""
PyPI Setup Helper for TagManager
This script helps set up PyPI credentials and configuration for publishing.
"""
import os
import sys
import getpass
from pathlib import Path
def create_pypirc():
"""Create .pypirc file for PyPI authentication"""
home_dir = Path.home()
pypirc_path = home_dir / ".pypirc"
print("π PyPI Configuration Setup")
print("=" * 30)
print()
if pypirc_path.exists():
print(f"β οΈ .pypirc already exists at {pypirc_path}")
response = input("Overwrite? (y/N): ").strip().lower()
if response != 'y':
print("Aborted.")
return False
print("Please provide your PyPI credentials:")
print("(You can get an API token from https://pypi.org/manage/account/token/)")
print()
# Get credentials
use_token = input("Use API token? (recommended) (Y/n): ").strip().lower()
use_token = use_token != 'n'
if use_token:
username = "__token__"
password = getpass.getpass("API Token: ").strip()
if not password:
print("β No token provided")
return False
else:
username = input("Username: ").strip()
password = getpass.getpass("Password: ").strip()
if not username or not password:
print("β Username and password required")
return False
# Create .pypirc content
pypirc_content = f"""[distutils]
index-servers = pypi
[pypi]
username = {username}
password = {password}
"""
try:
pypirc_path.write_text(pypirc_content)
# Set secure permissions (Unix-like systems)
if hasattr(os, 'chmod'):
os.chmod(pypirc_path, 0o600)
print(f"β
Created .pypirc at {pypirc_path}")
print("π File permissions set to 600 (owner read/write only)")
return True
except Exception as e:
print(f"β Failed to create .pypirc: {e}")
return False
def setup_environment_variables():
"""Guide user to set up environment variables"""
print("\nπ Environment Variables Setup")
print("=" * 30)
print()
print("Alternative to .pypirc: Set environment variables")
print()
use_token = input("Use API token? (recommended) (Y/n): ").strip().lower()
use_token = use_token != 'n'
if use_token:
token = getpass.getpass("API Token: ").strip()
if token:
print("\nπ Add these to your shell profile (.bashrc, .zshrc, etc.):")
print(f"export TWINE_USERNAME=__token__")
print(f"export TWINE_PASSWORD={token}")
print()
print("Or set them temporarily:")
print(f"TWINE_USERNAME=__token__ TWINE_PASSWORD={token} ./install.sh --remote")
else:
username = input("Username: ").strip()
password = getpass.getpass("Password: ").strip()
if username and password:
print("\nπ Add these to your shell profile (.bashrc, .zshrc, etc.):")
print(f"export TWINE_USERNAME={username}")
print(f"export TWINE_PASSWORD={password}")
def check_existing_config():
"""Check for existing PyPI configuration"""
print("π Checking existing PyPI configuration...")
print()
# Check .pypirc
pypirc_path = Path.home() / ".pypirc"
if pypirc_path.exists():
print(f"β
Found .pypirc at {pypirc_path}")
return True
# Check environment variables
if os.getenv('TWINE_USERNAME') and os.getenv('TWINE_PASSWORD'):
print("β
Found TWINE_USERNAME and TWINE_PASSWORD environment variables")
return True
print("β No PyPI configuration found")
return False
def test_pypi_connection():
"""Test PyPI connection"""
print("\nπ§ͺ Testing PyPI Connection")
print("=" * 25)
try:
import subprocess
result = subprocess.run(['twine', 'check', '--help'],
capture_output=True, text=True)
if result.returncode == 0:
print("β
Twine is available")
else:
print("β Twine not found. Install with: pip install twine")
return False
except FileNotFoundError:
print("β Twine not found. Install with: pip install twine")
return False
return True
def main():
print("π TagManager PyPI Setup Helper")
print("=" * 35)
print()
# Check if configuration already exists
if check_existing_config():
print("\nβ
PyPI configuration already exists!")
response = input("Reconfigure anyway? (y/N): ").strip().lower()
if response != 'y':
print("Setup complete. You can now use ./install.sh --remote")
return
print("\nChoose configuration method:")
print("1. Create .pypirc file (recommended)")
print("2. Set environment variables")
print("3. Skip configuration")
choice = input("\nChoice (1-3): ").strip()
if choice == '1':
if create_pypirc():
print("\nβ
PyPI configuration complete!")
else:
print("\nβ Configuration failed")
sys.exit(1)
elif choice == '2':
setup_environment_variables()
elif choice == '3':
print("Skipped configuration.")
else:
print("Invalid choice.")
sys.exit(1)
# Test connection
if test_pypi_connection():
print("\nπ Setup complete!")
print("\nNext steps:")
print("1. Bump version: python bump_version.py patch")
print("2. Publish: ./install.sh --remote")
else:
print("\nβ οΈ Setup incomplete. Install twine first.")
if __name__ == "__main__":
main()