def main(domain, django_version, python_version, nuke): if domain == 'your-username.pythonanywhere.com': username = getpass.getuser().lower() pa_domain = os.environ.get('PYTHONANYWHERE_DOMAIN', 'pythonanywhere.com') domain = '{username}.{pa_domain}'.format(username=username, pa_domain=pa_domain) project = DjangoProject(domain, python_version) project.sanity_checks(nuke=nuke) project.create_virtualenv(django_version, nuke=nuke) project.run_startproject(nuke=nuke) project.find_django_files() project.update_settings_file() project.run_collectstatic() project.create_webapp(nuke=nuke) project.add_static_file_mappings() project.update_wsgi_file() project.webapp.reload() print( snakesay('All done! Your site is now live at https://{domain}'.format( domain=domain)))
def test_updates_wsgi_file_from_template(self): project = DjangoProject('mydomain.com', 'python.version') project.wsgi_file_path = Path(tempfile.NamedTemporaryFile().name) project.settings_path = Path('/path/to/settingsfolder/settings.py') template = (Path(pythonanywhere.django_project.__file__).parent / 'wsgi_file_template.py').open().read() project.update_wsgi_file() with project.wsgi_file_path.open() as f: contents = f.read() print(contents) assert contents == template.format(project=project)
def test_actually_produces_wsgi_file_that_can_import_nested_project( self, fake_home, more_nested_submodule, virtualenvs_folder): project = DjangoProject('mydomain.com', '3.6') shutil.copytree(str(more_nested_submodule), str(project.project_path)) project.create_virtualenv() project.find_django_files() project.wsgi_file_path = Path(tempfile.NamedTemporaryFile().name) project.update_wsgi_file() print(project.wsgi_file_path.open().read()) subprocess.check_output([ str(project.virtualenv.path / 'bin/python'), str(project.wsgi_file_path) ])
def autoconfigure( repo_url: str = typer.Argument( ..., help="url of remote git repository of your django project"), domain_name: str = typer.Option( "your-username.pythonanywhere.com", "-d", "--domain", help="Domain name, eg www.mydomain.com", ), python_version: str = typer.Option( "3.6", "-p", "--python-version", help="Python version, eg '3.8'", ), nuke: bool = typer.Option( False, help= "*Irrevocably* delete any existing web app config on this domain. Irrevocably.", ), ): """ Autoconfigure a Django project from on a github URL. \b - downloads the repo - creates a virtualenv and installs django (or detects a requirements.txt if available) - creates webapp via api - creates django wsgi configuration file - adds static files config """ domain = ensure_domain(domain_name) project = DjangoProject(domain, python_version) project.sanity_checks(nuke=nuke) project.download_repo(repo_url, nuke=nuke), project.create_virtualenv(nuke=nuke) project.create_webapp(nuke=nuke) project.add_static_file_mappings() project.find_django_files() project.update_wsgi_file() project.update_settings_file() project.run_collectstatic() project.run_migrate() project.webapp.reload() typer.echo( snakesay( f"All done! Your site is now live at https://{domain_name}\n")) project.start_bash()
def main(domain, django_version, python_version, nuke): domain = ensure_domain(domain) project = DjangoProject(domain, python_version) project.sanity_checks(nuke=nuke) project.create_virtualenv(django_version, nuke=nuke) project.run_startproject(nuke=nuke) project.find_django_files() project.update_settings_file() project.run_collectstatic() project.create_webapp(nuke=nuke) project.add_static_file_mappings() project.update_wsgi_file() project.webapp.reload() print(snakesay('All done! Your site is now live at https://{domain}'.format(domain=domain)))
def start( domain_name: str = typer.Option( "your-username.pythonanywhere.com", "-d", "--domain", help="Domain name, eg www.mydomain.com", ), django_version: str = typer.Option( "latest", "-j", "--django-version", help="Django version, eg '3.1.2'", ), python_version: str = typer.Option( "3.6", "-p", "--python-version", help="Python version, eg '3.8'", ), nuke: bool = typer.Option( False, help= "*Irrevocably* delete any existing web app config on this domain. Irrevocably.", ), ): """ Create a new Django webapp with a virtualenv. Defaults to your free domain, the latest version of Django and Python 3.6 """ domain = ensure_domain(domain_name) project = DjangoProject(domain, python_version) project.sanity_checks(nuke=nuke) project.create_virtualenv(django_version, nuke=nuke) project.run_startproject(nuke=nuke) project.find_django_files() project.update_settings_file() project.run_collectstatic() project.create_webapp(nuke=nuke) project.add_static_file_mappings() project.update_wsgi_file() project.webapp.reload() typer.echo( snakesay(f"All done! Your site is now live at https://{domain}"))
def main(repo_url, domain, python_version, nuke): domain = ensure_domain(domain) project = DjangoProject(domain, python_version) project.sanity_checks(nuke=nuke) project.download_repo(repo_url, nuke=nuke), project.create_virtualenv(nuke=nuke) project.create_webapp(nuke=nuke) project.add_static_file_mappings() project.find_django_files() project.update_wsgi_file() project.update_settings_file() project.run_collectstatic() project.run_migrate() project.webapp.reload() print(snakesay(f'All done! Your site is now live at https://{domain}')) print() project.start_bash()
def test_actually_produces_wsgi_file_that_can_import_nested_project( self, fake_home, more_nested_submodule, virtualenvs_folder): running_python_version = ".".join(python_version().split(".")[:2]) project = DjangoProject("mydomain.com", running_python_version) shutil.copytree(str(more_nested_submodule), str(project.project_path)) if running_python_version in ["3.7", "3.8"]: project.create_virtualenv(django_version="latest") else: project.create_virtualenv() project.find_django_files() project.wsgi_file_path = Path(tempfile.NamedTemporaryFile().name) project.update_wsgi_file() print(project.wsgi_file_path.open().read()) subprocess.check_output([ str(project.virtualenv.path / "bin/python"), str(project.wsgi_file_path) ])
def main(repo_url, domain, python_version, nuke): if domain == 'your-username.pythonanywhere.com': username = getpass.getuser().lower() pa_domain = os.environ.get('PYTHONANYWHERE_DOMAIN', 'pythonanywhere.com') domain = f'{username}.{pa_domain}' project = DjangoProject(domain, python_version) project.sanity_checks(nuke=nuke) project.download_repo(repo_url, nuke=nuke), project.create_virtualenv(nuke=nuke) project.create_webapp(nuke=nuke) project.add_static_file_mappings() project.find_django_files() project.update_wsgi_file() project.update_settings_file() project.run_collectstatic() project.run_migrate() project.webapp.reload() print(snakesay(f'All done! Your site is now live at https://{domain}')) print() project.start_bash()