Skip to content

Commit 5129e49

Browse files
committed
pdk init, build & watch
1 parent cf9956b commit 5129e49

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

.pdk/pdk/__init__.py

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,66 @@
1+
import os
2+
import pathlib
3+
import shutil
4+
import subprocess
5+
16
import fire
27

8+
MSG_DIR = pathlib.Path(__file__).parent.parent.parent
9+
10+
11+
def sh(cmd, capture=False, chdir=None):
12+
opts = {
13+
"shell": True,
14+
"stdin": subprocess.PIPE,
15+
}
16+
cwd = os.getcwd() if chdir else None
17+
if chdir:
18+
os.chdir(chdir)
19+
try:
20+
if capture:
21+
opts["stderr"] = subprocess.STDOUT
22+
opts["universal_newlines"] = True
23+
return subprocess.check_output(cmd, **opts)
24+
else:
25+
return subprocess.check_call(cmd, **opts)
26+
finally:
27+
if cwd:
28+
os.chdir(cwd)
29+
30+
31+
def create_symlink(symlink, to):
32+
np = len(pathlib.Path(os.path.commonpath([symlink, to])).parts)
33+
parts = ("..",) * (len(symlink.parts) - np - 1) + to.parts[np:]
34+
relpath = os.path.sep.join(parts)
35+
symlink.parent.mkdir(parents=True, exist_ok=True)
36+
symlink.symlink_to(relpath, target_is_directory=to.is_dir())
37+
38+
39+
def chdir_Doc():
40+
os.chdir(MSG_DIR / "../cpython/Doc")
41+
342

443
class Command:
544
def init(self):
645
"""Initialize .pdk."""
7-
pass
46+
os.chdir(MSG_DIR / "..")
47+
if pathlib.Path("cpython").exists():
48+
shutil.rmtree("cpython")
49+
sh(f"git clone --single-branch -b {os.environ['PDK_BRANCH']} https://github.com/python/cpython")
50+
sh(f"git checkout {os.environ['PDK_REVISION']}", chdir="cpython")
51+
LC_MESSAGES = pathlib.Path(
52+
"cpython/Doc/locales/ko/LC_MESSAGES").absolute()
53+
create_symlink(LC_MESSAGES, MSG_DIR)
54+
55+
def build(self):
56+
"""Build translated document."""
57+
chdir_Doc()
58+
sh("make -e SPHINXOPTS=\"-D language='ko'\" html")
59+
60+
def watch(self):
61+
"""Rebuild translated document on changes, with hot reloading in the browser."""
62+
chdir_Doc()
63+
sh("make -e SPHINXOPTS=\"-D language='ko'\" htmllive")
864

965

1066
def main():

.pdk/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ authors = [
1111
]
1212
dependencies = [
1313
"blurb==2.0.0",
14-
"fire>=0.7,<1",
14+
"fire==0.7.0",
1515
"python-docs-theme==2025.2",
1616
"sphinx==8.2.3",
1717
"sphinx-intl==2.3.1",

0 commit comments

Comments
 (0)