-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_dist.py
42 lines (31 loc) · 1.31 KB
/
build_dist.py
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
import glob
import shutil
import os
import build.__main__
os.environ['DGENERATE_POETRY_LOCKFILE_PATH'] = os.path.join(os.path.dirname(__file__), 'poetry', 'poetry.lock')
os.environ['DGENERATE_POETRY_PYPROJECT_PATH'] = os.path.join(os.path.dirname(__file__), 'poetry', 'pyproject.toml')
platforms = {
'Windows': ['win_amd64'],
'Darwin': ['macosx_11_0_arm64'],
'Linux': ['any']
}
def latest_file(directory):
files = glob.glob(os.path.join(directory, '*'))
if not files:
return None
return max(files, key=os.path.getmtime)
for platform, platform_tags in platforms.items():
os.environ['DGENERATE_PLATFORM'] = platform
for platform_tag in platform_tags:
os.environ['DGENERATE_PLATFORM_TAG'] = platform_tag
directory = os.path.join(os.path.dirname(__file__), 'dist', platform, platform_tag)
os.makedirs(directory, exist_ok=True)
build.__main__.main(['--wheel', '-o', directory])
wheel = latest_file(directory)
wheel_name = wheel.replace('any', platform_tag)
dest = os.path.join(os.path.dirname(__file__), 'dist', os.path.basename(wheel_name))
if os.path.exists(dest):
os.unlink(dest)
shutil.move(wheel, dest)
shutil.rmtree(os.path.dirname(directory), ignore_errors=True)
build.__main__.main(['--sdist'])