I picked up Ticket #18296 a few months ago, as it relates to some friction I regularly encounter myself. When working in a project where the apps aren’t in the root directory, I need to pass the directory to the startapp
command:
python startapp myapp apps/myapp
Which return an error because the directory doesn’t exists:
CommandError: Destination directory '/Users/bruno/.../apps/myapp' does not exist, please create it first.
The fix is quite simple, I can do mkdir apps/myapp
and then run the command again, but it always struck me as uncesseray friction. If the directory doesn’t exists, why not go ahead and create it?
I’ve opened Refs #18296 -- Create custom target directory if missing in startproject and startapp by browniebroke · Pull Request #18387 · django/django · GitHub to change the behaviour to fix that specific problem, and was directed to the forum to gather more feedback. so here we are.
Is this change of behaviour desirable?
4 Likes
Did you manage to find any discussion of the existing behaviour? Chesterton’s Gate: was it just an accident it’s how it is, or what breaks if we do change it? If the answer there is nothing then likely it’s an edge we can smooth?
Great question. I didn’t look before but just did a bit of acheology ![:mag: :mag:](https://emoji.discourse-cdn.com/twitter/mag.png?v=12)
As far as I can tell, it’s been like this for ~13 years, since this change (released in Django 1.4) which references ticket #17920.
Reading the ticket, I think the original problem was that the directory wasn’t the full path, but as far as I can tell the logic is now resolving it to be absolute with os.path.abspath(os.path.expanduser(target))
, which works correctly even if the director does not exist.
There was actually a comment suggesting to create the missing path:
I’m not sure though whether the target shouldn’t just be created if it doesn’t exist?
I don’t see anything addressing it, so I assume it was overlooked.
2 Likes
@browniebroke Good hustle! That seems kind of convincing to me.
I’m struggling to see any great concern with creating the intermediate directories.
Like, I’m sure it’d upset some purist somewhere, but I struggle to imagine such folks not having the target directory ready in place before invoking the command.
In general it’s got to be the desired behaviour for the vast majority no?
![:+1: :+1:](https://emoji.discourse-cdn.com/twitter/+1.png?v=12)
4 Likes
I agree that it makes sense to create the intermediate directories. We should properly handle any error arising from lacking of perms or similar OS errors, but in general I’m in favor!
1 Like
Have we given this topic enough time to gather feedback? If no, how much time is enough time? If yes, I think the current status is that there is no blocker for that change and that people seem fairly in favour of it.
What are the next step to progress the ticket/PR forward? Do I need to update a flag on the ticket to appear in the review queue again or should I leave this to the fellows? There was a comment in the PR regarding documentation, which I happily address if needed.
Thanks everyone for your feedback.