mirror of
https://github.com/django/django.git
synced 2024-11-30 23:20:50 +01:00
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']
|
||||
if options['use_default_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']
|
||||
|
||||
def collect(self):
|
||||
|
@ -22,10 +22,14 @@ def get_files(storage, ignore_patterns=None, location=''):
|
||||
ignore_patterns = []
|
||||
directories, files = storage.listdir(location)
|
||||
for fn in files:
|
||||
# Match only the basename.
|
||||
if matches_patterns(fn, ignore_patterns):
|
||||
continue
|
||||
if location:
|
||||
fn = os.path.join(location, fn)
|
||||
# Match the full file path.
|
||||
if matches_patterns(fn, ignore_patterns):
|
||||
continue
|
||||
yield fn
|
||||
for dir in directories:
|
||||
if matches_patterns(dir, ignore_patterns):
|
||||
|
@ -94,8 +94,13 @@ Some commonly used options are:
|
||||
|
||||
.. django-admin-option:: --ignore PATTERN, -i PATTERN
|
||||
|
||||
Ignore files or directories matching this glob-style pattern. Use multiple
|
||||
times to ignore more.
|
||||
Ignore files, directories, or paths matching this glob-style pattern. Use
|
||||
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
|
||||
|
||||
|
@ -105,7 +105,8 @@ Minor features
|
||||
: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`
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -2,4 +2,4 @@ from django.contrib.staticfiles.apps import StaticFilesConfig
|
||||
|
||||
|
||||
class IgnorePatternsAppConfig(StaticFilesConfig):
|
||||
ignore_patterns = ['*.css']
|
||||
ignore_patterns = ['*.css', '*/vendor/*.js']
|
||||
|
0
tests/staticfiles_tests/apps/test/static/test/vendor/module.js
vendored
Normal file
0
tests/staticfiles_tests/apps/test/static/test/vendor/module.js
vendored
Normal file
@ -319,11 +319,12 @@ class TestCollectionExcludeNoDefaultIgnore(TestDefaults, CollectionTestCase):
|
||||
class TestCollectionCustomIgnorePatterns(CollectionTestCase):
|
||||
def test_custom_ignore_patterns(self):
|
||||
"""
|
||||
A custom ignore_patterns list, ['*.css'] in this case, can be specified
|
||||
in an AppConfig definition.
|
||||
A custom ignore_patterns list, ['*.css', '*/vendor/*.js'] in this case,
|
||||
can be specified in an AppConfig definition.
|
||||
"""
|
||||
self.assertFileNotFound('test/nonascii.css')
|
||||
self.assertFileContains('test/.hidden', 'should be ignored')
|
||||
self.assertFileNotFound(os.path.join('test', 'vendor', 'module.js'))
|
||||
|
||||
|
||||
class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user