Skip to content

Commit eecf20b

Browse files
committed
chore: use variable for folders
1 parent 5263aee commit eecf20b

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

python/scripts/build.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@
77
from pathlib import Path
88

99

10+
# Get the proton root directory
11+
ROOT_DIR = Path(__file__).parent.parent.parent
12+
PYTHON_DIR = Path(__file__).parent.parent
13+
DIST_DIR = PYTHON_DIR / "dist"
14+
15+
1016
def clean():
1117
"""Remove the dist directory."""
12-
dist_dir = Path(__file__).parent.parent / "dist"
13-
if dist_dir.exists():
14-
print(f"Cleaning {dist_dir}")
15-
shutil.rmtree(dist_dir)
18+
if DIST_DIR.exists():
19+
print(f"Cleaning {DIST_DIR}")
20+
shutil.rmtree(DIST_DIR)
1621

1722

1823
def publish():
1924
"""Build wheel for publishing."""
20-
dist_dir = Path(__file__).parent.parent / "dist"
21-
22-
if not dist_dir.exists():
25+
if not DIST_DIR.exists():
2326
print("Error: dist directory not found. Run 'build' first.", file=sys.stderr)
2427
sys.exit(1)
2528

@@ -36,24 +39,21 @@ def publish():
3639
print("Building wheel...")
3740
result = subprocess.run(
3841
[sys.executable, "-m", "build", "--wheel"],
39-
cwd=dist_dir
42+
cwd=DIST_DIR
4043
)
4144

4245
if result.returncode != 0:
4346
print("Wheel build failed!", file=sys.stderr)
4447
sys.exit(1)
4548

4649
print("Wheel built successfully!")
47-
print(f"Output: {dist_dir}/dist/")
50+
print(f"Output: {DIST_DIR}/dist/")
4851

4952

5053
def build(version_hash=None):
5154
"""Generate Python code from proto files."""
5255
clean()
5356

54-
# Get the proton root directory
55-
root_dir = Path(__file__).parent.parent.parent
56-
5757
cmd = [
5858
"buf",
5959
"generate",
@@ -66,17 +66,16 @@ def build(version_hash=None):
6666
]
6767

6868
print(f"Running: {' '.join(cmd)}")
69-
result = subprocess.run(cmd, cwd=root_dir)
69+
result = subprocess.run(cmd, cwd=ROOT_DIR)
7070

7171
if result.returncode != 0:
7272
print("Build failed!", file=sys.stderr)
7373
sys.exit(1)
7474

7575
# Create __init__.py files in all directories
76-
dist_dir = Path(__file__).parent.parent / "dist"
77-
if dist_dir.exists():
76+
if DIST_DIR.exists():
7877
print("Creating __init__.py files...")
79-
for dir_path in dist_dir.rglob("*"):
78+
for dir_path in DIST_DIR.rglob("*"):
8079
if dir_path.is_dir():
8180
init_file = dir_path / "__init__.py"
8281
if not init_file.exists():
@@ -94,13 +93,19 @@ def build(version_hash=None):
9493
content = content.replace('version = "0.1.0"', f'version = "{version_str}"')
9594
print(f"Set version to: {version_str}")
9695

97-
(dist_dir / "pyproject.toml").write_text(content)
96+
(DIST_DIR / "pyproject.toml").write_text(content)
9897

9998
# Copy README to dist
100-
readme_file = Path(__file__).parent.parent / "README.md"
99+
readme_file = PYTHON_DIR / "README.md"
101100
if readme_file.exists():
102101
print("Copying README.md to dist...")
103-
shutil.copy(readme_file, dist_dir / "README.md")
102+
shutil.copy(readme_file, DIST_DIR / "README.md")
103+
104+
# Copy LICENSE to dist
105+
license_file = ROOT_DIR / "LICENSE"
106+
if license_file.exists():
107+
print("Copying LICENSE to dist...")
108+
shutil.copy(license_file, DIST_DIR / "LICENSE")
104109

105110
print("Build successful!")
106111

0 commit comments

Comments
 (0)