@@ -143,30 +143,42 @@ def _prep_automate_all(self):
143143 """Take any further actions needed if using automate_all."""
144144 pass
145145
146- def _clone_and_run_setup_script (self ):
146+ def _clone_and_run_setup_script (self , repo_name : str ):
147147 # Run the setup script to clone repo and install dependencies
148148 cmd = [f"curl -fsSL { REMOTE_SETUP_SCRIPT_URL } | bash -s --" ]
149149 origin_url = self ._get_origin_url ()
150- repo_name = self ._get_repo_name ()
151150 django_project_name = dsd_config .local_project_name
152151 cmd .append (f"{ origin_url } { repo_name } { django_project_name } " )
153152 cmd = " " .join (cmd )
154153 plugin_utils .write_output (f" Cloning and running setup script: { cmd } " )
155154 self .client .run_command (cmd )
156155 plugin_utils .write_output ("Done cloning and running setup script." )
157- # Finally, create the webapp
158- self ._create_webapp (client = self .client , repo_name = repo_name )
159156
160- def _create_webapp (self , client : PythonAnywhereClient , repo_name : str ):
157+ def _copy_wsgi_file (self , repo_name : str ):
158+ """Copy wsgi.py to PythonAnywhere's wsgi location.
159+
160+ This must be done after webapp creation, as creating a webapp
161+ overwrites the wsgi file.
162+ """
163+ plugin_utils .write_output (" Copying wsgi.py to PythonAnywhere..." )
164+
165+ django_project_name = dsd_config .local_project_name
166+ domain = f"{ self .client .username } .pythonanywhere.com"
167+ wsgi_dest = f"/var/www/{ domain .replace ('.' , '_' )} _wsgi.py"
168+ wsgi_src = f"{ repo_name } /{ django_project_name } /wsgi.py"
169+
170+ cmd = f"cp { wsgi_src } { wsgi_dest } "
171+ self .client .run_command (cmd )
172+ plugin_utils .write_output (f" Copied { wsgi_src } to { wsgi_dest } " )
173+
174+ def _create_webapp (self , repo_name : str ):
161175 """Create the webapp on PythonAnywhere."""
162176 plugin_utils .write_output (" Creating webapp on PythonAnywhere..." )
163-
164177 # Paths on PythonAnywhere (remote home directory)
165- remote_home = Path (f"/home/{ client .username } " )
178+ remote_home = Path (f"/home/{ self . client .username } " )
166179 project_path = remote_home / repo_name
167180 virtualenv_path = remote_home / "venv"
168-
169- client .create_or_update_webapp (
181+ self .client .create_or_update_webapp (
170182 python_version = "3.13" ,
171183 virtualenv_path = virtualenv_path ,
172184 project_path = project_path ,
@@ -232,10 +244,10 @@ def _conclude_automate_all(self):
232244
233245 # Push project.
234246 plugin_utils .write_output (" Deploying to PythonAnywhere..." )
235-
236- # Should set self.deployed_url, which will be reported in the success message.
237- self ._clone_and_run_setup_script ( )
238-
247+ repo_name = self . _get_repo_name ()
248+ self ._clone_and_run_setup_script ( repo_name = repo_name )
249+ self ._create_webapp ( repo_name = repo_name )
250+ self . _copy_wsgi_file ( repo_name = repo_name )
239251 self .deployed_url = f"https://{ self ._get_deployed_project_name ()} .pythonanywhere.com"
240252
241253 def _show_success_message (self ):
0 commit comments