|
1 | 1 | """Specifies a hatch build hook to create the wheel for mscl.""" |
2 | 2 |
|
3 | 3 | import platform |
4 | | -import subprocess |
| 4 | +import shutil |
5 | 5 | import sys |
6 | 6 | from pathlib import Path |
7 | 7 |
|
@@ -92,13 +92,25 @@ def initialize(self, version, build_data): |
92 | 92 | ) |
93 | 93 |
|
94 | 94 | self.app.display_success("Downloaded files successfully.") |
95 | | - build_data["artifacts"] = ["_mscl.so", "mscl.py"] |
96 | 95 |
|
97 | 96 | # --- STEP 3: Copy the files ("_mscl.so" & "mscl.py") to the src/mscl/ directory: --- |
98 | 97 | # Move from root (i.e. cwd) to src/mscl |
99 | | - subprocess.run(["mv", "mscl.py", "src/python_mscl/"], check=True) |
| 98 | + # Use shutil.move() to move the files. |
| 99 | + |
| 100 | + self.remove_existing_files(Path("src/python_mscl/"), ["_mscl.so", "_mscl.pyd", "mscl.py"]) |
| 101 | + shutil.move("mscl.py", "src/python_mscl/") |
100 | 102 | if platform.system() == "Windows": |
101 | | - subprocess.run(["mv", "_mscl.pyd", "src/python_mscl/"], check=True) |
| 103 | + shutil.move("_mscl.pyd", "src/python_mscl/") |
| 104 | + build_data["artifacts"] = ["_mscl.pyd", "mscl.py"] |
102 | 105 | else: |
103 | | - subprocess.run(["mv", "_mscl.so", "src/python_mscl/"], check=True) |
| 106 | + shutil.move("_mscl.so", "src/python_mscl/") |
| 107 | + build_data["artifacts"] = ["_mscl.so", "mscl.py"] |
| 108 | + |
104 | 109 | self.app.display_success("Moved files to src/python_mscl/ successfully. Building wheel...") |
| 110 | + |
| 111 | + def remove_existing_files(self, directory: Path, files: list[str]) -> None: |
| 112 | + """Remove the existing files from the directory.""" |
| 113 | + for file in files: |
| 114 | + file_path = directory / file |
| 115 | + if file_path.exists(): |
| 116 | + file_path.unlink() |
0 commit comments