-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackager.py
More file actions
54 lines (49 loc) · 1.6 KB
/
packager.py
File metadata and controls
54 lines (49 loc) · 1.6 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
import sys
from pathlib import Path
from os import listdir
import shutil
from subprocess import Popen, PIPE
class Package:
def __init__(self, build_path: Path, output_path: Path, verbose: bool = False):
self.build_path = build_path
self.output_path = output_path
self.verbose = verbose
def build(self, with_version=False):
version = (
[
"--python-tag",
f"cp{sys.version_info.major}{sys.version_info.minor}",
]
if with_version
else []
)
process = Popen(
[
sys.executable,
"setup.py",
"build",
"bdist_wheel",
"--dist-dir",
"whl",
]
+ version,
cwd=f"{self.build_path}",
stdout=PIPE,
stderr=PIPE,
)
stdout, stderr = process.communicate()
if self.verbose:
print(stdout.decode("utf-8"), stderr.decode("utf-8"))
if process.returncode == 0:
package_filename = listdir(self.build_path / "whl")[0]
print(f"### Package `{package_filename}` file created successfully!")
return stdout, stderr
def move_to_output(self):
files = listdir(self.build_path / "whl")
for file in files:
# Move and overwrite existing files
shutil.move(
str(self.build_path.joinpath(f"whl/{file}")),
self.output_path.joinpath(f"{file}"),
)
print(f"### Package `{file}` was moved to output!")