Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#31283 closed New feature (wontfix)

"collecstatic --clear" could take ignored patterns into consideration

Reported by: Mateusz Papiernik Owned by: nobody
Component: contrib.staticfiles Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When calling collectstatic --clear all files from STATIC_ROOT are cleared, as per documentation (see #22891), which is understandable.

However, collectstatic has --ignore PATTERN option as well as the possibility to configure ignored patterns through StaticFilesConfig and ignore_patterns variable. This is a handy feature that by default ignores some auxiliary files ['CVS', '.*', '*~'] during collecting process.

The documentation is lax about that, but --clear is not taking those patterns into account, while I think it could.

The most obvious scenario I've run into was with a project that had static folder commited to the repository with .gitkeep and/or .gitignore file inside, to make sure the directory is present, clearly visible from the outset in the project tree and accounted for.

Running collectstatic --clear clears all the directory contents, including .gitkeep that would be matched by ['CVS', '.*', '*~'] if pattern ignores were considered during clearing. As a result, Git will start treating this directory as untracked one, and missing .git* as a uncommited changeset.

Ideally, the --clear option would respect --ignore and StaticFilesConfig, hence the feature proposal. Otherwise, the documentation could be a bit more verbose that it's not the case.

Change History (3)

comment:1 by Carlton Gibson, 5 years ago

Resolution: wontfix
Status: newclosed

Hi Mateusz.

I suspect this change wouldn't merit the code it would take to implement. Static root is meant to be a empty folder specifically for Django to put files into. Like the case in #22891 with the S3 bucket, putting files in there yourself isn't really supported. And I'm sceptical that it's a wide-enough use-case to be worth supporting.

Rather I'd point you to subclassing the collectstatic.Command and overriding clear_dir(). At that point you can implement whatever logic you need.

I hope that makes sense.

comment:2 by Mateusz Papiernik, 5 years ago

Hi Carlton,

thanks for your reply. Fair enough, I understand the logic and the complexity to merit ratio. How about updating the docs on collectstatic to have a remark on that behaviour? It is now not obvious from the flags description that clear (which actually first clears and then copies, not just clears) is using ignore patterns only for the latter part of its job. I gathered how it behaves by reading the command code and not just docs. I'd be happy to make a patch for that.

comment:3 by Carlton Gibson, 5 years ago

The existing text seems clear enough to me:

--clear, -c
Clear the existing files before trying to copy or link the original file.

If you want to propose an adjustment, we're always happy to look at it.

Note: See TracTickets for help on using tickets.
Back to Top