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

Implement custom call_command #9

Open
2 tasks done
mikicz opened this issue Sep 25, 2024 · 1 comment · May be fixed by #13
Open
2 tasks done

Implement custom call_command #9

mikicz opened this issue Sep 25, 2024 · 1 comment · May be fixed by #13
Labels
enhancement New feature or request

Comments

@mikicz
Copy link

mikicz commented Sep 25, 2024

Description

Hello, what an interesting project! I'd find it quite useful for something I am working on, where I need to load management commands from outside apps.

One thing we heavily use at work is the call_command function, for running management commands from celery for example, etc. Right now with your solution that wouldn't work yet, as that function is not aware of the customisations (sadly the management command register cannot be easily overwritten)

Suggested Solution

Similar to how a custom implementation of execute_from_command_line must be imported, same should be possible for call_command, which would be aware of these custom commands

Terms

@mikicz
Copy link
Author

mikicz commented Sep 25, 2024

I have tried this:

def call_command(command_name, *args, **options):
    if isinstance(command_name, BaseCommand):
        return base_call_command(command_name, *args, **options)

    if dotted_path := settings.PATHS.get(command_name):
        command_class = import_command_class(dotted_path)
    else:
        try:
            app_label, name = command_name.rsplit(".", 1)
        except ValueError:
            app_label, name = None, command_name

        command_class = load_command_class(name, app_label)

    command_name = command_class()

    return base_call_command(command_name, *args, **options)

And that worked for when commands are included PATHS or MODULES/SUBMODULES - won't work for ALIASES I think?

There are probably more edge cases though!

I would be happy to contribute if you point me towards anything I'm missing?

@paduszyk paduszyk added the enhancement New feature or request label Sep 25, 2024
@paduszyk paduszyk changed the title Implement custom call_command Implement custom call_command Sep 25, 2024
@mikicz mikicz linked a pull request Oct 1, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants