[Django] #28565: Collectstatic raises error when trying to ignore files with glob wildcards

21 views
Skip to first unread message

Django

unread,
Sep 4, 2017, 6:28:08 AM9/4/17
to django-...@googlegroups.com
#28565: Collectstatic raises error when trying to ignore files with glob wildcards
-------------------------------------+-------------------------------------
Reporter: Daniel | Owner: nobody
Wiesmann |
Type: Bug | Status: new
Component: | Version: 1.11
contrib.staticfiles | Keywords: staticfiles ignore
Severity: Normal | pattern
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28565>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 4, 2017, 7:00:06 AM9/4/17
to django-...@googlegroups.com
#28565: Collectstatic raises error when trying to ignore files with glob wildcards
-------------------------------------+-------------------------------------
Reporter: Daniel Wiesmann | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 1.11
Severity: Normal | Resolution:
Keywords: staticfiles ignore | Triage Stage: Accepted
pattern |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by hui shang):

* stage: Unreviewed => Accepted


Comment:

I got the errors the first time running the commands above.

--
Ticket URL: <https://code.djangoproject.com/ticket/28565#comment:1>

Django

unread,
Sep 4, 2017, 8:35:34 AM9/4/17
to django-...@googlegroups.com
#28565: Collectstatic raises error when trying to ignore files with glob wildcards
-------------------------------------+-------------------------------------
Reporter: Daniel Wiesmann | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 1.11
Severity: Normal | Resolution: invalid

Keywords: staticfiles ignore | Triage Stage: Accepted
pattern |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28565#comment:2>

Django

unread,
Sep 4, 2017, 9:51:50 AM9/4/17
to django-...@googlegroups.com
#28565: Collectstatic raises error when trying to ignore files with glob wildcards
-------------------------------------+-------------------------------------
Reporter: Daniel Wiesmann | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 1.11
Severity: Normal | Resolution: invalid
Keywords: staticfiles ignore | Triage Stage: Accepted
pattern |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Daniel Wiesmann):

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).

https://github.com/django/django/pull/9021

--
Ticket URL: <https://code.djangoproject.com/ticket/28565#comment:3>

Reply all
Reply to author
Forward
0 new messages