@@ -75,6 +75,15 @@ def main() -> None:
7575 "Author email" ,
get_git_config (
"email" )
or "[email protected] " 7676 )
7777
78+ # Update project information
79+ print ("📝 Updating project configuration..." )
80+ update_pyproject_toml (
81+ project_name ,
82+ project_description ,
83+ author_name ,
84+ author_email
85+ )
86+
7887 # Handle example code
7988 code_choice = prompt_with_default (
8089 "How would you like to handle example code?\n "
@@ -84,36 +93,101 @@ def main() -> None:
8493 "Choose option" , "1"
8594 )
8695
96+ # Create module directory with project name (replacing src)
97+ project_module_name = project_name .replace ("-" , "_" ).lower ()
98+
99+ # Always update the Makefile to use the new module name
100+ print (f"🔧 Updating Makefile to use module name: { project_module_name } " )
101+ makefile_path = Path ("Makefile" )
102+ with open (makefile_path , "r" ) as f :
103+ makefile_content = f .read ()
104+
105+ # Replace module name in Makefile
106+ updated_makefile = makefile_content .replace ("MODULE_NAME := src" , f"MODULE_NAME := { project_module_name } " )
107+
108+ with open (makefile_path , "w" ) as f :
109+ f .write (updated_makefile )
110+
111+ # Always update pyproject.toml to point to the new module directory
112+ print (f"📦 Updating pyproject.toml for module: { project_module_name } " )
113+ pyproject_path = Path ("pyproject.toml" )
114+ with open (pyproject_path , "rb" ) as f :
115+ config = tomli .load (f )
116+
117+ # Update packages from src to new module name
118+ if "tool" in config and "hatch" in config ["tool" ] and "build" in config ["tool" ]["hatch" ] and "targets" in config ["tool" ]["hatch" ]["build" ] and "wheel" in config ["tool" ]["hatch" ]["build" ]["targets" ]:
119+ config ["tool" ]["hatch" ]["build" ]["targets" ]["wheel" ]["packages" ] = [project_module_name ]
120+
121+ with open (pyproject_path , "wb" ) as f :
122+ tomli_w .dump (config , f )
123+
124+ # Create the new module directory if it doesn't exist
125+ if not os .path .exists (project_module_name ):
126+ print (f"📁 Creating module directory: { project_module_name } " )
127+ os .mkdir (project_module_name )
128+ # Create __init__.py
129+ with open (f"{ project_module_name } /__init__.py" , "w" ) as f :
130+ f .write (f'"""Main package for { project_name } ."""\n ' )
131+
132+ # Copy src content to new module directory if src exists
133+ if os .path .exists ("src" ) and project_module_name != "src" :
134+ print (f"📦 Copying content from src to { project_module_name } ..." )
135+ for item in os .listdir ("src" ):
136+ src_path = os .path .join ("src" , item )
137+ dest_path = os .path .join (project_module_name , item )
138+
139+ if os .path .isfile (src_path ):
140+ with open (src_path , "r" ) as src_file :
141+ content = src_file .read ()
142+ with open (dest_path , "w" ) as dest_file :
143+ dest_file .write (content )
144+
145+ # Remove the old src directory after copying
146+ print ("🗑️ Removing old src directory..." )
147+ run_command ("rm -rf src" )
148+
87149 if code_choice == "2" :
88150 print ("📝 Creating minimal placeholder test..." )
89- # Create minimal src module
90- with open ("src /example.py" , "w" ) as f :
151+ # Create minimal module
152+ with open (f" { project_module_name } /example.py" , "w" ) as f :
91153 f .write ("""def add(a: int, b: int) -> int:
92154 \" \" \" Add two numbers.\" \" \"
93155 return a + b
94156""" )
95157
96158 # Create minimal test
97159 with open ("tests/test_example.py" , "w" ) as f :
98- f .write ("""from src .example import add
160+ f .write (f """from { project_module_name } .example import add
99161
100162def test_add():
101163 assert add(1, 2) == 3
102164""" )
103165 elif code_choice == "3" :
104166 print ("🧹 Removing all example code..." )
105167 run_command ("make clean-example" )
168+ # Create __init__.py in tests
169+ with open ("tests/__init__.py" , "w" ) as f :
170+ f .write ("" )
106171 else :
107- print ("📚 Keeping example code for reference..." )
172+ print ("📚 Updating example code imports for new module name..." )
173+ # Update example.py to use new module name
174+ if os .path .exists ("src/example.py" ):
175+ with open ("src/example.py" , "r" ) as f :
176+ example_content = f .read ()
177+ # Save it to new module directory
178+ with open (f"{ project_module_name } /example.py" , "w" ) as f :
179+ f .write (example_content )
180+
181+ # Update test imports
182+ if os .path .exists ("tests/test_example.py" ):
183+ with open ("tests/test_example.py" , "r" ) as f :
184+ test_content = f .read ()
185+ updated_test = test_content .replace ("from src." , f"from { project_module_name } ." )
186+ with open ("tests/test_example.py" , "w" ) as f :
187+ f .write (updated_test )
108188
109- # Update pyproject.toml
110- print ("📝 Updating project configuration..." )
111- update_pyproject_toml (
112- project_name ,
113- project_description ,
114- author_name ,
115- author_email
116- )
189+ # Update already happened above, fix the duplicate
190+ # The configuration has already been updated above
117191
118192 # Get current directory name and handle renaming
119193 current_dir = os .path .basename (os .getcwd ())
@@ -124,6 +198,18 @@ def test_add():
124198 if os .path .exists (new_dir ):
125199 print (f"⚠️ Directory { project_name } already exists. Keeping current directory name." )
126200 else :
201+ # Update source code directory references in Makefile
202+ makefile_path = Path ("Makefile" )
203+ with open (makefile_path , "r" ) as f :
204+ makefile_content = f .read ()
205+
206+ # Replace any hardcoded references to python-collab-template in the Makefile
207+ updated_makefile = makefile_content .replace ("python-collab-template" , project_name )
208+
209+ with open (makefile_path , "w" ) as f :
210+ f .write (updated_makefile )
211+
212+ # Now rename the directory
127213 os .chdir (parent_dir )
128214 os .rename (current_dir , project_name )
129215 os .chdir (project_name )
@@ -155,9 +241,9 @@ def test_add():
155241 else :
156242 print ("⏩ Skipping pre-commit hooks setup" )
157243
158- # Initial commit
244+ # Initial commit without running pre-commit hooks
159245 run_command ("git add ." )
160- run_command ('git commit -m "feat: Initial project setup"' )
246+ run_command ('git commit -m "feat: Initial project setup" --no-verify ' )
161247
162248 print ("✨ Project initialized successfully!" )
163249 print ("""
0 commit comments