-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_workflow.py
More file actions
executable file
·159 lines (136 loc) · 4.89 KB
/
Copy pathbuild_workflow.py
File metadata and controls
executable file
·159 lines (136 loc) · 4.89 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
#!/usr/bin/env python3
"""
Interactive build workflow script for the AILF package.
This script guides you through the process of:
1. Cleaning the project
2. Running tests
3. Building the package
4. Testing the installation
5. Publishing to PyPI
Use this script for a complete workflow instead of running individual scripts.
"""
import os
import subprocess
import sys
from pathlib import Path
def print_header(title):
"""Print a formatted header."""
print("\n" + "=" * 60)
print(f" {title}")
print("=" * 60)
def run_command(cmd, cwd=None, check=True):
"""Run a command and print output."""
print(f"\n> {' '.join(cmd)}")
result = subprocess.run(cmd, cwd=cwd, check=check)
return result.returncode == 0
def prompt_yes_no(question, default="yes"):
"""Ask a yes/no question via input() and return the answer."""
valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
if default is None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError(f"Invalid default answer: '{default}'")
while True:
sys.stdout.write(question + prompt)
choice = input().lower()
if default is not None and choice == '':
return valid[default]
elif choice in valid:
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n').\n")
def clean():
"""Clean the project."""
print_header("CLEANING PROJECT")
dirs_to_remove = [
"dist",
"build",
"*.egg-info",
"**/__pycache__",
".pytest_cache"
]
for pattern in dirs_to_remove:
files = list(Path(".").glob(pattern))
if files:
for file in files:
if file.is_dir():
print(f"Removing directory: {file}")
try:
import shutil
shutil.rmtree(file)
except Exception as e:
print(f"Error removing {file}: {e}")
else:
print(f"Removing file: {file}")
file.unlink()
def run_tests():
"""Run the test suite."""
print_header("RUNNING TESTS")
return run_command([sys.executable, "-m", "pytest", "-v"])
def build_package():
"""Build the package."""
print_header("BUILDING PACKAGE")
return run_command([sys.executable, "build_dist.py"])
def test_installation():
"""Test package installation."""
print_header("TESTING INSTALLATION")
return run_command([sys.executable, "test_installation.py"])
def publish_package():
"""Publish the package to PyPI."""
print_header("PUBLISHING PACKAGE")
if prompt_yes_no("Publish to Test PyPI first?"):
run_command([sys.executable, "-m", "pip", "install", "--upgrade", "twine"])
run_command([
sys.executable, "-m", "twine", "upload",
"--repository-url", "https://test.pypi.org/legacy/",
"dist/*"
], check=False)
print("\nTest PyPI URL: https://test.pypi.org/project/ailf/")
if prompt_yes_no("Test installation from Test PyPI?"):
run_command([
sys.executable, "-m", "pip", "install",
"--index-url", "https://test.pypi.org/simple/",
"--no-deps", "ailf"
], check=False)
if prompt_yes_no("Publish to PyPI?"):
run_command([
sys.executable, "-m", "twine", "upload", "dist/*"
], check=False)
print("\nPyPI URL: https://pypi.org/project/ailf/")
def main():
"""Main workflow function."""
print_header("AILF PACKAGE BUILD WORKFLOW")
workflow_steps = [
("Clean project", clean),
("Run tests", run_tests),
("Build package", build_package),
("Test installation", test_installation),
("Publish package", publish_package),
]
for i, (step_name, step_func) in enumerate(workflow_steps, 1):
print(f"\n{i}. {step_name}")
while True:
try:
choice = int(input("\nSelect a step to run (1-5), or 0 to run all: "))
if choice == 0:
for _, step_func in workflow_steps:
if not step_func():
print("Workflow stopped due to error.")
break
break
elif 1 <= choice <= len(workflow_steps):
workflow_steps[choice-1][1]()
else:
print(f"Please enter a number between 0 and {len(workflow_steps)}")
except ValueError:
print("Please enter a valid number")
except KeyboardInterrupt:
print("\nWorkflow cancelled.")
break
print("\nWorkflow completed!")
if __name__ == "__main__":
main()