diff --git a/pyproject.toml b/pyproject.toml index 6103cd7faa..6f8cac418f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,6 +113,9 @@ issues = "https://github.com/rdmorganiser/rdmo/issues" repository = "https://github.com/rdmorganiser/rdmo.git" slack = "https://rdmo.slack.com" +[project.scripts] +rdmo-admin = "rdmo.__main__:main" + [tool.setuptools.packages.find] include = ["rdmo*"] exclude = ["*assets*", "*tests*"] diff --git a/rdmo/__main__.py b/rdmo/__main__.py new file mode 100644 index 0000000000..b19f323ed1 --- /dev/null +++ b/rdmo/__main__.py @@ -0,0 +1,27 @@ +''' +Runs rdmo-admin when the rdmo module is run as a script, much like django-admin +(see: https://github.com/django/django/blob/main/django/__main__.py): + + python -m rdmo check + +The main method is added as script in pyproject.toml so that + + rdmo-admin check + +works as well. Unlike django-admin, a set of generic settings is used for the +management scripts. +''' + +import os + +from django.core import management + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rdmo.core.management.settings") + + +def main(): + management.execute_from_command_line() + + +if __name__ == "__main__": + main() diff --git a/rdmo/core/management/commands/build.py b/rdmo/core/management/commands/build.py new file mode 100644 index 0000000000..90746fafce --- /dev/null +++ b/rdmo/core/management/commands/build.py @@ -0,0 +1,10 @@ +import subprocess +import sys + +from django.core.management.base import BaseCommand + + +class Command(BaseCommand): + + def handle(self, *args, **options): + subprocess.call(['/bin/bash', '-c', f'{sys.executable} -m build']) diff --git a/rdmo/core/management/commands/npm.py b/rdmo/core/management/commands/npm.py new file mode 100644 index 0000000000..5e5929d931 --- /dev/null +++ b/rdmo/core/management/commands/npm.py @@ -0,0 +1,22 @@ +import os +import subprocess + +from django.core.management.base import BaseCommand, CommandError + + +class Command(BaseCommand): + + def add_arguments(self, parser): + parser.add_argument('command', nargs="*") + + def handle(self, *args, **options): + nvm_dir = os.getenv('NVM_DIR') + + if nvm_dir is None: + raise CommandError('NVM_DIR is not set, is nvm.sh installed?') + + if not os.path.exists(nvm_dir): + raise CommandError('NVM_DIR does not exist, is nvm.sh installed?') + + command = ' '.join(options['command']) + subprocess.call(['/bin/bash', '-c', f'source {nvm_dir}/nvm.sh; npm {command}']) diff --git a/rdmo/core/management/settings.py b/rdmo/core/management/settings.py new file mode 100644 index 0000000000..3f10d00114 --- /dev/null +++ b/rdmo/core/management/settings.py @@ -0,0 +1,9 @@ +''' +Generic settings to be used with rdmo-admin outside of an rdmo-app. +''' + +from rdmo.core.settings import * # noqa: F403 + +ROOT_URLCONF = '' + +DATABASES = {}