Skip to content

Commit 8eb74e6

Browse files
Updates for different python and django versions.
Version bump and new core. Actions betterification. Co-authored-by: Piotr Kaznowski <[email protected]>
1 parent 6adad1d commit 8eb74e6

File tree

10 files changed

+126
-102
lines changed

10 files changed

+126
-102
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
name: Tests
22

3-
on: [push]
3+
on: [push, pull_request]
44

55
jobs:
66
build:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
10+
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13" ]
1111

1212
name: Python ${{ matrix.python-version }}
1313
steps:
1414

1515
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
1616

17-
- name: Setup timezone
18-
uses: zcong1993/setup-timezone@master
19-
with:
20-
timezone: UTC
21-
2217
- name: Set up Python
2318
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5
2419
with:

cli/django.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
@app.command()
1313
def autoconfigure(
1414
repo_url: str = typer.Argument(..., help="url of remote git repository of your django project"),
15+
branch: str = typer.Option(
16+
"None",
17+
"-b",
18+
"--branch",
19+
help="Branch name in case of multiple branches",
20+
),
1521
domain_name: str = typer.Option(
1622
"your-username.pythonanywhere.com",
1723
"-d",
@@ -43,6 +49,7 @@ def autoconfigure(
4349
project = DjangoProject(domain, python_version)
4450
project.sanity_checks(nuke=nuke)
4551
project.download_repo(repo_url, nuke=nuke),
52+
project.ensure_branch(branch),
4653
project.create_virtualenv(nuke=nuke)
4754
project.create_webapp(nuke=nuke)
4855
project.add_static_file_mappings()

pythonanywhere/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.15.4"
1+
__version__ = "0.15.5"

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name="pythonanywhere",
12-
version="0.15.4",
12+
version="0.15.5",
1313
description="PythonAnywhere helper tools for users",
1414
long_description=long_description,
1515
long_description_content_type="text/markdown",
@@ -22,6 +22,8 @@
2222
"Intended Audience :: Developers",
2323
"Topic :: Software Development :: Libraries",
2424
"License :: OSI Approved :: MIT License",
25+
"Programming Language :: Python :: 3.13",
26+
"Programming Language :: Python :: 3.12",
2527
"Programming Language :: Python :: 3.11",
2628
"Programming Language :: Python :: 3.10",
2729
"Programming Language :: Python :: 3.9",
@@ -36,7 +38,7 @@
3638
"docopt",
3739
"packaging",
3840
"python-dateutil",
39-
"pythonanywhere_core==0.2.3",
41+
"pythonanywhere_core==0.2.4",
4042
"requests",
4143
"schema",
4244
"snakesay",

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import tempfile
44
from getpass import getuser
55
from pathlib import Path
6+
from platform import python_version
67
from unittest.mock import Mock, patch
78

89
import psutil
@@ -120,3 +121,21 @@ def process_killer():
120121
for child in psutil.Process(p.pid).children():
121122
child.kill()
122123
p.kill()
124+
125+
@pytest.fixture
126+
def running_python_version():
127+
return ".".join(python_version().split(".")[:2])
128+
129+
@pytest.fixture
130+
def new_django_version(running_python_version):
131+
if running_python_version in ["3.10", "3.11", "3.12", "3.13"]:
132+
return "5.1.3"
133+
else:
134+
return "4.2.16"
135+
136+
@pytest.fixture
137+
def old_django_version(running_python_version):
138+
if running_python_version in ["3.10", "3.11", "3.12", "3.13"]:
139+
return "5.1.2"
140+
else:
141+
return "4.2.15"

tests/test_cli_django.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_autoconfigure_calls_all_stuff_in_right_order(mock_django_project):
5959
assert mock_django_project.return_value.method_calls == [
6060
call.sanity_checks(nuke=True),
6161
call.download_repo("repo.url", nuke=True),
62+
call.ensure_branch("None"),
6263
call.create_virtualenv(nuke=True),
6364
call.create_webapp(nuke=True),
6465
call.add_static_file_mappings(),
@@ -86,6 +87,8 @@ def test_autoconfigure_actually_works_against_example_repo(
8687
process_killer,
8788
running_python_version,
8889
):
90+
git_ref = "non-nested-old" if running_python_version in ["3.8", "3.9"] else "master"
91+
expected_django_version = "4.2.16" if running_python_version in ["3.8", "3.9"] else "5.1.3"
8992
mocker.patch("cli.django.DjangoProject.start_bash")
9093
repo = "https://github.com/pythonanywhere/example-django-project.git"
9194
domain = "mydomain.com"
@@ -99,10 +102,11 @@ def test_autoconfigure_actually_works_against_example_repo(
99102
domain,
100103
"-p",
101104
running_python_version,
105+
"--branch",
106+
git_ref,
102107
],
103108
)
104109

105-
expected_django_version = "3.0.6"
106110
expected_virtualenv = virtualenvs_folder / domain
107111
expected_project_path = fake_home / domain
108112
django_project_name = "myproject"
@@ -122,7 +126,7 @@ def test_autoconfigure_actually_works_against_example_repo(
122126

123127
with expected_settings_path.open() as f:
124128
lines = f.read().split("\n")
125-
assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" in lines
129+
assert "MEDIA_ROOT = Path(BASE_DIR / 'media')" in lines
126130
assert "ALLOWED_HOSTS = ['mydomain.com'] # type: List[str]" in lines
127131

128132
assert "base.css" in os.listdir(str(fake_home / domain / "static/admin/css"))
@@ -180,6 +184,7 @@ def test_start_actually_creates_django_project_in_virtualenv_with_hacked_setting
180184
virtualenvs_folder,
181185
api_token,
182186
running_python_version,
187+
new_django_version,
183188
):
184189
runner.invoke(
185190
app,
@@ -188,7 +193,7 @@ def test_start_actually_creates_django_project_in_virtualenv_with_hacked_setting
188193
"-d",
189194
"mydomain.com",
190195
"-j",
191-
"2.2.12",
196+
new_django_version,
192197
"-p",
193198
running_python_version,
194199
],
@@ -204,11 +209,11 @@ def test_start_actually_creates_django_project_in_virtualenv_with_hacked_setting
204209
.decode()
205210
.strip()
206211
)
207-
assert django_version == "2.2.12"
212+
assert django_version == new_django_version
208213

209214
with (fake_home / "mydomain.com/mysite/settings.py").open() as f:
210215
lines = f.read().split("\n")
211-
assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" in lines
216+
assert "MEDIA_ROOT = Path(BASE_DIR / 'media')" in lines
212217
assert "ALLOWED_HOSTS = ['mydomain.com']" in lines
213218

214219
assert "base.css" in os.listdir(str(fake_home / "mydomain.com/static/admin/css"))
@@ -222,10 +227,9 @@ def test_nuke_option_lets_you_run_twice(
222227
virtualenvs_folder,
223228
api_token,
224229
running_python_version,
230+
old_django_version,
231+
new_django_version,
225232
):
226-
old_django_version = "2.2.12"
227-
new_django_version = "3.0.6"
228-
229233
runner.invoke(
230234
app,
231235
[

tests/test_django_project.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,21 @@ def test_nuke_option_handles_directory_not_existing(self, mock_subprocess, fake_
247247

248248

249249
@pytest.fixture
250-
def non_nested_submodule():
250+
def non_nested_submodule(running_python_version):
251+
git_ref = "non-nested-old" if running_python_version in ["3.8", "3.9"] else "master"
251252
subprocess.check_call(["git", "submodule", "update", "--init", "--recursive"])
252253
submodule_path = Path(__file__).parents[1] / "submodules" / "example-django-project"
253-
subprocess.check_call(["git", "checkout", "master"], cwd=str(submodule_path))
254+
subprocess.check_call(["git", "checkout", git_ref], cwd=str(submodule_path))
254255
yield submodule_path
255256
subprocess.check_call(["git", "submodule", "update", "--init", "--recursive"])
256257

257258

258259
@pytest.fixture
259-
def more_nested_submodule():
260+
def more_nested_submodule(running_python_version):
261+
git_ref = "more-nested-old" if running_python_version in ["3.8", "3.9"] else "morenested"
260262
subprocess.check_call(["git", "submodule", "update", "--init", "--recursive"])
261263
submodule_path = Path(__file__).parents[1] / "submodules" / "example-django-project"
262-
subprocess.check_call(["git", "checkout", "morenested"], cwd=str(submodule_path))
264+
subprocess.check_call(["git", "checkout", git_ref], cwd=str(submodule_path))
263265
yield submodule_path
264266
subprocess.check_call(["git", "submodule", "update", "--init", "--recursive"])
265267

@@ -509,9 +511,8 @@ def test_updates_wsgi_file_from_template(self, virtualenvs_folder):
509511

510512
@pytest.mark.slowtest
511513
def test_actually_produces_wsgi_file_that_can_import_project_non_nested(
512-
self, fake_home, non_nested_submodule, virtualenvs_folder
514+
self, fake_home, non_nested_submodule, virtualenvs_folder, running_python_version
513515
):
514-
running_python_version = ".".join(python_version().split(".")[:2])
515516
project = DjangoProject("mydomain.com", running_python_version)
516517
shutil.copytree(str(non_nested_submodule), str(project.project_path))
517518
if running_python_version in ["3.8", "3.9", "3.10", "3.11"]:
@@ -529,15 +530,14 @@ def test_actually_produces_wsgi_file_that_can_import_project_non_nested(
529530

530531
@pytest.mark.slowtest
531532
def test_actually_produces_wsgi_file_that_can_import_nested_project(
532-
self, fake_home, more_nested_submodule, virtualenvs_folder
533+
self, fake_home, more_nested_submodule, virtualenvs_folder, running_python_version
533534
):
534-
running_python_version = ".".join(python_version().split(".")[:2])
535535
project = DjangoProject("mydomain.com", running_python_version)
536536
shutil.copytree(str(more_nested_submodule), str(project.project_path))
537-
if running_python_version in ["3.8", "3.9", "3.10", "3.11"]:
538-
project.create_virtualenv(django_version="latest")
539-
else:
537+
if running_python_version in ["3.8", "3.9"]:
540538
project.create_virtualenv()
539+
else:
540+
project.create_virtualenv(django_version="latest")
541541

542542
project.find_django_files()
543543
project.wsgi_file_path = Path(tempfile.NamedTemporaryFile().name)

tests/test_pa_autoconfigure_django.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from platform import python_version
21
from unittest.mock import call, patch
32
import os
43
import pytest
@@ -7,6 +6,7 @@
76
import time
87

98
from scripts.pa_autoconfigure_django import main
9+
from tests.conftest import new_django_version
1010

1111

1212
class TestMain:
@@ -33,23 +33,22 @@ def test_calls_all_stuff_in_right_order(self):
3333

3434
@pytest.mark.slowtest
3535
def test_actually_works_against_example_repo(
36-
self, fake_home, virtualenvs_folder, api_token, process_killer
36+
self, fake_home, virtualenvs_folder, api_token, process_killer, running_python_version, new_django_version
3737
):
38-
running_python_version = ".".join(python_version().split(".")[:2])
38+
git_ref = "non-nested-old" if running_python_version in ["3.8", "3.9"] else "master"
3939
repo = 'https://github.com/pythonanywhere/example-django-project.git'
4040
domain = 'mydomain.com'
4141
with patch('scripts.pa_autoconfigure_django.DjangoProject.update_wsgi_file'):
4242
with patch('scripts.pa_autoconfigure_django.DjangoProject.start_bash'):
4343
with patch('pythonanywhere_core.webapp.call_api'):
4444
main(
4545
repo_url=repo,
46-
branch="master",
46+
branch=git_ref,
4747
domain=domain,
4848
python_version=running_python_version,
4949
nuke=False
5050
)
5151

52-
expected_django_version = '3.0.6'
5352
expected_virtualenv = virtualenvs_folder / domain
5453
expected_project_path = fake_home / domain
5554
django_project_name = 'myproject'
@@ -60,11 +59,11 @@ def test_actually_works_against_example_repo(
6059
'-c'
6160
'import django; print(django.get_version())'
6261
]).decode().strip()
63-
assert django_version == expected_django_version
62+
assert django_version == new_django_version
6463

6564
with expected_settings_path.open() as f:
6665
lines = f.read().split('\n')
67-
assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" in lines
66+
assert "MEDIA_ROOT = Path(BASE_DIR / 'media')" in lines
6867
assert "ALLOWED_HOSTS = ['mydomain.com'] # type: List[str]" in lines
6968

7069
assert 'base.css' in os.listdir(str(fake_home / domain / 'static/admin/css'))

0 commit comments

Comments
 (0)