Skip to content

Commit b326f95

Browse files
update setup
1 parent 2544cea commit b326f95

1 file changed

Lines changed: 31 additions & 12 deletions

File tree

setup.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
import os
44
import shutil
55

6+
# --- Configuration ---
7+
# Get the directory where setup.py is located
8+
SETUP_DIR = os.path.dirname(os.path.abspath(__file__))
69
PICA_PKG_DIR = 'pica'
10+
11+
# Define files to be copied, relative to the project root
712
DATA_FILES_TO_COPY = {
13+
# Destination subdir in package: list of source files
814
'': [
915
'README.md',
1016
'LICENSE',
@@ -17,30 +23,43 @@
1723
]
1824
}
1925

26+
2027
class build_py(build_py_orig):
2128
"""
22-
Custom build command to copy data files into the package source tree.
29+
Custom build command to copy data files into the package source tree
30+
before the main build, ensuring they are included in the wheel.
2331
"""
2432
def run(self):
25-
# First, copy the files
26-
print("--- Custom build_py: Copying data files ---")
33+
print("--- [Custom Build] Running robust data file copy ---")
34+
35+
# Copy the files using absolute paths
2736
for dest_subdir, files in DATA_FILES_TO_COPY.items():
37+
# Destination directory inside the 'pica' package
2838
dest_dir = os.path.join(PICA_PKG_DIR, dest_subdir)
39+
2940
if not os.path.exists(dest_dir):
30-
print(f"Creating directory: {dest_dir}")
41+
print(f"--- [Custom Build] Creating directory: {dest_dir}")
3142
os.makedirs(dest_dir)
3243

33-
for file_path in files:
34-
if os.path.exists(file_path):
35-
print(f"Copying {file_path} to {dest_dir}")
36-
shutil.copy(file_path, dest_dir)
44+
for file_name in files:
45+
# Construct absolute source path
46+
source_path = os.path.join(SETUP_DIR, file_name)
47+
48+
if os.path.exists(source_path):
49+
print(f"--- [Custom Build] Copying '{source_path}' to '{dest_dir}'")
50+
shutil.copy(source_path, dest_dir)
3751
else:
38-
print(f"WARNING: File not found, cannot copy: {file_path}")
52+
# This warning is critical for debugging
53+
print(f"--- [Custom Build] WARNING: Source file not found, cannot copy: {source_path}")
3954

40-
# Then run the original build_py command
41-
print("--- Custom build_py: Running original build command ---")
55+
# Then, run the original build_py command to continue the build
56+
print("--- [Custom Build] Handing over to original build process ---")
4257
build_py_orig.run(self)
4358

59+
60+
# --- Main setup ---
61+
# All project metadata is in pyproject.toml.
62+
# We only use setup.py to inject our custom build command.
4463
setup(
4564
cmdclass={'build_py': build_py}
46-
)
65+
)

0 commit comments

Comments
 (0)