Skip to content

Commit ff20d11

Browse files
authored
Demonstrate the right way to run manage.py from source. (#32)
Updates to 2.16.0rc0, which supports setting "restartable" on a source file. Then sets that on manage.py/gunicorn.py, instead of on their pex_binary targets. It is not useful to run the pex binary as a dev server, since every edit will rebuild the pex. The upgrade forced a black upgrade which tweaked some lint.
1 parent 67681a5 commit ff20d11

File tree

12 files changed

+25
-20
lines changed

12 files changed

+25
-20
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ pants run helloworld/service/admin/manage.py -- runserver
120120
Note that for `runserver`, each dev server will run on its own port, see DEV_PORTS in
121121
[`helloworld/util/discovery.py`](helloworld/util/discovery.py).
122122

123-
Also, with `runserver` we turn off Django's autoreloader, since we rely on Pants's own
124-
file-watching instead, by setting `restartable=True` on the `pex_binary` targets for `manage.py`.
123+
Also, with `runserver` we [turn off](helloworld/util/service.py#L40) Django's autoreloader.
124+
Instead, we rely on Pants's own file-watching, by setting `restartable=True` on `manage.py`.
125125
Pants will correctly restart servers in situations where Django cannot, such as changes to
126126
BUILD files, to `.proto` files, or to 3rdparty dependencies.
127127

helloworld/greet/migrations/0001_initial.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class Migration(migrations.Migration):
10-
1110
initial = True
1211

1312
dependencies = []

helloworld/greet/migrations/0002_data.py

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def create(
2929

3030

3131
class Migration(migrations.Migration):
32-
3332
dependencies = [
3433
("greet", "0001_initial"),
3534
]

helloworld/person/migrations/0001_initial.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class Migration(migrations.Migration):
10-
1110
initial = True
1211

1312
dependencies = []

helloworld/person/migrations/0002_data.py

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def create(slug, full_name):
2121

2222

2323
class Migration(migrations.Migration):
24-
2524
dependencies = [
2625
("person", "0001_initial"),
2726
]

helloworld/service/admin/BUILD

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ python_sources(
88
"helloworld/person",
99
"helloworld/translate",
1010
],
11+
overrides={
12+
"manage.py": {
13+
"dependencies": ["helloworld/service/admin/settings.py:lib"],
14+
"restartable": True,
15+
},
16+
"gunicorn.py": {"restartable": True},
17+
},
1118
)
1219

1320
pex_binary(
@@ -16,7 +23,6 @@ pex_binary(
1623
dependencies=[
1724
":lib",
1825
],
19-
restartable=True,
2026
)
2127

2228
pex_binary(
@@ -25,5 +31,4 @@ pex_binary(
2531
dependencies=[
2632
":lib",
2733
],
28-
restartable=True,
2934
)

helloworld/service/frontend/BUILD

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ python_sources(
77
"helloworld/ui",
88
],
99
overrides={
10-
"manage.py": {"dependencies": ["helloworld/service/frontend/settings.py:lib"]}
10+
"manage.py": {
11+
"dependencies": ["helloworld/service/frontend/settings.py:lib"],
12+
"restartable": True,
13+
},
14+
"gunicorn.py": {"restartable": True},
1115
},
1216
)
1317

@@ -17,7 +21,6 @@ pex_binary(
1721
dependencies=[
1822
":lib",
1923
],
20-
restartable=True,
2124
)
2225

2326
pex_binary(
@@ -26,5 +29,4 @@ pex_binary(
2629
dependencies=[
2730
":lib",
2831
],
29-
restartable=True,
3032
)

helloworld/service/user/BUILD

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ python_sources(
77
"helloworld/person",
88
],
99
overrides={
10-
"manage.py": {"dependencies": ["helloworld/service/user/settings.py:lib"]}
10+
"manage.py": {
11+
"dependencies": ["helloworld/service/user/settings.py:lib"],
12+
"restartable": True,
13+
},
14+
"gunicorn.py": {"restartable": True},
1115
},
1216
)
1317

@@ -17,7 +21,6 @@ pex_binary(
1721
dependencies=[
1822
":lib",
1923
],
20-
restartable=True,
2124
)
2225

2326
pex_binary(
@@ -26,5 +29,4 @@ pex_binary(
2629
dependencies=[
2730
":lib",
2831
],
29-
restartable=True,
3032
)

helloworld/service/welcome/BUILD

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ python_sources(
88
"helloworld/translate",
99
],
1010
overrides={
11-
"manage.py": {"dependencies": ["helloworld/service/welcome/settings.py:lib"]}
11+
"manage.py": {
12+
"dependencies": ["helloworld/service/welcome/settings.py:lib"],
13+
"restartable": True,
14+
},
15+
"gunicorn.py": {"restartable": True},
1216
},
1317
)
1418

@@ -18,7 +22,6 @@ pex_binary(
1822
dependencies=[
1923
":lib",
2024
],
21-
restartable=True,
2225
)
2326

2427
pex_binary(
@@ -27,5 +30,4 @@ pex_binary(
2730
dependencies=[
2831
":lib",
2932
],
30-
restartable=True,
3133
)

helloworld/translate/migrations/0001_initial.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class Migration(migrations.Migration):
11-
1211
initial = True
1312

1413
dependencies = [

helloworld/translate/migrations/0002_data.py

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def create(slug: str, lang: str, translation: str) -> None:
3434

3535

3636
class Migration(migrations.Migration):
37-
3837
dependencies = [
3938
("translate", "0001_initial"),
4039
("greet", "0002_data"),

pants.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the Apache License, Version 2.0 (see LICENSE).
33

44
[GLOBAL]
5-
pants_version = "2.15.0"
5+
pants_version = "2.16.0rc0"
66

77
backend_packages.add = [
88
'pants.backend.python',

0 commit comments

Comments
 (0)