-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_package.py
More file actions
executable file
·140 lines (109 loc) · 4.53 KB
/
install_package.py
File metadata and controls
executable file
·140 lines (109 loc) · 4.53 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# import os
# import subprocess
# import sys
# import shutil
# if sys.version_info[:2] in [(3, 9), (3, 10), (3, 11), (3, 12), (3, 13), (3, 14)]:
# py_requires = f"python{sys.version_info.major}.{sys.version_info.minor}"
# else:
# py_requires = "python3.8"
# file = os.getcwd()
# #subprocess.run(["cd",file]), check=True, stdout=subprocess.PIPE).stdout
# os.system('cd ' + file)
# os.system('./make_version.sh')
# print("version file updated")
# print('*'*100)
# # subprocess.run(["git", "add", "."], check=True, stdout=subprocess.PIPE).stdout
# # subprocess.run(["git", "commit", "-am", "Bug fix commit"], check=True, stdout=subprocess.PIPE).stdout
# # print('git commit done')
# subprocess.run(["git", "pull"], check=True, stdout=subprocess.PIPE).stdout
# print('git pull done')
# print('*'*100)
# subprocess.run(["git", "push"], check=True, stdout=subprocess.PIPE).stdout
# print('*'*100)
# print('removing dist and build folders')
# for folder in ['dist', 'build']:
# if os.path.exists(folder):
# shutil.rmtree(folder)
# print('dist/build folders removed')
# print('*'*100)
# if subprocess.run(['uv','--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).returncode != 0:
# subprocess.run([py_requires, '-m', 'build'], check=True)
# print('*'*100)
# subprocess.run([py_requires, '-m', 'pip', 'install', os.path.join('dist', os.listdir('dist')[-1]), '--break-system-packages'], check=True)
# print('build and installed using pip')
# print('*'*100)
# else:
# subprocess.run(['uv', 'build'], check=True)
# print('*'*100)
# subprocess.run(['sudo','uv', 'pip', 'install', '--system', os.path.join('dist', os.listdir('dist')[-1])], check=True)
# print('build and installed using uv')
# print('*'*100)
# ##Twine upload
# subprocess.run([py_requires, '-m', 'twine', 'upload', 'dist/*'], check=True)
# print('package installed')
# print('*'*100)
# # os.system(py_requires + ' -m twine upload dist/*')
import os
import subprocess
import sys
import glob
def install_package():
subprocess.run(['./make_version.sh'], check=True)
print("version file updated")
print('*'*100)
# subprocess.run(['./make_docs_version.sh'], check=True)
# print("docs version file updated")
# print('*'*100)
version = subprocess.run(['cat', 'VERSION.txt'], capture_output=True, text=True).stdout.strip()
msg = f"updated version: {version}"
subprocess.run(['git', 'add', '.'], check=True)
status = subprocess.run(['git', 'status', '--porcelain'], capture_output=True, text=True)
if status.stdout.strip():
subprocess.run(['git', 'commit', '-am', msg], check=True)
print('git commit done')
else:
print('nothing to commit, skipping')
# Tag AFTER the single commit so the tag points at HEAD
subprocess.run(['git', 'tag', '-f', version], check=True)
print(f'Tagged as {version}')
subprocess.run(['git', 'pull'], check=True)
print('git pull done')
subprocess.run(['git', 'push'], check=True)
subprocess.run(['git', 'push', 'origin', version], check=False)
print('git push done')
print('*'*100)
subprocess.run(['rm', '-rf', 'dist'], check=True)
subprocess.run(['uv', 'build'], check=True)
latest_file = sorted(os.listdir('./dist'))[-1]
whl_files = [f for f in os.listdir('./dist') if f.endswith('.whl')]
latest_file = sorted(whl_files)[-1] if whl_files else sorted(os.listdir('./dist'))[-1]
print(f'Installing package file: {latest_file}')
prefix = os.environ.get('MB_UV_PREFIX', os.path.expanduser('~/.local'))
print(f'Installing into prefix: {prefix}')
subprocess.run(
[
'uv',
'pip',
'install',
f'./dist/{latest_file}',
'--python',
sys.executable,
'--prefix',
prefix,
],
check=True,
)
install_package()
print('package installed')
print('*'*100)
whl_files = glob.glob("dist/*.whl")
subprocess.run(["uvx", "uv-publish"] + whl_files, check=True)
# Upload .whl to the latest GitHub release
version = subprocess.run(['cat', 'VERSION.txt'], capture_output=True, text=True).stdout.strip()
# Create the release if it doesn't exist yet
subprocess.run(['gh', 'release', 'create', version, '--title', f'v{version}', '--notes', f'Release {version}', '--latest'], check=False)
for whl in whl_files:
subprocess.run(['gh', 'release', 'upload', version, whl, '--clobber'], check=True)
print(f'Uploaded {len(whl_files)} whl file(s) to GitHub release {version}')