Build the wheel package
()
| 80 | |
| 81 | |
| 82 | def build_wheel(): |
| 83 | """Build the wheel package""" |
| 84 | |
| 85 | root_dir = Path(__file__).parent.absolute() |
| 86 | build_root = root_dir / 'build' |
| 87 | |
| 88 | print('\n' + '='*60) |
| 89 | print('Building wheel package...') |
| 90 | print('='*60 + '\n') |
| 91 | |
| 92 | # Clean previous builds |
| 93 | dist_dir = build_root / 'dist' |
| 94 | build_dir = build_root / 'build' |
| 95 | egg_info_dir = build_root / 'openocr_python.egg-info' |
| 96 | |
| 97 | for dir_path in [dist_dir, build_dir, egg_info_dir]: |
| 98 | if dir_path.exists(): |
| 99 | print(f'Cleaning {dir_path}...') |
| 100 | shutil.rmtree(dir_path) |
| 101 | |
| 102 | # Build wheel from build directory |
| 103 | print('\nRunning: python setup.py sdist bdist_wheel') |
| 104 | result = subprocess.run( |
| 105 | [sys.executable, 'setup.py', 'sdist', 'bdist_wheel'], |
| 106 | cwd=build_root, |
| 107 | capture_output=True, |
| 108 | text=True |
| 109 | ) |
| 110 | |
| 111 | print(result.stdout) |
| 112 | if result.stderr: |
| 113 | print('STDERR:', result.stderr) |
| 114 | |
| 115 | if result.returncode == 0: |
| 116 | print('\n' + '='*60) |
| 117 | print('Build successful!') |
| 118 | print('='*60) |
| 119 | print(f'\nWheel package created in: {dist_dir}') |
| 120 | |
| 121 | # List created files |
| 122 | if dist_dir.exists(): |
| 123 | print('\nCreated files:') |
| 124 | for file in dist_dir.iterdir(): |
| 125 | print(f' - {file.name}') |
| 126 | return True |
| 127 | else: |
| 128 | print('\n' + '='*60) |
| 129 | print('Build failed!') |
| 130 | print('='*60) |
| 131 | return False |
| 132 | |
| 133 | |
| 134 | def main(): |