Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyutils.py
More file actions
Latest commit
121 lines (102 loc) · 3.84 KB
/
Copy pathpyutils.py
File metadata and controls
121 lines (102 loc) · 3.84 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
importos
importsubprocess
importsys
importshutil
importglob
defbuild_with_cython():
"""Compiles all Python files in the project using Cython."""
print("Building all Python files with Cython...")
# Compile all Python files to C files
py_files=glob.glob('**/*.py', recursive=True)
forpy_fileinpy_files:
subprocess.run([sys.executable, '-m', 'cython', py_file])
print("Cython build completed.")
deftest_package():
"""Builds the package and installs it."""
print("Starting the test process...")
# Run the build process (without cython)
build_package()
# Install the package
install_package()
defpublish_package():
"""Builds the package and uploads it to PyPI without installing."""
print("Starting the publish process...")
# Run the build process (without cython)
build_package()
# Upload to PyPI using twine
upload_package()
defbuild_package():
"""Handles building the package into distribution files."""
print("Removing existing dist directory...")
shutil.rmtree('dist', ignore_errors=True)
print("Building the package...")
result=subprocess.run([sys.executable, 'setup.py', 'sdist', 'bdist_wheel'])
ifresult.returncode!=0:
print("Failed to build the package")
sys.exit(1)
print("Build process completed.")
definstall_package():
"""Installs the package from the dist directory."""
os.chdir('dist')
whl_files= [fforfinos.listdir() iff.endswith('.whl')]
ifnotwhl_files:
print("No .whl file found")
sys.exit(1)
whl_file=whl_files[0]
subprocess.run(['pip', 'install', '--force-reinstall', whl_file])
print("Package installed successfully.")
defupload_package():
"""Uploads the package to PyPI using Twine."""
print("Uploading the package to PyPI...")
result=subprocess.run(['twine', 'upload', 'dist/*'])
ifresult.returncode!=0:
print("Failed to upload the package")
sys.exit(1)
print("Package uploaded successfully.")
defclean_project():
"""Cleans all build artifacts, C/C++ files, Cython-related files, and __pycache__ directories."""
# Remove build artifacts
fordir_namein ['scriptblocks.egg-info', 'build', 'dist']:
ifos.path.exists(dir_name):
print(f"Removing {dir_name} directory...")
shutil.rmtree(dir_name)
else:
print(f"{dir_name} directory does not exist.")
# Remove all .c and .cpp files in the project
forextin ['*.c', '*.cpp']:
forfileinglob.glob(f'**/{ext}', recursive=True):
os.remove(file)
print(f"Removed {file}")
# Remove Cython-related files like .so, .pyd
forextin ['*.so', '*.pyd']:
forfileinglob.glob(f'**/{ext}', recursive=True):
os.remove(file)
print(f"Removed {file}")
# Remove all __pycache__ directories
forpycache_diringlob.glob('**/__pycache__', recursive=True):
shutil.rmtree(pycache_dir)
print(f"Removed {pycache_dir}")
print("Project cleanup completed.")
defmain():
iflen(sys.argv) !=2:
print("Usage: python cli.py <command>")
print("Commands:")
print(" build - Cython build all Python files in the project")
print(" test - Build and install the package")
print(" publish - Build and upload the package with Twine")
print(" clean - Remove build artifacts, C/C++ files, Cython files, and __pycache__ directories")
sys.exit(1)
command=sys.argv[1]
ifcommand=='build':
build_with_cython()
elifcommand=='test':
test_package()
elifcommand=='publish':
publish_package()
elifcommand=='clean':
clean_project()
else:
print(f"Unknown command: {command}")
sys.exit(1)
if__name__=='__main__':
main()