Skip to content

Commit

Permalink
Add rdmo-admin script
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Nov 7, 2024
1 parent 1eadee5 commit f96b115
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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*"]
Expand Down
27 changes: 27 additions & 0 deletions rdmo/__main__.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 10 additions & 0 deletions rdmo/core/management/commands/build.py
Original file line number Diff line number Diff line change
@@ -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'])
22 changes: 22 additions & 0 deletions rdmo/core/management/commands/npm.py
Original file line number Diff line number Diff line change
@@ -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}'])
9 changes: 9 additions & 0 deletions rdmo/core/management/settings.py
Original file line number Diff line number Diff line change
@@ -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 = {}

0 comments on commit f96b115

Please sign in to comment.