Package: dj-command
Why?It is available everywhere if you install viapip, has cute aliases defined in a JSON file (.dj-config.json) per project, will run as many commands as you want, and defaults to Django management commands if an alias cannot be found.Commands can be run sequentially bydj(e.g.dj makemigrations migrate). However, calling a long-running process (e.g.dj runserver) will prevent any other commands from being run. For example,dj runserver migratewill never run themigratecommand becauserunserverwill block the process.Configuration fileExample .dj-config.tomldisable_django_management_command=falsepython_interpreter="python"environment_file_path=".env"[[commands]]name="m"help="Does the migration dance"execute="./manage.py makemigrations && ./manage.py migrate"requires_virtualenv=true[[commands]]name="r"help="Runs all the servers"execute="./manage.py runserver"requires_virtualenv=truelong_running=true[[commands]]name="ls"help="Lists all the files, of course"execute="ls"[[commands]]name="up"help="Up all the things"execute="pip3 install -r requirements/development.txt && ./manage.py migrate && ./manage.py runserver"requires_virtualenv=truelong_running=true[[commands]]name="restore_database"help="Restores a Postgres database from live to local"execute="PGPASSWORD=$PGPASSWORD pg_dump $DATABASE_NAME --host=$DATABASE_HOST --port=$DATABASE_PORT --username=$DATABASE_USERNAME --format=tar | pg_restore --clean --dbname=$DATABASE_NAME --no-owner --host=localhost --port=5432"Config file locationIf the--configargument is used to specify a particular file location, that is the only placedjlooks for a configuration file.Otherwise,djwill search for appropriate config files and "merge" them together. This allows you to have a base config file in~/.dj-config.toml, but override it on a per-folder basis.djprioritizes.tomlconfig files over.json. So, it will look for~/.dj-config.tomlfirst and, if it's missing, then look for~/.dj-config.json. Then, it will follow the same pattern for the current directory. The current directory's config file will take precedence if there is an overlap in configuration settings.Using environment variables in commandsdjwill look for a.envfile to load environment variables using the wonderfulpython-dotenvlibrary. You can specify environment variables in an execute command just like you would from the shell (i.e.$VARIABLE_NAME).Basic arguments and optionsdj --helpto see all of the optionsdj --listto see all of the available custom commandsdj {command_name}to run a custom command or Django management command (e.g.dj migrate)dj {command_name} {command_name} {command_name}to run multiple commands (e.g.dj makemigrations migrate)dj {command_name} --dry_runto show what commands would run without actually executing themHow to work on the sourceClone the repoRun the source locally:poetry run python djTest the source:poetry run pytestBuild and install locally:poetry build && pip3 install --user --force-reinstall .Test with~/.local/bin/dj migratePublish the source to pypi:poetry publish --build --username USERNAME --password PASSWORDAcknowledgementspoetry: please, please, please continue to help wrangle the complexity of 1) creating Python projects, and 2) installing dependencies; seriously, it's baffling out there without youclick: ridiculously full-featured library to help implement CLI programs in Python; it has all the bells and most of the whistlesattrs: would you like easy classes in Python? yes, pleasedelegator.py:subprocessis a pain, butdelegatorhides all the ugly cruft behind a nice APIpython-dotenv: 12-factor all the things with .env filestoml: the fewer braces in my life the betterPrior artThis isn't a new idea and there are a few other implementations out there that do similar things. But, uh, I like mine. 😀dj-cmdDjango-djdj-cli