Hi guys, what’s the best way how to create Django ...
# general
e
Hi guys, what’s the best way how to create Django migrations with Pants? Since everything is run in the sandbox I need to copy migrations manually which is quite tedious with 20+ django apps. Also I have issue with detecting changes unless the django app is specified explicitly. I’m composing django apps from shared apps (e.g.
comapany.payments
,
comapany.contrib
) and service specific (e.g.
my_service.auth
). Any help is welcome 🙂
f
did you check the example repo? there are migrations added as dependencies for tests - I would assume something similar is possible for running migrations?
e
Yop, it’s only mentioning how to run migrations, but nothing about creating them. It would be nice for this particular use case if the command won’t run in sandbox or if it would be possible to define some shell target which would move the files from sandbox to the project
f
export a venv like you'd do for IDE integration maybe? 🤔
I guess that's maybe not 'the pants way' of doing it ... but feels like that part is more like a runtime thing
e
Not sure how it would work. I guess you can run the django makemigrations outside of pants with the generated env, but it doesn’t feel right 🙂
f
yeah that's the idea
or, extend the dependencies for runserver to include migrations - which is also not prefect IMHO to 'bloat' the env
s
in our repo, we set
run_goal_use_sandbox=False
on the targets for our
manage.py
files. then we
pants run path/to/manage.py -- makemigrations
disabling the sandbox causes the files to land in the source tree
there might be a global toggle to say
pants run
of a Python source is always un-sandboxed 🤔 it’s been awhile since I looked at the details
e
There is: https://www.pantsbuild.org/docs/reference-python#default_run_goal_use_sandbox I think the confusing thing about the example-django repo is its just old. It uses a
pex_binary
target for
manage.py
and the
run_goal_use_sandbox=False
does not exist for
pex_binary
targets; only
python_source(s)
in this run-a-thing context.
e
Awesome, this is what I was looking for. Thanks guys
Just wondering, as @enough-analyst-54434 mentioned - how to use it for
pex_binary
? There is not such option for this target and I don’t want to set it for the whole
python_sources
since it should use sandbox in other cases. When I run
pants --python-default-run-goal-use-sandbox=false  run ...
it will still put the migrations into the sandbox 🤔
e
You cannot use it for
pex_binary
- that was my point. If you cannot convert your
pex_binary
target to a
python_source
target and use that instead (or define both ~side-by-side), then you may have to file a feature request.