Fixed #28566 -- Added path matching to collectstatic ignore patterns.
This commit is contained in:
parent
c28bf990d7
commit
8f75d21a2e
|
@ -80,7 +80,7 @@ class Command(BaseCommand):
|
||||||
ignore_patterns = options['ignore_patterns']
|
ignore_patterns = options['ignore_patterns']
|
||||||
if options['use_default_ignore_patterns']:
|
if options['use_default_ignore_patterns']:
|
||||||
ignore_patterns += apps.get_app_config('staticfiles').ignore_patterns
|
ignore_patterns += apps.get_app_config('staticfiles').ignore_patterns
|
||||||
self.ignore_patterns = list(set(ignore_patterns))
|
self.ignore_patterns = list(set(os.path.normpath(p) for p in ignore_patterns))
|
||||||
self.post_process = options['post_process']
|
self.post_process = options['post_process']
|
||||||
|
|
||||||
def collect(self):
|
def collect(self):
|
||||||
|
|
|
@ -22,10 +22,14 @@ def get_files(storage, ignore_patterns=None, location=''):
|
||||||
ignore_patterns = []
|
ignore_patterns = []
|
||||||
directories, files = storage.listdir(location)
|
directories, files = storage.listdir(location)
|
||||||
for fn in files:
|
for fn in files:
|
||||||
|
# Match only the basename.
|
||||||
if matches_patterns(fn, ignore_patterns):
|
if matches_patterns(fn, ignore_patterns):
|
||||||
continue
|
continue
|
||||||
if location:
|
if location:
|
||||||
fn = os.path.join(location, fn)
|
fn = os.path.join(location, fn)
|
||||||
|
# Match the full file path.
|
||||||
|
if matches_patterns(fn, ignore_patterns):
|
||||||
|
continue
|
||||||
yield fn
|
yield fn
|
||||||
for dir in directories:
|
for dir in directories:
|
||||||
if matches_patterns(dir, ignore_patterns):
|
if matches_patterns(dir, ignore_patterns):
|
||||||
|
|
|
@ -94,8 +94,13 @@ Some commonly used options are:
|
||||||
|
|
||||||
.. django-admin-option:: --ignore PATTERN, -i PATTERN
|
.. django-admin-option:: --ignore PATTERN, -i PATTERN
|
||||||
|
|
||||||
Ignore files or directories matching this glob-style pattern. Use multiple
|
Ignore files, directories, or paths matching this glob-style pattern. Use
|
||||||
times to ignore more.
|
multiple times to ignore more. When specifying a path, always use forward
|
||||||
|
slashes, even on Windows.
|
||||||
|
|
||||||
|
.. versionchanged:: 2.2
|
||||||
|
|
||||||
|
Path matching was added.
|
||||||
|
|
||||||
.. django-admin-option:: --dry-run, -n
|
.. django-admin-option:: --dry-run, -n
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,8 @@ Minor features
|
||||||
:mod:`django.contrib.staticfiles`
|
:mod:`django.contrib.staticfiles`
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
* ...
|
* Added path matching to the :option:`collectstatic --ignore` option so that
|
||||||
|
patterns like ``/vendor/*.js`` can be used.
|
||||||
|
|
||||||
:mod:`django.contrib.syndication`
|
:mod:`django.contrib.syndication`
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -2,4 +2,4 @@ from django.contrib.staticfiles.apps import StaticFilesConfig
|
||||||
|
|
||||||
|
|
||||||
class IgnorePatternsAppConfig(StaticFilesConfig):
|
class IgnorePatternsAppConfig(StaticFilesConfig):
|
||||||
ignore_patterns = ['*.css']
|
ignore_patterns = ['*.css', '*/vendor/*.js']
|
||||||
|
|
|
@ -319,11 +319,12 @@ class TestCollectionExcludeNoDefaultIgnore(TestDefaults, CollectionTestCase):
|
||||||
class TestCollectionCustomIgnorePatterns(CollectionTestCase):
|
class TestCollectionCustomIgnorePatterns(CollectionTestCase):
|
||||||
def test_custom_ignore_patterns(self):
|
def test_custom_ignore_patterns(self):
|
||||||
"""
|
"""
|
||||||
A custom ignore_patterns list, ['*.css'] in this case, can be specified
|
A custom ignore_patterns list, ['*.css', '*/vendor/*.js'] in this case,
|
||||||
in an AppConfig definition.
|
can be specified in an AppConfig definition.
|
||||||
"""
|
"""
|
||||||
self.assertFileNotFound('test/nonascii.css')
|
self.assertFileNotFound('test/nonascii.css')
|
||||||
self.assertFileContains('test/.hidden', 'should be ignored')
|
self.assertFileContains('test/.hidden', 'should be ignored')
|
||||||
|
self.assertFileNotFound(os.path.join('test', 'vendor', 'module.js'))
|
||||||
|
|
||||||
|
|
||||||
class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase):
|
class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase):
|
||||||
|
|
Loading…
Reference in New Issue