From 6f2ecf832cc78d7a644213678058903682258031 Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 23 Nov 2022 20:35:53 +0100 Subject: [PATCH] feat: create funkwhale-manage entrypoint Part-of: --- api/funkwhale_api/main.py | 34 +++++++++++++++++++ api/manage.py | 29 ---------------- api/pyproject.toml | 3 ++ .../create-api-package-entrypoint.enhancement | 1 + 4 files changed, 38 insertions(+), 29 deletions(-) create mode 100755 api/funkwhale_api/main.py delete mode 100755 api/manage.py create mode 100644 changes/changelog.d/create-api-package-entrypoint.enhancement diff --git a/api/funkwhale_api/main.py b/api/funkwhale_api/main.py new file mode 100755 index 000000000..2a6ab18c2 --- /dev/null +++ b/api/funkwhale_api/main.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production") + + try: + import django + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + + if len(sys.argv) > 1 and sys.argv[1] in ["fw", "funkwhale"]: + django.setup() + + from funkwhale_api.cli import main as cli + + sys.argv = sys.argv[1:] + cli.invoke() + + else: + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/api/manage.py b/api/manage.py deleted file mode 100755 index eb8514aa6..000000000 --- a/api/manage.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys - -import django - -sys.path.append(os.path.dirname(os.path.abspath(__file__))) - -if __name__ == "__main__": - - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production") - # we're doing this here since otherwise, missing environment - # files in settings result in AttributeError being raised, generating - # a cryptic django.core.exceptions.AppRegistryNotReady error. - # To prevent that, we explicitly load settings here before anything - # else, so we fail fast with a relevant error. See #140 for more details. - django.setup() - - from django.core.management import execute_from_command_line - - if len(sys.argv) > 1 and sys.argv[1] in ["fw", "funkwhale"]: - # trigger our own click-based cli - from funkwhale_api.cli import main - - sys.argv = sys.argv[1:] - main.invoke() - else: - execute_from_command_line(sys.argv) diff --git a/api/pyproject.toml b/api/pyproject.toml index cc3739d25..0bde0d3a6 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -20,6 +20,9 @@ include = [ ] exclude = ["tests"] +[tool.poetry.scripts] +funkwhale-manage = 'funkwhale_api.main:main' + [tool.poetry.dependencies] python = "^3.7" Django = "==3.2.16" diff --git a/changes/changelog.d/create-api-package-entrypoint.enhancement b/changes/changelog.d/create-api-package-entrypoint.enhancement new file mode 100644 index 000000000..eabad34f3 --- /dev/null +++ b/changes/changelog.d/create-api-package-entrypoint.enhancement @@ -0,0 +1 @@ +Create the funkwhale-manage entrypoint in the api package