#28565 closed Bug (invalid)
Collectstatic raises error when trying to ignore files with glob wildcards
| Reported by: | Daniel Wiesmann | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.staticfiles | Version: | 1.11 |
| Severity: | Normal | Keywords: | staticfiles ignore pattern |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I got an unexpected error when trying to ignore a file pattern in subdirectories when using the collectstatic command. Here is an example that reproduces the error in a new project:
cd /tmp && django-admin.py startproject proj
echo "STATIC_ROOT = '/tmp/staticroot'" >> /tmp/proj/proj/settings.py
echo "STATICFILES_DIRS = ('/tmp/proj/static', )" >> /tmp/proj/proj/settings.py
mkdir -p /tmp/proj/static/vendor/lib
touch /tmp/proj/static/vendor/lib/module1.js
touch /tmp/proj/static/vendor/lib/moudle2.js
touch /tmp/proj/static/vendor/lib/moudle3.js
touch /tmp/proj/static/vendor/lib/moudle4.js
/tmp/proj/manage.py collectstatic --no-input -i **/vendor/**/*.js
The first time running the collectstatic command, it gives no error but collects the js files in /static/vendor/lib, the second time running this command gives the follwoing error message:
$ /tmp/proj/manage.py collectstatic --no-input -i **/vendor/**/*.js
usage: manage.py collectstatic [-h] [--version] [-v {0,1,2,3}]
[--settings SETTINGS] [--pythonpath PYTHONPATH]
[--traceback] [--no-color] [--noinput]
[--no-post-process] [-i PATTERN] [-n] [-c] [-l]
[--no-default-ignore]
manage.py collectstatic: error: unrecognized arguments: staticroot/vendor/lib/moudle2.js staticroot/vendor/lib/moudle3.js staticroot/vendor/lib/moudle4.js
Change History (3)
comment:1 by , 8 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 8 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Correct me if I'm wrong, but I think your shell is expanding **/vendor/**/*.js and then passing those arguments to Django. Quote the pattern, i.e. -i '**/vendor/**/*.js' to avoid that.
comment:3 by , 8 years ago
You were right, the error came from the shell expansion. I had tried the quoted version before, but it did not result in any matching, that is why I got confused.
After looking into the details of collectstatic, I saw that the patterns were not matched against the full file paths. So the above statement would never find a match. I made a small pull request to allow for this kind of matching and added a reference to the fnmatch library to the docs, so that its easier to understand how the matching is done (since its not using glob directly).
I got the errors the first time running the commands above.