Skip to content

Commit

Permalink
Demonstrate the right way to run manage.py from source. (pantsbuild#32)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benjyw authored Apr 20, 2023
1 parent 67681a5 commit ff20d11
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ pants run helloworld/service/admin/manage.py -- runserver
Note that for `runserver`, each dev server will run on its own port, see DEV_PORTS in
[`helloworld/util/discovery.py`](helloworld/util/discovery.py).

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

Expand Down
1 change: 0 additions & 1 deletion helloworld/greet/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
1 change: 0 additions & 1 deletion helloworld/greet/migrations/0002_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def create(


class Migration(migrations.Migration):

dependencies = [
("greet", "0001_initial"),
]
Expand Down
1 change: 0 additions & 1 deletion helloworld/person/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
1 change: 0 additions & 1 deletion helloworld/person/migrations/0002_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def create(slug, full_name):


class Migration(migrations.Migration):

dependencies = [
("person", "0001_initial"),
]
Expand Down
9 changes: 7 additions & 2 deletions helloworld/service/admin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ python_sources(
"helloworld/person",
"helloworld/translate",
],
overrides={
"manage.py": {
"dependencies": ["helloworld/service/admin/settings.py:lib"],
"restartable": True,
},
"gunicorn.py": {"restartable": True},
},
)

pex_binary(
Expand All @@ -16,7 +23,6 @@ pex_binary(
dependencies=[
":lib",
],
restartable=True,
)

pex_binary(
Expand All @@ -25,5 +31,4 @@ pex_binary(
dependencies=[
":lib",
],
restartable=True,
)
8 changes: 5 additions & 3 deletions helloworld/service/frontend/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ python_sources(
"helloworld/ui",
],
overrides={
"manage.py": {"dependencies": ["helloworld/service/frontend/settings.py:lib"]}
"manage.py": {
"dependencies": ["helloworld/service/frontend/settings.py:lib"],
"restartable": True,
},
"gunicorn.py": {"restartable": True},
},
)

Expand All @@ -17,7 +21,6 @@ pex_binary(
dependencies=[
":lib",
],
restartable=True,
)

pex_binary(
Expand All @@ -26,5 +29,4 @@ pex_binary(
dependencies=[
":lib",
],
restartable=True,
)
8 changes: 5 additions & 3 deletions helloworld/service/user/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ python_sources(
"helloworld/person",
],
overrides={
"manage.py": {"dependencies": ["helloworld/service/user/settings.py:lib"]}
"manage.py": {
"dependencies": ["helloworld/service/user/settings.py:lib"],
"restartable": True,
},
"gunicorn.py": {"restartable": True},
},
)

Expand All @@ -17,7 +21,6 @@ pex_binary(
dependencies=[
":lib",
],
restartable=True,
)

pex_binary(
Expand All @@ -26,5 +29,4 @@ pex_binary(
dependencies=[
":lib",
],
restartable=True,
)
8 changes: 5 additions & 3 deletions helloworld/service/welcome/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ python_sources(
"helloworld/translate",
],
overrides={
"manage.py": {"dependencies": ["helloworld/service/welcome/settings.py:lib"]}
"manage.py": {
"dependencies": ["helloworld/service/welcome/settings.py:lib"],
"restartable": True,
},
"gunicorn.py": {"restartable": True},
},
)

Expand All @@ -18,7 +22,6 @@ pex_binary(
dependencies=[
":lib",
],
restartable=True,
)

pex_binary(
Expand All @@ -27,5 +30,4 @@ pex_binary(
dependencies=[
":lib",
],
restartable=True,
)
1 change: 0 additions & 1 deletion helloworld/translate/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
1 change: 0 additions & 1 deletion helloworld/translate/migrations/0002_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def create(slug: str, lang: str, translation: str) -> None:


class Migration(migrations.Migration):

dependencies = [
("translate", "0001_initial"),
("greet", "0002_data"),
Expand Down
2 changes: 1 addition & 1 deletion pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

[GLOBAL]
pants_version = "2.15.0"
pants_version = "2.16.0rc0"

backend_packages.add = [
'pants.backend.python',
Expand Down

0 comments on commit ff20d11

Please sign in to comment.