This repository was archived by the owner on Jan 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
55 lines (43 loc) · 1.81 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
"""Automate build.
v.2023-12-13(1)
"""
import os
import shutil
from pathlib import Path
import re
import tomlkit
from resoup import __version__, __url__, __github_user_name__, __github_project_name__
LEAVE_README_BUILD_VERSION = False
def make_relative_link_work(match: re.Match) -> str:
if match.group('directory_type') == 'images':
return (
f'[{match.group("description")}]'
f'(https://raw.githubusercontent.com/{__github_user_name__}'
f'/{__github_project_name__}/master/'
f'{match.group("path")})'
)
return (
f'[{match.group("description")}]'
f'(https://github.com/{__github_user_name__}/{__github_project_name__}'
f'/blob/master/{match.group("path")})'
)
try:
shutil.rmtree('dist')
except FileNotFoundError:
os.mkdir('dist')
# update pyproject.toml version
pyproject_path = Path("pyproject.toml")
pyproject_data = tomlkit.parse(pyproject_path.read_text())
pyproject_data['tool']['poetry']['version'] = __version__ # type: ignore
pyproject_path.write_text(tomlkit.dumps(pyproject_data), encoding='utf-8')
long_description = f'이 설명은 최신 버전이 아닐 수 있습니다. 만약 최신 버전을 확인하고 싶으시다면 [이 깃허브 링크]({__url__})를 참고하세요.\n'
long_description += Path('README.md').read_text(encoding='utf-8')
long_description = re.sub(r'[[](?P<description>.*?)[]][(](..\/)*(?P<path>(?P<directory_type>images|docs).*?)[)]',
make_relative_link_work, long_description)
try:
Path("README_build.md").write_text(long_description, encoding='utf-8')
os.system('poetry build')
os.system(f'poetry publish -u __token__ -p {Path("_token.txt").read_text("utf-8")}')
finally:
if not LEAVE_README_BUILD_VERSION:
os.remove("README_build.md")