-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
65 lines (58 loc) · 1.79 KB
/
build.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import shutil
# version control
version = "1.0.5";
install_requires = ['numpy>=1.23.5'];
# path
path_cur = os.getcwd();
path_dist = "_dist/";
path_dist_pkg = path_dist + "whatshow_phy_detect_ep/";
# file
file = "EP.py"
file_init = "__init__.py";
file_setup = "setup.py";
file_readme = "README.md";
# file content
file_init_content = "from .EP import EP";
file_setup_content = f'from setuptools import setup, find_packages\n\
\n\
# prepare the instruction\n\
description = "";\n\
with open("README.md", "r") as readme:\n\
description = readme.read();\n\
setup(\n\
name="whatshow_phy_detect_ep",\n\
version="{version}",\n\
packages=find_packages(),\n\
install_requires={install_requires},\n\
long_description = description,\n\
long_description_content_type = \"text/markdown\"\n\
);';
# clear the distribution
if os.path.exists(path_dist):
shutil.rmtree(path_dist);
# create the distribution folder
os.makedirs(path_dist_pkg);
# copy files to the distribution
shutil.copyfile(file, path_dist_pkg + file);
# add config files
# __init__.py
with open(path_dist_pkg + file_init, "w") as init:
init.write(file_init_content);
# setup.py
with open(path_dist + file_setup, "w") as setup:
setup.write(file_setup_content);
# README.md
description_pypi = "";
with open(file_readme, "r") as readme:
description = readme.read();
txt_1_start = description.find("## How to install");
txt_2_start = description.find("## How to use");
description_pypi = description[:txt_1_start] + description[txt_2_start:];
with open(path_dist + file_readme, "w") as readme_pypi:
readme_pypi.write(description_pypi);
# build & upload
os.chdir(path_dist);
os.system("python " + file_setup + " sdist bdist_wheel");
os.system("twine upload dist/*");
os.chdir(path_cur);