clean-city-64472
10/13/2021, 9:37 PMpip install Django==3.2
django-admin startproject mysite
Trying to map this over to a fresh pants environment. If I add Django==3.2
to my requirements.txt
is there some light weight way I could run the django-admin
script contained in that package through the pants CLI?happy-kitchen-89482
10/13/2021, 9:41 PMdjango-admin
is the same as manage.py
(except that manage.py
also sets the DJANGO_SETTINGS_MODULE), so normally I'd say create a pex_binary around the manage.py and ./pants run
it. But in this case there is no manage.py
yet, so I guess we have to run django-admin
itself?happy-kitchen-89482
10/13/2021, 9:42 PMclean-city-64472
10/13/2021, 9:42 PMclean-city-64472
10/13/2021, 9:43 PMsrc/django-admin.py
"""
Invokes django-admin when the django module is run as a script.
Example: python -m django check
"""
from django.core import management
if __name__ == "__main__":
management.execute_from_command_line()
Then I can run
./pants run src/django-admin.py -- startproject mysite
hundreds-father-404
10/13/2021, 9:45 PMclean-city-64472
10/13/2021, 9:48 PMdjango-admin
and it would find that script inside of the Django package and run it?hundreds-father-404
10/13/2021, 9:52 PMentry_point
is for your own code, script
can be set to third-party entry points. Like to build a PEX that runs Black, you could set script="black"
New feature in Pants 2.8clean-city-64472
10/13/2021, 9:52 PMhundreds-father-404
10/13/2021, 9:57 PM./pants run //:django-admin
(or whatever the path to the pex_binary
target is, like utils:django_admin_pex
)
One possible solution to that: the new [cli.alias]
feature added by @curved-television-6568 this week! https://github.com/pantsbuild/pants/pull/13228 You can set up an alias so that ./pants django-admin
expands out to ./pants run //:django-admin
, and your users don't have to think about what a target is etccurved-television-6568
10/14/2021, 1:55 PMBUILD
python_requirement(
name="django",
requirements=["Django"]
)
pex_binary(
name="django-admin",
script="django-admin",
dependencies=[":django"],
)
Then:
$ ./pants run :django-admin
Type 'django-admin.pex help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
...
curved-television-6568
10/14/2021, 1:56 PM$ ./pants run :django-admin -- help check
usage: django-admin.pex check [-h] [--tag TAGS] [--list-tags] [--deploy] [--fail-level {CRITICAL,ERROR,WARNING,INFO,DEBUG}] [--database DATABASES] [--version] [-v {0,1,2,3}]
[--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color]
[app_label [app_label ...]]
Checks the entire Django project for potential problems.
positional arguments:
app_label
hundreds-father-404
10/14/2021, 1:59 PM[cli].alias
can include --
in it: run :django-admin --
, so all you run is ./pants django-admin help check
?curved-television-6568
10/14/2021, 1:59 PMcurved-television-6568
10/14/2021, 2:02 PM[cli.alias]
django-admin = "run :django-admin --"
You can call django admin like this:
$ ./pants django-admin --version
3.2.8
$ ./pants django-admin help check
usage: django-admin.pex check [-h] [--tag TAGS] [--list-tags] [--deploy] [--fail-level {CRITICAL,ERROR,WARNING,INFO,DEBUG}] [--database DATABASES] [--version] [-v {0,1,2,3}]
[--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color]
[app_label [app_label ...]]
Checks the entire Django project for potential problems.
This is on bleeding edge, using export PANTS_SHA=c711f53fc4beaf2a544920514c4082b6527f75ba
$ ./pants --version
2.8.0.dev4+gitc711f53f
curved-television-6568
10/14/2021, 2:03 PM