Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a management command option to exclude files ... #1024

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

spapas
Copy link

@spapas spapas commented Nov 16, 2020

from offline compression. It uses the fnmatch module to
match the files and will output the list of excluded
templates if verbose >=2.

Example call:

python manage.py compress -x "forms/*.html" -x "test*/*.html"

This shoud fix #785

from offline compression. It uses the fnmatch module to
match the files and will output the list of excluded
templates if verbose >=2.

Example call:

python manage.py compress -x "forms/*.html" -x "test*/*.html"
@diox
Copy link
Member

diox commented Nov 16, 2020

Hi,

Please include tests for the changes introduced in this PR.

@spapas
Copy link
Author

spapas commented Nov 16, 2020

Hello @diox, I checked the tests but the compress management command isn't tested that thoroughly... Could you point me to the right direction?

@diox
Copy link
Member

diox commented Nov 16, 2020

test_offline.py should have decent (though far from perfect I agree) coverage. It uses the test_templates and test_templates_jinja2 directories.

@raphaelm
Copy link

Any way we can help moving this forward?

@diox
Copy link
Member

diox commented Feb 13, 2022

Hi,

My comment from #1024 (comment) still applies. In order for it to be considered, pull request needs to come with tests and docs for the changes added.

So if you want for this feature to be added, try forking the original poster repos (or work directly with them) and add tests & docs.

@raphaelm
Copy link

Hi diox, thanks.

We decided it's not the right solution for us anyways, so I'm not able to invest the time at the moment. With is solution, we'd need to train every user of our software to pass the new command-line parameters, but we'd rather like a solution that "just works" when you say "manage.py compress", so we're now using a custom django-level template loader that excludes the 3rd-party templates we don't actually use.

@spapas
Copy link
Author

spapas commented Feb 23, 2022

@raphaelm could you clarify a bit more on your solution? Which is the template loader you use? It may be helpful for me also.

Thank you

@raphaelm
Copy link

Yeah, sure, you can have a look at our work in progress here: https://github.com/pretix/pretix/pull/2459/files

@rvanlaar
Copy link

Here's our solution.

Place file in management/commands directory as compress_vendor.
Replace APPLICATION_DIR with the root directory of your application.
Run it with ./manage.py compress_vendor

from __future__ import annotations

from pathlib import Path
from typing import cast

from compressor.management.commands import compress
from django.template import engines
from django.template.backends.django import DjangoTemplates
from django.template.loaders.app_directories import Loader


class CompressLoader(Loader):
    """Loader which only returns template paths inside this application."""

    def get_dirs(self) -> list[str | Path]:
        ds = super().get_dirs()
        return [d for d in ds if "APPLICATION_DIR" in str(d)]


class Command(compress.Command):
    """Compressor for only edubroker_kom templates."""

    def get_loaders(self) -> list[Loader]:
        template = cast(DjangoTemplates, engines["django"])
        return [CompressLoader(template.engine)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Offline compress command add --ignore=PATTERN support
4 participants