https://pantsbuild.org/ logo
h

happy-kitchen-89482

05/26/2022, 1:46 PM
Remind me, @polite-garden-50641, when we run Django's makemigrations command internally, we don't do it via
./pants run
, right?
Because then the migrations would end up in the tmpdir, not the real source tree?
b

bitter-ability-32190

05/26/2022, 1:53 PM
p

polite-garden-50641

05/26/2022, 1:57 PM
yup. we don't. However, I think it will work, we do use
./pants run
since when the pex file runs it is like running a python script (the only process that runs in isolation is the pex build) once the code runs it is not isolated and it has access to the local file system whatever the cwd is. I don't use it since it is faster for me to just use the underlying VE which I already have rather than wait for pants to build the pex file and run it.
but I just checked, running makemigrations using pants run works just fine.
b

bitter-ability-32190

05/26/2022, 2:06 PM
and it has access to the local file system whatever the cwd is.
How does Django know to ouput relative to CWD, then and not the caller's
__file__
which will be in the tempdir? This seems like shouldn't work, so thats surprising
p

polite-garden-50641

05/26/2022, 2:20 PM
the way I see it, and I might be wrong, doing
./pants run
is just like doing
./pants package
and then just running the pex file (
./dist/my_script.pex
)
b

bitter-ability-32190

05/26/2022, 2:22 PM
Spiritually, that is true. However the point stands that in your Python code doing
__file__
will not give you the sandbox path, which isn't relative to CWD (at least not in a meaningful way). So I'm not sure how Django can remedy that fact in a meaningful way. I guess, what's the full command/code look like? Maybe I'm missing something?
p

polite-garden-50641

05/26/2022, 2:23 PM
Screen Shot 2022-05-26 at 10.22.51 AM.png
šŸ¤·ā€ā™‚ļø
b

bitter-ability-32190

05/26/2022, 2:23 PM
Ah, yeah specifically the issue here is if it did need to make changes. It wouldn't write them to the repo. Try making a DB change and running the command
(or whatever triggers Django to make a migration script, it's been a while since I've done Django)
p

polite-garden-50641

05/26/2022, 2:24 PM
naa..it works...
ahh.. u are right... it doesn't...
b

bitter-ability-32190

05/26/2022, 2:25 PM
....doens't that screenshot show it doesnt work? The migrations file is not in repo. It's in the tempdir
p

polite-garden-50641

05/26/2022, 2:25 PM
look where it wrote the migration script... ok. I stand corrected.
šŸ¤¦ā€ā™‚ļø
b

bitter-ability-32190

05/26/2022, 2:26 PM
So the good news is I'm not taking crazy pills (I mean, I suppose I could be, we just can't prove it here). The bad news is we still can't codegenerate files easily in Pants šŸ˜›
I think @happy-kitchen-89482’s question though was how y'all do it internally in the Toolchain codebase because of this issue
p

polite-garden-50641

05/26/2022, 2:33 PM
yes. so as I mentioned, I used our virtualenv since it is faster... I am very impatient and won't wait for computers... I also find the fastest way to do things for my workflow...
b

bitter-ability-32190

05/26/2022, 2:34 PM
Generally speaking. I think if users are reaching outside of Pants (especially into a virtualenv) it's a signal we're doing something wrong.
p

polite-garden-50641

05/26/2022, 2:35 PM
I agree.. pants can do many things better and faster.
and the team knows about it... I keep letting them know every so often.
šŸ™Œ 1
b

bitter-ability-32190

05/26/2022, 2:36 PM
Good 😈
p

polite-garden-50641

05/26/2022, 2:38 PM
case in point (pants run not using a cached pex) https://github.com/pantsbuild/pants/issues/10513
h

happy-kitchen-89482

05/26/2022, 3:58 PM
Yeah, OK, so no crazy pills, and no workaround, so we probably want to do that ticket
b

bitter-ability-32190

05/26/2022, 3:59 PM
Your latest comment is 100% valid though, and I expect to see that as a stumbling block. Not sure if there's a way to "win" here šŸ˜•
2 Views